部分验证移植到登陆服前 备份
This commit is contained in:
parent
eb01bd5ecd
commit
94cb7822fe
@ -5,4 +5,6 @@ const WEIXIN_APP_ID = 'wxfa9c8ea6a55f00d0';
|
||||
const WEIXIN_APP_SECRET = '999712592d00ad2f75b04421e030ba04';
|
||||
const WEIXIN_API_URL = 'https://api.weixin.qq.com/sns/jscode2session';
|
||||
const WEIXIN_MSG_KEY = 'MzebhFcmcIFT85xOr5TnrDVeLx5HMbpgAl5gw2PVvhX';
|
||||
const WEIXIN_TOKEN = 'kingsome';
|
||||
const WEIXIN_TOKEN = 'kingsome';
|
||||
const WEIXIN_THUMB_URL = 'http://mmbiz.qpic.cn/mmbiz_jpg/6zVc6fZKcB3zuNoqEULTjPSHPcaR26qciaSykxSCvw4SSq1I4Y6TAp7udB2BjST4YB9NedeRFfywlUt3AunAcJg/0';
|
||||
const WEIXIN_THUMB_MEDIA_ID = 'h2oYnOGns5T7wcJmjFGWTsYnkz3j9Et3258n9xZ8eezOj-8Dzsk23Ao6SzHgV20A';
|
||||
|
29
tools/kefu_robot.py
Normal file
29
tools/kefu_robot.py
Normal file
@ -0,0 +1,29 @@
|
||||
#coding utf8
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import json
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
|
||||
class SelfCheckingHandler(tornado.web.RequestHandler):
|
||||
|
||||
def get(self):
|
||||
self.write(json.dumps({
|
||||
'errcode': 0,
|
||||
'errmsg': '',
|
||||
'healthy': 1,
|
||||
'max_rundelay': 10
|
||||
}))
|
||||
|
||||
def make_app():
|
||||
return tornado.web.Application([
|
||||
(r"/webapp/index[\.]php", SelfCheckingHandler),
|
||||
])
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf = json.loads(open('config/kefu_redissave.json', 'r').read())
|
||||
|
||||
app = make_app()
|
||||
app.listen(conf['listen_port'])
|
||||
tornado.ioloop.IOLoop.current().start()
|
@ -18,23 +18,41 @@ class KefuController {
|
||||
return $r;
|
||||
}
|
||||
|
||||
protected function getMysql()
|
||||
protected function getMysql($accountid)
|
||||
{
|
||||
$mysql_conf = require('../config/kefu.mysql.cluster.php');
|
||||
$mysql_conf = getMysqlConfig(crc32($accountid));
|
||||
$conn = new phpcommon\Mysql(array(
|
||||
'host' => $mysql_conf[0]['host'],
|
||||
'port' => $mysql_conf[0]['port'],
|
||||
'user' => $mysql_conf[0]['user'],
|
||||
'passwd' => $mysql_conf[0]['passwd'],
|
||||
'host' => $mysql_conf['host'],
|
||||
'port' => $mysql_conf['port'],
|
||||
'user' => $mysql_conf['user'],
|
||||
'passwd' => $mysql_conf['passwd'],
|
||||
'dbname' => 'kefudb'
|
||||
));
|
||||
return $conn;
|
||||
}
|
||||
|
||||
private function getAppointMysql($mysql_conf)
|
||||
{
|
||||
$conn = new phpcommon\Mysql(array(
|
||||
'host' => $mysql_conf['host'],
|
||||
'port' => $mysql_conf['port'],
|
||||
'user' => $mysql_conf['user'],
|
||||
'passwd' => $mysql_conf['passwd'],
|
||||
'dbname' => 'kefudb'
|
||||
));
|
||||
return $conn;
|
||||
}
|
||||
|
||||
private function getAllMysql()
|
||||
{
|
||||
return require('../config/kefu.mysql.cluster.php');
|
||||
}
|
||||
|
||||
|
||||
#kefudb_info = array(accountid, channel, gameid, openid, awardtime)
|
||||
private function insertKefuInfoToDB($accountid, $kefu_info)
|
||||
{
|
||||
$conn = $this->getMysql();
|
||||
$conn = $this->getMysql($accountid);
|
||||
$tbl_name = 'accounts_kefu';
|
||||
$ret = $conn->execScript("INSERT INTO $tbl_name(" .
|
||||
'accountid, channel, gameid, openid, awardtime) ' .
|
||||
@ -52,7 +70,7 @@ class KefuController {
|
||||
|
||||
private function checkAccountKefuExist($accountid)
|
||||
{
|
||||
$conn = $this->getMysql();
|
||||
$conn = $this->getMysql($accountid);
|
||||
$select_tbl_name = 'accounts_kefu';
|
||||
|
||||
$row = $conn->execQueryOne('SELECT accountid ' .
|
||||
@ -60,7 +78,7 @@ class KefuController {
|
||||
array(
|
||||
':accountid' => $accountid,
|
||||
));
|
||||
error_log('check_row:' . json_encode($row));
|
||||
error_log('check_Exist:' . json_encode($row));
|
||||
if ($row) {
|
||||
return $row;
|
||||
}else{
|
||||
@ -70,7 +88,7 @@ class KefuController {
|
||||
|
||||
private function saveAwardTimeToDB($accountid, $time)
|
||||
{
|
||||
$conn = $this->getMysql();
|
||||
$conn = $this->getMysql($accountid);
|
||||
$select_tbl_name = 'accounts_kefu';
|
||||
$row = $conn->execScript("UPDATE $select_tbl_name SET " .
|
||||
' awardtime=:awardtime ' .
|
||||
@ -78,9 +96,8 @@ class KefuController {
|
||||
array(
|
||||
':accountid' => $accountid,
|
||||
':awardtime' => $time
|
||||
)
|
||||
);
|
||||
error_log('award_check_row:' . json_encode($row));
|
||||
));
|
||||
error_log('saveAwartTime:' . json_encode($row));
|
||||
return $row;
|
||||
|
||||
}
|
||||
@ -88,7 +105,7 @@ class KefuController {
|
||||
private function getAwardtimeFromDB($accountid)
|
||||
{
|
||||
|
||||
$conn = $this->getMysql();
|
||||
$conn = $this->getMysql($accountid);
|
||||
$select_tbl_name = 'accounts_kefu';
|
||||
$row = $conn->execQueryOne('SELECT awardtime ' .
|
||||
"FROM $select_tbl_name WHERE accountid = :accountid ;",
|
||||
@ -96,7 +113,7 @@ class KefuController {
|
||||
':accountid' => $accountid,
|
||||
));
|
||||
|
||||
error_log('checkAward_row:' . json_encode($row));
|
||||
error_log('getAward_row:' . json_encode($row));
|
||||
if ($row) {
|
||||
return $row['awardtime'];
|
||||
} else {
|
||||
@ -105,6 +122,41 @@ class KefuController {
|
||||
|
||||
}
|
||||
|
||||
private function getAwardDBMaxIdx($conn)
|
||||
{
|
||||
|
||||
$select_tbl_name = 'accounts_kefu';
|
||||
$row = $conn->execQueryOne('SELECT idx ' .
|
||||
"FROM $select_tbl_name GROUP BY idx DESC LIMIT 1;"
|
||||
);
|
||||
if ($row) {
|
||||
return $row['idx'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getAccountsKefuInfo($min_idx, $max_idx, $conn)
|
||||
{
|
||||
|
||||
$select_tbl_name = 'accounts_kefu';
|
||||
$row = $conn->execQuery("SELECT * FROM $select_tbl_name " .
|
||||
"where idx >= :min_idx and idx < :max_idx;",
|
||||
array(
|
||||
':min_idx' => $min_idx,
|
||||
':max_idx' => $max_idx
|
||||
));
|
||||
error_log('getAccountsKefuInfo:' . json_encode($row));
|
||||
if ($row) {
|
||||
return $row;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function getAwardConfig($gameid, $condition)
|
||||
{
|
||||
|
||||
@ -186,7 +238,6 @@ class KefuController {
|
||||
error_log('sendAward.url:' . $url);
|
||||
|
||||
$response = '';
|
||||
|
||||
if (!phpcommon\HttpClient::get($url, array(), $response)) {
|
||||
error_log('邮件发送失败');
|
||||
return;
|
||||
@ -233,7 +284,6 @@ class KefuController {
|
||||
|
||||
private function checkSignature()
|
||||
{
|
||||
|
||||
$signature = $_REQUEST["signature"];
|
||||
$timestamp = $_REQUEST["timestamp"];
|
||||
$nonce = $_REQUEST["nonce"];
|
||||
@ -253,15 +303,16 @@ class KefuController {
|
||||
|
||||
private function encryptJson()
|
||||
{
|
||||
$pc2 = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID);
|
||||
$pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID);
|
||||
$encryptMsg = '';
|
||||
$text = $postStr;
|
||||
$errCode = $pc2->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str);
|
||||
$errCode = $pc->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str);
|
||||
if ($errCode == 0) {
|
||||
error_log("加密后: " . $encryptMsg_str . "\n");
|
||||
$encryptMsg = json_decode($encryptMsg_str, true);
|
||||
|
||||
$errCode = $pc2->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce, $encryptMsg_str, $postStr2);
|
||||
$errCode = $pc->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce,
|
||||
$encryptMsg_str, $postStr2);
|
||||
error_log('error_log:' . json_encode($errCode));
|
||||
if ($errCode == 0) {
|
||||
|
||||
@ -273,7 +324,7 @@ class KefuController {
|
||||
|
||||
}
|
||||
|
||||
private function sendMsg($data)
|
||||
private function sendMsg($data, $openid, $accountid)
|
||||
{
|
||||
$postarray = json_encode( $data ,JSON_UNESCAPED_UNICODE);
|
||||
error_log($postarray);
|
||||
@ -297,21 +348,38 @@ class KefuController {
|
||||
'errcode' => 0,
|
||||
'errmsg' => ''
|
||||
)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function mytest()
|
||||
{
|
||||
|
||||
error_log('mytest');
|
||||
$content = 'hahah';
|
||||
|
||||
die();
|
||||
$content = '回复【111】领取奖励!';
|
||||
$data = array (
|
||||
"touser"=> $_REQUEST['openid'],
|
||||
"msgtype"=>"text",
|
||||
"text"=> array ("content" => $content)
|
||||
);
|
||||
|
||||
$this->sendMsg($data);
|
||||
$this->sendMsg($data, $openid, $accountid);
|
||||
}
|
||||
|
||||
public function sendMsgAllUser()
|
||||
{
|
||||
error_log('sendMsgAllUser:');
|
||||
|
||||
|
||||
error_log($maxIdx);
|
||||
$mysqls = $this->getAllMysql();
|
||||
foreach($mysqls as $mysql_conf) {
|
||||
$conn = getAppointMysql($mysql_conf);
|
||||
$minIdx = 10000;
|
||||
$maxIdx = $this->getAwardDBMaxIdx($conn);
|
||||
$arrayinfo = $this->getAccountsKefuInfo($minIdx, $maxIdx, $conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -340,7 +408,7 @@ class KefuController {
|
||||
"msgtype" => "text",
|
||||
"text" => array ("content" => $content)
|
||||
);
|
||||
$this->sendMsg($data);
|
||||
$this->sendMsg($data, $openid, $accountid);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -350,9 +418,18 @@ class KefuController {
|
||||
"msgtype" => "text",
|
||||
"text" => array ("content" => $content)
|
||||
);
|
||||
$this->sendMsg($data);
|
||||
$this->sendMsg($data, $openid, $accountid);
|
||||
}
|
||||
} else {
|
||||
$content = '回复【111】领取奖励!';
|
||||
$data = array (
|
||||
"touser" => $openid,
|
||||
"msgtype" => "text",
|
||||
"text" => array ("content" => $content)
|
||||
);
|
||||
$this->sendMsg($data, $openid, $accountid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function disposeImage($postArr, $accountid)
|
||||
@ -360,7 +437,7 @@ class KefuController {
|
||||
$openid = $postArr['FromUserName'];
|
||||
$CreateTime = $postArr['CreateTime'];
|
||||
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
private function disposeEvent($postArr, $accountid)
|
||||
@ -393,7 +470,7 @@ class KefuController {
|
||||
"msgtype" => "text",
|
||||
"text" => array ("content" => $content)
|
||||
);
|
||||
$this->sendMsg($data);
|
||||
$this->sendMsg($data, $openid, $accountid);
|
||||
|
||||
}
|
||||
}
|
||||
@ -430,7 +507,7 @@ class KefuController {
|
||||
} elseif (!empty( $postArr ['MsgType']) && $postArr['MsgType'] == 'event' ){ // 进入客服动作
|
||||
$this->disposeEvent($postArr, $accountid);
|
||||
} else {
|
||||
exit ('aaa');
|
||||
exit ();
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -448,7 +525,7 @@ class KefuController {
|
||||
public function getAccessToken($openid, $accountid)
|
||||
{
|
||||
|
||||
$r = $this->getRedis($openid);
|
||||
$r = $this->getRedis($accountid);
|
||||
$access_token = $r->get('kf_token:' . $accountid . ':');
|
||||
error_log('acc_token:' . $access_token);
|
||||
if (!empty($access_token)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user