This commit is contained in:
aozhiwei 2019-08-22 11:49:12 +08:00
parent 9f6e25e80e
commit 2549d147dd
2 changed files with 23 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import json
import time
import datetime
import hashlib
import binascii
import pymysql
import urllib.request
import tornado.ioloop
@ -21,7 +22,7 @@ def info(msg):
def getMysqlConn(accountid):
hash_code = binascii.crc32(accountid.encode())
assert(hash_code >= 0)
mysql_conf = mysql_cluster_json[hash_code % len(mysql_cluster)]
mysql_conf = mysql_cluster_json[hash_code % len(mysql_cluster_json)]
return pymysql.connect(host = mysql_conf['host'],
port = mysql_conf['port'],
user = mysql_conf['user'],
@ -51,12 +52,22 @@ def getDaySeconds(time_val, incdays):
return dayseconds
def fetchConfirmedOrderList():
global last_idx
global confirmed_order_list
try:
conn = getMysqlConn('')
cursor = conn.cursor()
cursor.execute('SELECT sp_pay_result, accountid, itemid, price, orderid, gameid '
'FROM orderinfo WHERE orderid="%s";' % conn.escape_string(orderid))
except:
cursor.execute('SELECT idx, orderid '
'FROM confirmed_order WHERE idx>%d;' % last_idx)
rows = cursor.fetchall();
for row in rows:
confirmed_order_list.append({
'idx' : int(row[0]),
'orderid': row[1]
})
last_idx = int(row[0])
except Exception as e:
print(e)
return
def sendOneOrder(idx, orderid):
@ -84,7 +95,8 @@ def sendOneOrder(idx, orderid):
jsonobj = json.loads(data)
info('sendNotify end')
return True
except:
except Exception as e:
print('sendOneOrder error:' + e)
return False
def sendNotify(conf, sendtime):
@ -100,7 +112,7 @@ def sendNotify(conf, sendtime):
else:
break
except Exception as e:
info('sendNotifu error: ' + str(e))
info('sendNotify error: ' + str(e))
#进入下一次循环
if len(confirmed_order_list) > 0:
@ -132,6 +144,6 @@ if __name__ == "__main__":
app = make_app()
app.listen(conf['listen_port'])
tornado.ioloop.IOLoop.current().call_at(time.time()+ conf['notifytime'],
tornado.ioloop.IOLoop.current().call_at(time.time(),
lambda : sendNotify(conf, conf['notifytime']))
tornado.ioloop.IOLoop.current().start()

View File

@ -68,12 +68,12 @@ class PayNotifyController {
$ret = $conn->execScript('UPDATE orderinfo SET ' .
' sp_pay_result = 1, ' .
' sp_confirm_time = :sp_confirm_time, ' .
' sp_orderid = :sp_orderid' .
' sp_orderid = :sp_orderid ' .
'WHERE orderid=:orderid;',
array(
'orderid' => $_REQUEST['BillNo'],
'sp_orderid' => $_REQUEST['OrderNo'],
'sp_confirm_time' => $nowtime
':orderid' => $_REQUEST['BillNo'],
':sp_orderid' => $_REQUEST['OrderNo'],
':sp_confirm_time' => $nowtime
));
if ($ret) {
die('ok');