def upd_db(): data = AccessModel.AccessModel(dataUrl) sql = "update OutBox set V3='0001' where id<192" if (data.db_modi(sql)): print("修改完成!") else: print("修改失败")
def del_db(): sql = "delete * from OutBox where id<184" data = AccessModel.AccessModel(dataUrl) if (data.db_modi(sql)): print("删除成功!") else: print("删除失败")
def Forexample(): try: data = AccessModel.AccessModel(dataUrl) # sql = "Select * FROM InBox WHERE Readed <>0 AND mbno='" + CARD_MBNO + "'" sql = "Select id,arrivetime,mbno,readed,msg FROM InBox" dataRecordSet = data.db_query_msg(sql) a = [] i = 0 for item in dataRecordSet: a = eval("(" + item + ")") # eval解析JSON数据 # print (a['Msg']) # Msg为字段名 JsonStr = json.dumps(dataRecordSet, ensure_ascii=False, encoding='UTF-8') url = 'http://localhost/api.php/Kmauth/notify' strRet = jsonPost(url, JsonStr) #输入两位 ok认为正常,否则接口返回失败信息 # ret = str[0:2] json_to_python = json.loads(strRet) result = json_to_python['result'] print result if (result == '0'): ids = json_to_python['ids'] print ids dataRecordSet = data.db_modi_inbox(ids) except (TypeError, ValueError) as e: # 将异常对象输出 print("error:" + str(e))
def get_msg_inbox_all(table, action): try: data = AccessModel.AccessModel(dataUrl) # log = Util.Util(COMM_LOG_FILE_ORDER) sql_msg_inbox = "Select * FROM " + table + " WHERE upload <> 1" # sql_msg_inbox = "Select * FROM " + table + " " dataRecordSet = data.db_query_table(sql_msg_inbox) mapdict = dict() i = 0 for item in dataRecordSet: strItem = unicode(item, "utf8") # eval解析JSON数据 a = eval("(" + strItem + ")") # print (a['msgtitle']) # Msg为字段名 i = i + 1 # if (i == 0): # return mapdict['size'] = i mapdict['dataList'] = dataRecordSet url = SVR_URL + 'api.php/sms/' + action + '?appid=5c0uF3Q78LXSrYwZEXjUA8lYi7LRxQvW&access_token=rgoVu@yddbUUccZIWZ3fICpaVpcmNS' # print url strRet = jsonPost2(url, mapdict) logger.info("Server sms/" + action + " ret:%s" % strRet) # 输入两位 ok认为正常,否则接口返回失败信息 # print strRet json_to_python = json.loads(strRet) result = json_to_python['result'] if (result != '0'): logger.info(action + "服务器返回结果为1,数据格式错误") print(action + "服务器返回结果为1,数据格式错误").encode("GBK") else: strResult = json_to_python['result'] if (strResult == '0'): ids = json_to_python['ids'] # print ids if (ids != ''): dataRecordSet = data.db_modi_table(ids, table) except: # 将异常对象输出 print("error:get_msg_inbox_all")
def query_db(): try: data = AccessModel.AccessModel(dataUrl) # sql = "Select * FROM InBox WHERE Readed <>0 AND mbno='" + CARD_MBNO + "'" sql = "Select * FROM InBox WHERE Readed=0" dataRecordSet = data.db_query(sql) a = [] i = 0 for item in dataRecordSet: a = eval("(" + item + ")") # eval解析JSON数据 print (a['Msg']) # Msg为字段名 JsonStr = json.dumps(dataRecordSet, ensure_ascii=False, encoding='UTF-8') jsonPost() except (TypeError, ValueError) as e: # 将异常对象输出 print("error:" + str(e))
def get_messages(): try: data = AccessModel.AccessModel(dataUrl) # log = Util.Util(COMM_LOG_FILE_ORDER) # sql = "Select * FROM InBox WHERE Readed <>0 AND mbno='" + CARD_MBNO + "'" dataRecordSet = data.db_query_msg_ret(sql) mapdict = dict() i = 0 for item in dataRecordSet: a = eval("(" + item + ")") # eval解析JSON数据 # print (a['msg']) # Msg为字段名 i = i + 1 mapdict['size'] = i mapdict['dataList'] = dataRecordSet # I_TIMES = I_TIMES + 1 url = SVR_URL + 'api.php/Kmauth/notify?appid=5c0uF3Q78LXSrYwZEXjUA8lYi7LRxQvW&access_token=rgoVu@yddbUUccZIWZ3fICpaVpcmNS×' strRet = jsonPost2(url, mapdict) logger.info("Server Kmauth/notify ret:%s" % strRet) # 输入两位 ok认为正常,否则接口返回失败信息 # print strRet json_to_python = json.loads(strRet) result = json_to_python['result'] if (result != '0'): logger.info("服务器返回结果为1,数据格式错误") print("服务器返回结果为1,数据格式错误").encode("GBK") else: strOk = json_to_python['ok'] strFail = json_to_python['fail'] if (strOk != ''): ids = json_to_python['ok'] # print ids dataRecordSet = data.db_modi_inbox(ids) except: # 将异常对象输出 print("error:get_messages")
def get_orders(): print "working......%d" % SLEEP_SECOND # url = 'http://localhost/api.php/sms/qryorder?minid=0&appid=5c0uF3Q78LXSrYwZEXjUA8lYi7LRxQvW&access_token=rgoVu@yddbUUccZIWZ3fICpaVpcmNS' url = SVR_URL + 'api.php/sms/qryorder?appid=5c0uF3Q78LXSrYwZEXjUA8lYi7LRxQvW&access_token=rgoVu@yddbUUccZIWZ3fICpaVpcmNS' try: html = urllib2.urlopen(url, timeout=10) hjson = json.loads(html.read()) errcode = hjson['errcode'] errmsg = hjson['errmsg'] size = hjson['size'] reqid = hjson['reqid'] data = hjson['data'] ret = [1] * size sql_statement = [1] * size print("待处理的订单条数为 : %d" % size).encode("GBK") logger.info("待处理的订单条数为 : %d" % size) if size != 0: for i in range(0, size): # data_order = hjson['summary'] print(" 处理第: %d条记录" % (i + 1)).encode("GBK") ret[i] = sms_to_send_arr(data[i]) sql_statement[i] = sms_ins_access_sql(ret[i]) data = AccessModel.AccessModel(dataUrl) conn = data.db_conn() for i in range(0, size): # 写入access数据库 print sql_statement[i] conn.Execute(sql_statement[i]) # sms_to_send_http(ret[i]) conn.Close() except: # 将异常对象输出 print("error:get_orders, api.php/sms/qryorder")