From bb11ed8c20fe61d82d808afc94ccfd15b07ea574 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 29 Jan 2019 14:42:51 +0800 Subject: [PATCH] update --- tools/kefu_robot.py | 28 ++++++++++------------ webapp/controller/KefuController.class.php | 15 ++++++++---- webapp/endecrypt/wxBizMsgCrypt.php | 6 ++--- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/tools/kefu_robot.py b/tools/kefu_robot.py index 0978736..c730b6f 100644 --- a/tools/kefu_robot.py +++ b/tools/kefu_robot.py @@ -10,19 +10,18 @@ import tornado.ioloop import tornado.web def md5Sign(params, secret, timestamp, connstr = '&', secret_connstr = ':'): - print('md5in') - print(params) params_str = '' for key in sorted(params.keys()): params_str = params_str + key + '=' + str(params[key]) + connstr - print(params_str) if params_str != '' and connstr != '': params_str = params_str[0:-1] - m5 = hashlib.md5() - str1 = params_str + secret_connstr + str(timestamp) + secret - m5.update(str1) - return m5.hexdigest() + try: + m5 = hashlib.md5() + m5.update(str1.encode('utf-8')) + return m5.hexdigest() + except Exception as e: + print('md5Sign error: ' + str(e)) def getDaySeconds(time_val, incdays): time_zone = 8 @@ -35,13 +34,11 @@ def sendNotify(conf, sendtime): secret = 'fc38349c5d084e920925e614c420be9f' timestamp = time.time() md5signstr = md5Sign(params, secret, timestamp) - print(md5signstr) - url = conf['notify_url'] + '×tamp=' + timestamp + '&sign=' + md5signstr - print(url) + url = conf['notify_url'] + '×tamp=' + str(timestamp) + '&sign=' + md5signstr req = urllib.request.Request(url) - data = urllib.request.urlopen(req).readall() - except: - pass + data = urllib.request.urlopen(req).read() + except Exception as e: + print('sendNotifu error: ' + str(e)) #进入下一次循环 tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime, @@ -63,14 +60,13 @@ def make_app(): ]) if __name__ == "__main__": + print('start!') conf = json.loads(open('../config/kefu_robot.json', 'r').read()) - app = make_app() app.listen(conf['listen_port']) + tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime1'], lambda : sendNotify(conf, conf['sendtime1'])) tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime2'], lambda : sendNotify(conf, conf['sendtime2'])) - tornado.ioloop.IOLoop.current().call_at(time.time() + 3, - lambda : sendNotify(conf, 30)) tornado.ioloop.IOLoop.current().start() diff --git a/webapp/controller/KefuController.class.php b/webapp/controller/KefuController.class.php index aa19232..8e1ff88 100644 --- a/webapp/controller/KefuController.class.php +++ b/webapp/controller/KefuController.class.php @@ -28,6 +28,12 @@ class KefuController { return $conn; } + private function getDaySeconds($time_val, $incdays) + { + $time_zone = 8; + return int(($time_val + $time_zone * 3600)/3600/24 + $incdays) * 3600 * 24 - 3600 * $time_zone; + } + private function translateAttachments($config) { $attachments = ''; @@ -152,7 +158,7 @@ class KefuController { { if (phpcommon\md5Sign(array ( - 'exclude_accountids' => $_REQUEST['key'] + 'key' => 'kingsome' ), 'fc38349c5d084e920925e614c420be9f', $_REQUEST['timestamp'] @@ -241,12 +247,12 @@ class KefuController { } foreach ($rows as $row) { $shareInfo = require('../config/kefu.share.config.php'); - $gameid = phpcommon/extractGameId($row['accountid']); - $this->sendKefuMsg($userInfo['accountid'], + $gameid = phpcommon\extractGameId($row['accountid']); + $this->sendKefuMsg($row['accountid'], array ( "touser" => $row['openid'], "msgtype" => "miniprogrampage", - "miniprogrampage" =>$shareInfo[$gameid] + "miniprogrampage" => $shareInfo[$gameid] )); if ($row['idx'] > $last_idx) { @@ -360,5 +366,4 @@ class KefuController { return ''; } } - } diff --git a/webapp/endecrypt/wxBizMsgCrypt.php b/webapp/endecrypt/wxBizMsgCrypt.php index ba290ad..bfc90b3 100644 --- a/webapp/endecrypt/wxBizMsgCrypt.php +++ b/webapp/endecrypt/wxBizMsgCrypt.php @@ -101,7 +101,7 @@ class WXBizMsgCrypt //生成安全签名 $sha1 = new SHA1; - error_log('加密encrypt:' . $encrypt); + #error_log('加密encrypt:' . $encrypt); $array = $sha1->getSHA1($this->token, $timeStamp, $nonce, $encrypt); $ret = $array[0]; if ($ret != 0) { @@ -217,8 +217,8 @@ class WXBizMsgCrypt } $signature = $array[1]; - error_log($signature); - error_log($msgSignature); + #error_log($signature); + #error_log($msgSignature); if ($signature != $msgSignature) { return ErrorCode::$ValidateSignatureError; }