1
This commit is contained in:
parent
f9b1308522
commit
a5fe2c79b0
@ -90,6 +90,7 @@ CREATE TABLE `confirmed_order` (
|
|||||||
`idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
`idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||||
`orderid` varchar(60) DEFAULT '' COMMENT '订单id',
|
`orderid` varchar(60) DEFAULT '' COMMENT '订单id',
|
||||||
`status` int(11) NOT NULL DEFAULT '0' COMMENT '0: 未确认 1:已确认',
|
`status` int(11) NOT NULL DEFAULT '0' COMMENT '0: 未确认 1:已确认',
|
||||||
|
`confirm_time` int(11) NOT NULL DEFAULT '0' COMMENT '确认时间',
|
||||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||||
PRIMARY KEY (`idx`),
|
PRIMARY KEY (`idx`),
|
||||||
KEY `orderid` (`orderid`)
|
KEY `orderid` (`orderid`)
|
||||||
|
@ -10,9 +10,26 @@ import urllib.request
|
|||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
import tornado.web
|
import tornado.web
|
||||||
|
|
||||||
|
mysql_cluster_json = json.loads(open('../config/pay_backend.mysql.cluster.json', 'r').read())
|
||||||
|
notifyapi_json = json.loads(open('../config/pay_backend.notifyapi.json', 'r').read())
|
||||||
|
last_idx = 0
|
||||||
|
confirmed_order_list = []
|
||||||
|
|
||||||
def info(msg):
|
def info(msg):
|
||||||
print(str(datetime.datetime.now()) + '[INFO] ' + msg, flush = True)
|
print(str(datetime.datetime.now()) + '[INFO] ' + msg, flush = True)
|
||||||
|
|
||||||
|
def getMysqlConn(accountid):
|
||||||
|
hash_code = binascii.crc32(accountid.encode())
|
||||||
|
assert(hash_code >= 0)
|
||||||
|
mysql_conf = mysql_cluster_json[hash_code % len(mysql_cluster)]
|
||||||
|
return pymysql.connect(host = mysql_conf['host'],
|
||||||
|
port = mysql_conf['port'],
|
||||||
|
user = mysql_conf['user'],
|
||||||
|
passwd = mysql_conf['passwd'],
|
||||||
|
db = 'paydb',
|
||||||
|
charset = 'utf8'
|
||||||
|
)
|
||||||
|
|
||||||
def md5Sign(params, secret, timestamp, connstr = '&', secret_connstr = ':'):
|
def md5Sign(params, secret, timestamp, connstr = '&', secret_connstr = ':'):
|
||||||
params_str = ''
|
params_str = ''
|
||||||
for key in sorted(params.keys()):
|
for key in sorted(params.keys()):
|
||||||
@ -33,23 +50,64 @@ def getDaySeconds(time_val, incdays):
|
|||||||
info(dayseconds)
|
info(dayseconds)
|
||||||
return dayseconds
|
return dayseconds
|
||||||
|
|
||||||
|
def fetchConfirmedOrderList():
|
||||||
|
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:
|
||||||
|
return
|
||||||
|
|
||||||
|
def sendOneOrder(idx, orderid):
|
||||||
|
try:
|
||||||
|
conn = getMysqlConn('')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('SELECT sp_pay_result, accountid, itemid, price, orderid, gameid, status '
|
||||||
|
'FROM orderinfo WHERE orderid="%s";' % conn.escape_string(orderid))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if (not row) or (row[0] != '1'):
|
||||||
|
return True
|
||||||
|
if row[6] == '0':
|
||||||
|
timestamp = time.time()
|
||||||
|
params = {
|
||||||
|
'account_id' : row[1],
|
||||||
|
'orderid' : row[4],
|
||||||
|
'itemid' : row[2],
|
||||||
|
'amount' : row[3],
|
||||||
|
}
|
||||||
|
secret = 'fc38349c5d084e920925e614c420be9f'
|
||||||
|
md5signstr = md5Sign(params, secret, timestamp)
|
||||||
|
url = conf['notify_url'] + '×tamp=' + str(timestamp) + '&sign=' + md5signstr
|
||||||
|
req = urllib.request.Request(url)
|
||||||
|
data = urllib.request.urlopen(req).read()
|
||||||
|
info('sendNotify end')
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
def sendNotify(conf, sendtime):
|
def sendNotify(conf, sendtime):
|
||||||
try:
|
try:
|
||||||
info('sendNotify start')
|
if len(confirmed_order_list) <= 0:
|
||||||
params = {'key' : 'kingsome'}
|
fetchConfirmedOrderList();
|
||||||
secret = 'fc38349c5d084e920925e614c420be9f'
|
handled_cout = 0
|
||||||
timestamp = time.time()
|
while len(confirmed_order_list) > 0 and handled_cout < 50:
|
||||||
md5signstr = md5Sign(params, secret, timestamp)
|
confirmed_order = confirmed_order_list[0]
|
||||||
url = conf['notify_url'] + '×tamp=' + str(timestamp) + '&sign=' + md5signstr
|
if sendOneOrder(confirmed_order['idx'], confirmed_order['orderid']):
|
||||||
req = urllib.request.Request(url)
|
confirmed_order_list.pop(0)
|
||||||
data = urllib.request.urlopen(req).read()
|
handled_cout += 1
|
||||||
info('sendNotify end')
|
else:
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
info('sendNotifu error: ' + str(e))
|
info('sendNotifu error: ' + str(e))
|
||||||
|
|
||||||
#进入下一次循环
|
#进入下一次循环
|
||||||
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime,
|
if len(confirmed_order_list) > 0:
|
||||||
lambda : sendNotify(conf, sendtime))
|
tornado.ioloop.IOLoop.current().call_at(time.time() + 1,
|
||||||
|
lambda : sendNotify(conf, sendtime))
|
||||||
|
else:
|
||||||
|
tornado.ioloop.IOLoop.current().call_at(time.time() + sendtime,
|
||||||
|
lambda : sendNotify(conf, sendtime))
|
||||||
|
|
||||||
class SelfCheckingHandler(tornado.web.RequestHandler):
|
class SelfCheckingHandler(tornado.web.RequestHandler):
|
||||||
|
|
||||||
@ -73,6 +131,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(getDaySeconds(time.time(), 1) + conf['notifytime'],
|
tornado.ioloop.IOLoop.current().call_at(time.time()+ conf['notifytime'],
|
||||||
lambda : sendNotify(conf, conf['notifytime']))
|
lambda : sendNotify(conf, conf['notifytime']))
|
||||||
tornado.ioloop.IOLoop.current().start()
|
tornado.ioloop.IOLoop.current().start()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user