1
This commit is contained in:
parent
9f6e25e80e
commit
2549d147dd
@ -5,6 +5,7 @@ import json
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import binascii
|
||||||
import pymysql
|
import pymysql
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
@ -21,7 +22,7 @@ def info(msg):
|
|||||||
def getMysqlConn(accountid):
|
def getMysqlConn(accountid):
|
||||||
hash_code = binascii.crc32(accountid.encode())
|
hash_code = binascii.crc32(accountid.encode())
|
||||||
assert(hash_code >= 0)
|
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'],
|
return pymysql.connect(host = mysql_conf['host'],
|
||||||
port = mysql_conf['port'],
|
port = mysql_conf['port'],
|
||||||
user = mysql_conf['user'],
|
user = mysql_conf['user'],
|
||||||
@ -51,12 +52,22 @@ def getDaySeconds(time_val, incdays):
|
|||||||
return dayseconds
|
return dayseconds
|
||||||
|
|
||||||
def fetchConfirmedOrderList():
|
def fetchConfirmedOrderList():
|
||||||
|
global last_idx
|
||||||
|
global confirmed_order_list
|
||||||
try:
|
try:
|
||||||
conn = getMysqlConn('')
|
conn = getMysqlConn('')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT sp_pay_result, accountid, itemid, price, orderid, gameid '
|
cursor.execute('SELECT idx, orderid '
|
||||||
'FROM orderinfo WHERE orderid="%s";' % conn.escape_string(orderid))
|
'FROM confirmed_order WHERE idx>%d;' % last_idx)
|
||||||
except:
|
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
|
return
|
||||||
|
|
||||||
def sendOneOrder(idx, orderid):
|
def sendOneOrder(idx, orderid):
|
||||||
@ -84,7 +95,8 @@ def sendOneOrder(idx, orderid):
|
|||||||
jsonobj = json.loads(data)
|
jsonobj = json.loads(data)
|
||||||
info('sendNotify end')
|
info('sendNotify end')
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception as e:
|
||||||
|
print('sendOneOrder error:' + e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def sendNotify(conf, sendtime):
|
def sendNotify(conf, sendtime):
|
||||||
@ -100,7 +112,7 @@ def sendNotify(conf, sendtime):
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
info('sendNotifu error: ' + str(e))
|
info('sendNotify error: ' + str(e))
|
||||||
|
|
||||||
#进入下一次循环
|
#进入下一次循环
|
||||||
if len(confirmed_order_list) > 0:
|
if len(confirmed_order_list) > 0:
|
||||||
@ -132,6 +144,6 @@ if __name__ == "__main__":
|
|||||||
app = make_app()
|
app = make_app()
|
||||||
app.listen(conf['listen_port'])
|
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']))
|
lambda : sendNotify(conf, conf['notifytime']))
|
||||||
tornado.ioloop.IOLoop.current().start()
|
tornado.ioloop.IOLoop.current().start()
|
||||||
|
@ -68,12 +68,12 @@ class PayNotifyController {
|
|||||||
$ret = $conn->execScript('UPDATE orderinfo SET ' .
|
$ret = $conn->execScript('UPDATE orderinfo SET ' .
|
||||||
' sp_pay_result = 1, ' .
|
' sp_pay_result = 1, ' .
|
||||||
' sp_confirm_time = :sp_confirm_time, ' .
|
' sp_confirm_time = :sp_confirm_time, ' .
|
||||||
' sp_orderid = :sp_orderid' .
|
' sp_orderid = :sp_orderid ' .
|
||||||
'WHERE orderid=:orderid;',
|
'WHERE orderid=:orderid;',
|
||||||
array(
|
array(
|
||||||
'orderid' => $_REQUEST['BillNo'],
|
':orderid' => $_REQUEST['BillNo'],
|
||||||
'sp_orderid' => $_REQUEST['OrderNo'],
|
':sp_orderid' => $_REQUEST['OrderNo'],
|
||||||
'sp_confirm_time' => $nowtime
|
':sp_confirm_time' => $nowtime
|
||||||
));
|
));
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
die('ok');
|
die('ok');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user