update
This commit is contained in:
parent
d607d55792
commit
bb11ed8c20
@ -10,19 +10,18 @@ import tornado.ioloop
|
|||||||
import tornado.web
|
import tornado.web
|
||||||
|
|
||||||
def md5Sign(params, secret, timestamp, connstr = '&', secret_connstr = ':'):
|
def md5Sign(params, secret, timestamp, connstr = '&', secret_connstr = ':'):
|
||||||
print('md5in')
|
|
||||||
print(params)
|
|
||||||
params_str = ''
|
params_str = ''
|
||||||
for key in sorted(params.keys()):
|
for key in sorted(params.keys()):
|
||||||
params_str = params_str + key + '=' + str(params[key]) + connstr
|
params_str = params_str + key + '=' + str(params[key]) + connstr
|
||||||
print(params_str)
|
|
||||||
if params_str != '' and connstr != '':
|
if params_str != '' and connstr != '':
|
||||||
params_str = params_str[0:-1]
|
params_str = params_str[0:-1]
|
||||||
m5 = hashlib.md5()
|
|
||||||
|
|
||||||
str1 = params_str + secret_connstr + str(timestamp) + secret
|
str1 = params_str + secret_connstr + str(timestamp) + secret
|
||||||
m5.update(str1)
|
try:
|
||||||
return m5.hexdigest()
|
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):
|
def getDaySeconds(time_val, incdays):
|
||||||
time_zone = 8
|
time_zone = 8
|
||||||
@ -35,13 +34,11 @@ def sendNotify(conf, sendtime):
|
|||||||
secret = 'fc38349c5d084e920925e614c420be9f'
|
secret = 'fc38349c5d084e920925e614c420be9f'
|
||||||
timestamp = time.time()
|
timestamp = time.time()
|
||||||
md5signstr = md5Sign(params, secret, timestamp)
|
md5signstr = md5Sign(params, secret, timestamp)
|
||||||
print(md5signstr)
|
url = conf['notify_url'] + '×tamp=' + str(timestamp) + '&sign=' + md5signstr
|
||||||
url = conf['notify_url'] + '×tamp=' + timestamp + '&sign=' + md5signstr
|
|
||||||
print(url)
|
|
||||||
req = urllib.request.Request(url)
|
req = urllib.request.Request(url)
|
||||||
data = urllib.request.urlopen(req).readall()
|
data = urllib.request.urlopen(req).read()
|
||||||
except:
|
except Exception as e:
|
||||||
pass
|
print('sendNotifu error: ' + str(e))
|
||||||
|
|
||||||
#进入下一次循环
|
#进入下一次循环
|
||||||
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime,
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + sendtime,
|
||||||
@ -63,14 +60,13 @@ def make_app():
|
|||||||
])
|
])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
print('start!')
|
||||||
conf = json.loads(open('../config/kefu_robot.json', 'r').read())
|
conf = json.loads(open('../config/kefu_robot.json', 'r').read())
|
||||||
|
|
||||||
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['sendtime1'],
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime1'],
|
||||||
lambda : sendNotify(conf, conf['sendtime1']))
|
lambda : sendNotify(conf, conf['sendtime1']))
|
||||||
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime2'],
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['sendtime2'],
|
||||||
lambda : sendNotify(conf, 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()
|
tornado.ioloop.IOLoop.current().start()
|
||||||
|
@ -28,6 +28,12 @@ class KefuController {
|
|||||||
return $conn;
|
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)
|
private function translateAttachments($config)
|
||||||
{
|
{
|
||||||
$attachments = '';
|
$attachments = '';
|
||||||
@ -152,7 +158,7 @@ class KefuController {
|
|||||||
{
|
{
|
||||||
if (phpcommon\md5Sign(array
|
if (phpcommon\md5Sign(array
|
||||||
(
|
(
|
||||||
'exclude_accountids' => $_REQUEST['key']
|
'key' => 'kingsome'
|
||||||
),
|
),
|
||||||
'fc38349c5d084e920925e614c420be9f',
|
'fc38349c5d084e920925e614c420be9f',
|
||||||
$_REQUEST['timestamp']
|
$_REQUEST['timestamp']
|
||||||
@ -241,12 +247,12 @@ class KefuController {
|
|||||||
}
|
}
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$shareInfo = require('../config/kefu.share.config.php');
|
$shareInfo = require('../config/kefu.share.config.php');
|
||||||
$gameid = phpcommon/extractGameId($row['accountid']);
|
$gameid = phpcommon\extractGameId($row['accountid']);
|
||||||
$this->sendKefuMsg($userInfo['accountid'],
|
$this->sendKefuMsg($row['accountid'],
|
||||||
array (
|
array (
|
||||||
"touser" => $row['openid'],
|
"touser" => $row['openid'],
|
||||||
"msgtype" => "miniprogrampage",
|
"msgtype" => "miniprogrampage",
|
||||||
"miniprogrampage" =>$shareInfo[$gameid]
|
"miniprogrampage" => $shareInfo[$gameid]
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($row['idx'] > $last_idx) {
|
if ($row['idx'] > $last_idx) {
|
||||||
@ -360,5 +366,4 @@ class KefuController {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class WXBizMsgCrypt
|
|||||||
|
|
||||||
//生成安全签名
|
//生成安全签名
|
||||||
$sha1 = new SHA1;
|
$sha1 = new SHA1;
|
||||||
error_log('加密encrypt:' . $encrypt);
|
#error_log('加密encrypt:' . $encrypt);
|
||||||
$array = $sha1->getSHA1($this->token, $timeStamp, $nonce, $encrypt);
|
$array = $sha1->getSHA1($this->token, $timeStamp, $nonce, $encrypt);
|
||||||
$ret = $array[0];
|
$ret = $array[0];
|
||||||
if ($ret != 0) {
|
if ($ret != 0) {
|
||||||
@ -217,8 +217,8 @@ class WXBizMsgCrypt
|
|||||||
}
|
}
|
||||||
|
|
||||||
$signature = $array[1];
|
$signature = $array[1];
|
||||||
error_log($signature);
|
#error_log($signature);
|
||||||
error_log($msgSignature);
|
#error_log($msgSignature);
|
||||||
if ($signature != $msgSignature) {
|
if ($signature != $msgSignature) {
|
||||||
return ErrorCode::$ValidateSignatureError;
|
return ErrorCode::$ValidateSignatureError;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user