update
This commit is contained in:
parent
0b8e67ddd9
commit
f4c7928fed
6
config/kefu_robot.json
Normal file
6
config/kefu_robot.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"listen_port": 10001,
|
||||||
|
"notify_url": "https://kefu-test.kingsome.cn/webapp/index.php?c=Kefu&a=sendMsgAllUser",
|
||||||
|
"sendtime1": 32400,
|
||||||
|
"sendtime2": 64800
|
||||||
|
}
|
@ -78,7 +78,7 @@ class KefuController {
|
|||||||
array(
|
array(
|
||||||
':accountid' => $accountid,
|
':accountid' => $accountid,
|
||||||
));
|
));
|
||||||
error_log('check_Exist:' . json_encode($row));
|
#error_log('check_Exist:' . json_encode($row));
|
||||||
if ($row) {
|
if ($row) {
|
||||||
return $row;
|
return $row;
|
||||||
}else{
|
}else{
|
||||||
@ -97,7 +97,7 @@ class KefuController {
|
|||||||
':accountid' => $accountid,
|
':accountid' => $accountid,
|
||||||
':awardtime' => $time
|
':awardtime' => $time
|
||||||
));
|
));
|
||||||
error_log('saveAwartTime:' . json_encode($row));
|
#error_log('saveAwartTime:' . json_encode($row));
|
||||||
return $row;
|
return $row;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ class KefuController {
|
|||||||
':accountid' => $accountid,
|
':accountid' => $accountid,
|
||||||
));
|
));
|
||||||
|
|
||||||
error_log('getAward_row:' . json_encode($row));
|
#error_log('getAward_row:' . json_encode($row));
|
||||||
if ($row) {
|
if ($row) {
|
||||||
return $row['awardtime'];
|
return $row['awardtime'];
|
||||||
} else {
|
} else {
|
||||||
@ -124,7 +124,6 @@ class KefuController {
|
|||||||
|
|
||||||
private function getAwardDBMaxIdx($conn)
|
private function getAwardDBMaxIdx($conn)
|
||||||
{
|
{
|
||||||
|
|
||||||
$select_tbl_name = 'accounts_kefu';
|
$select_tbl_name = 'accounts_kefu';
|
||||||
$row = $conn->execQueryOne('SELECT idx ' .
|
$row = $conn->execQueryOne('SELECT idx ' .
|
||||||
"FROM $select_tbl_name GROUP BY idx DESC LIMIT 1;"
|
"FROM $select_tbl_name GROUP BY idx DESC LIMIT 1;"
|
||||||
@ -142,12 +141,12 @@ class KefuController {
|
|||||||
|
|
||||||
$select_tbl_name = 'accounts_kefu';
|
$select_tbl_name = 'accounts_kefu';
|
||||||
$row = $conn->execQuery("SELECT * FROM $select_tbl_name " .
|
$row = $conn->execQuery("SELECT * FROM $select_tbl_name " .
|
||||||
"where idx >= :min_idx and idx < :max_idx;",
|
"WHERE idx >= :min_idx AND idx < :max_idx;",
|
||||||
array(
|
array(
|
||||||
':min_idx' => $min_idx,
|
':min_idx' => $min_idx,
|
||||||
':max_idx' => $max_idx
|
':max_idx' => $max_idx
|
||||||
));
|
));
|
||||||
error_log('getAccountsKefuInfo:' . json_encode($row));
|
#error_log('getAccountsKefuInfo:' . json_encode($row));
|
||||||
if ($row) {
|
if ($row) {
|
||||||
return $row;
|
return $row;
|
||||||
} else {
|
} else {
|
||||||
@ -167,16 +166,16 @@ class KefuController {
|
|||||||
$url = 'https://center.kingsome.cn/api/replays/';
|
$url = 'https://center.kingsome.cn/api/replays/';
|
||||||
}
|
}
|
||||||
$url .= $gameid . '/' . $condition;
|
$url .= $gameid . '/' . $condition;
|
||||||
error_log($url);
|
#error_log($url);
|
||||||
$response = '';
|
$response = '';
|
||||||
$params = array();
|
$params = array();
|
||||||
if (!phpcommon\HttpClient::get($url,$params,$response)) {
|
if (!phpcommon\HttpClient::get($url,$params,$response)) {
|
||||||
error_log('奖励配置发送失败');
|
#error_log('奖励配置发送失败');
|
||||||
die();
|
die();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$ret = json_decode($response, true);
|
$ret = json_decode($response, true);
|
||||||
error_log('awardconfig:' . $response);
|
#error_log('awardconfig:' . $response);
|
||||||
if($ret['errcode'] == 0) {
|
if($ret['errcode'] == 0) {
|
||||||
return $ret['items'];
|
return $ret['items'];
|
||||||
} else {
|
} else {
|
||||||
@ -189,9 +188,9 @@ class KefuController {
|
|||||||
private function translateAttachments($config)
|
private function translateAttachments($config)
|
||||||
{
|
{
|
||||||
$attachments = '';
|
$attachments = '';
|
||||||
error_log('config:' . json_encode($config));
|
#error_log('config:' . json_encode($config));
|
||||||
foreach ($config as $attachment) {
|
foreach ($config as $attachment) {
|
||||||
error_log('attachment:'. json_encode($attachment));
|
#error_log('attachment:'. json_encode($attachment));
|
||||||
$attachments .= $attachment['item_id'] . ':' . $attachment['count'] . ';';
|
$attachments .= $attachment['item_id'] . ':' . $attachment['count'] . ';';
|
||||||
}
|
}
|
||||||
return $attachments;
|
return $attachments;
|
||||||
@ -227,7 +226,7 @@ class KefuController {
|
|||||||
$sendtime = time();
|
$sendtime = time();
|
||||||
$ext = '';
|
$ext = '';
|
||||||
$expire_time = time() + 60 * 60 * 24 * 1;
|
$expire_time = time() + 60 * 60 * 24 * 1;
|
||||||
error_log('congifsendaward:' . json_encode($config));
|
#error_log('congifsendaward:' . json_encode($config));
|
||||||
$attachments = $this->translateAttachments($config);
|
$attachments = $this->translateAttachments($config);
|
||||||
$game_id = phpcommon\extractGameId($accountid);
|
$game_id = phpcommon\extractGameId($accountid);
|
||||||
|
|
||||||
@ -235,15 +234,15 @@ class KefuController {
|
|||||||
"&mail_subtype=$mail_subtype&subject=$subject&content=$content&sendtime=$sendtime" .
|
"&mail_subtype=$mail_subtype&subject=$subject&content=$content&sendtime=$sendtime" .
|
||||||
"&ext=$ext&expire_time=$expire_time&attachments=$attachments&game_id=$game_id";
|
"&ext=$ext&expire_time=$expire_time&attachments=$attachments&game_id=$game_id";
|
||||||
|
|
||||||
error_log('sendAward.url:' . $url);
|
#error_log('sendAward.url:' . $url);
|
||||||
|
|
||||||
$response = '';
|
$response = '';
|
||||||
if (!phpcommon\HttpClient::get($url, array(), $response)) {
|
if (!phpcommon\HttpClient::get($url, array(), $response)) {
|
||||||
error_log('邮件发送失败');
|
#error_log('邮件发送失败');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$data = json_decode($response, true);
|
$data = json_decode($response, true);
|
||||||
error_log('邮件返回:' . $response);
|
#error_log('邮件返回:' . $response);
|
||||||
if(isset($data) && $data['errcode'] == 0) {
|
if(isset($data) && $data['errcode'] == 0) {
|
||||||
return true;
|
return true;
|
||||||
} else{
|
} else{
|
||||||
@ -257,7 +256,7 @@ class KefuController {
|
|||||||
{
|
{
|
||||||
|
|
||||||
$gameid = $_REQUEST['gameid'];
|
$gameid = $_REQUEST['gameid'];
|
||||||
error_log($gameid);
|
#error_log($gameid);
|
||||||
$config_name = "../config/game$gameid/weixin/config.php";
|
$config_name = "../config/game$gameid/weixin/config.php";
|
||||||
require $config_name;
|
require $config_name;
|
||||||
if ( isset($_REQUEST['echostr'])) {
|
if ( isset($_REQUEST['echostr'])) {
|
||||||
@ -308,18 +307,18 @@ class KefuController {
|
|||||||
$text = $postStr;
|
$text = $postStr;
|
||||||
$errCode = $pc->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str);
|
$errCode = $pc->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str);
|
||||||
if ($errCode == 0) {
|
if ($errCode == 0) {
|
||||||
error_log("加密后: " . $encryptMsg_str . "\n");
|
#error_log("加密后: " . $encryptMsg_str . "\n");
|
||||||
$encryptMsg = json_decode($encryptMsg_str, true);
|
$encryptMsg = json_decode($encryptMsg_str, true);
|
||||||
|
|
||||||
$errCode = $pc->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce,
|
$errCode = $pc->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce,
|
||||||
$encryptMsg_str, $postStr2);
|
$encryptMsg_str, $postStr2);
|
||||||
error_log('error_log:' . json_encode($errCode));
|
#error_log('#error_log:' . json_encode($errCode));
|
||||||
if ($errCode == 0) {
|
if ($errCode == 0) {
|
||||||
|
|
||||||
error_log("解密后: " . $postStr2 . "\n");
|
#error_log("解密后: " . $postStr2 . "\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error_log($errCode . "\n");
|
#error_log($errCode . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -327,7 +326,7 @@ class KefuController {
|
|||||||
private function sendMsg($data, $accountid)
|
private function sendMsg($data, $accountid)
|
||||||
{
|
{
|
||||||
$postarray = json_encode($data, JSON_UNESCAPED_UNICODE);
|
$postarray = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||||
error_log("sendData:" . $postarray);
|
#error_log("sendData:" . $postarray);
|
||||||
//POST发送https请求客服接口api
|
//POST发送https请求客服接口api
|
||||||
$access_token = $this->getAccessToken($accountid);
|
$access_token = $this->getAccessToken($accountid);
|
||||||
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
|
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
|
||||||
@ -338,21 +337,18 @@ class KefuController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$ret_info = json_decode($response, true);
|
$ret_info = json_decode($response, true);
|
||||||
error_log('sendMsgRet:' . $response);
|
#error_log('sendMsgRet:' . $response);
|
||||||
if ($ret_info['errcode'] == 0) {
|
if ($ret_info['errcode'] == 0) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error_log($response);
|
#error_log('sendMsg发送失败!');
|
||||||
echo(json_encode(array(
|
echo(0);
|
||||||
'errcode' => 0,
|
|
||||||
'errmsg' => ''
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mytest()
|
public function mytest()
|
||||||
{
|
{
|
||||||
error_log('mytest');
|
#error_log('mytest');
|
||||||
$openid = $_REQUEST['openid'];
|
$openid = $_REQUEST['openid'];
|
||||||
$shareInfo = require('../config/kefu.share.config.php');
|
$shareInfo = require('../config/kefu.share.config.php');
|
||||||
$miniprogrampateInfo = $shareInfo['1011'];
|
$miniprogrampateInfo = $shareInfo['1011'];
|
||||||
@ -386,7 +382,7 @@ class KefuController {
|
|||||||
"msgtype" => "miniprogrampage",
|
"msgtype" => "miniprogrampage",
|
||||||
"miniprogrampage" => $miniprogrampateInfo
|
"miniprogrampage" => $miniprogrampateInfo
|
||||||
);
|
);
|
||||||
error_log('sendmsg11111:' . json_encode($data));
|
#error_log('sendmsg11111:' . json_encode($data));
|
||||||
$this->sendMsg($data, $userInfo['accountid']);
|
$this->sendMsg($data, $userInfo['accountid']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,15 +391,14 @@ class KefuController {
|
|||||||
{
|
{
|
||||||
$selectOneCount = 20;
|
$selectOneCount = 20;
|
||||||
$selectCount = $maxIdx - $minIdx;
|
$selectCount = $maxIdx - $minIdx;
|
||||||
$remainderTimes = ($selectCount % $selectOneCount) ? 1 : 0;
|
$selectTimes = ceil($selectCount / $selectOneCount);
|
||||||
$selectTimes = floor($selectCount / $selectOneCount) + $remainderTimes;
|
|
||||||
|
|
||||||
error_log('selectCount:' . $selectCount);
|
#error_log('selectCount:' . $selectCount);
|
||||||
error_log('selectTimes:' . $selectTimes);
|
#error_log('selectTimes:' . $selectTimes);
|
||||||
|
|
||||||
$selectMin = $minIdx;
|
$selectMin = $minIdx;
|
||||||
for ($i = 0; $i < $selectTimes; $i++ ) {
|
for ($i = 0; $i < $selectTimes; $i++ ) {
|
||||||
error_log('selectMin:' . $selectMin);
|
#error_log('selectMin:' . $selectMin);
|
||||||
$arrayInfo = $this->getAccountsKefuInfo($selectMin, $selectMin + $selectOneCount, $conn);
|
$arrayInfo = $this->getAccountsKefuInfo($selectMin, $selectMin + $selectOneCount, $conn);
|
||||||
$this->sendMsgSomeUser($arrayInfo);
|
$this->sendMsgSomeUser($arrayInfo);
|
||||||
$selectMin = $selectMin + $selectOneCount;
|
$selectMin = $selectMin + $selectOneCount;
|
||||||
@ -413,7 +408,7 @@ class KefuController {
|
|||||||
|
|
||||||
public function sendMsgAllUser()
|
public function sendMsgAllUser()
|
||||||
{
|
{
|
||||||
error_log('sendMsgAllUser:');
|
#error_log('sendMsgAllUser:');
|
||||||
|
|
||||||
$mysqls = $this->getAllMysql();
|
$mysqls = $this->getAllMysql();
|
||||||
foreach($mysqls as $mysql_conf) {
|
foreach($mysqls as $mysql_conf) {
|
||||||
@ -427,13 +422,13 @@ class KefuController {
|
|||||||
|
|
||||||
private function disposeText($postArr, $accountid)
|
private function disposeText($postArr, $accountid)
|
||||||
{
|
{
|
||||||
error_log('text');
|
#error_log('text');
|
||||||
$openid = $postArr['FromUserName'];
|
$openid = $postArr['FromUserName'];
|
||||||
$CreateTime = $postArr['CreateTime'];
|
$CreateTime = $postArr['CreateTime'];
|
||||||
$test = $postArr['Content'];
|
$text = $postArr['Content'];
|
||||||
$gameid = phpcommon\extractGameId($accountid);
|
$gameid = phpcommon\extractGameId($accountid);
|
||||||
$awardConfig = $this->getAwardConfig($gameid, $test);
|
$awardConfig = $this->getAwardConfig($gameid, $text);
|
||||||
error_log('awardConfig:' . json_encode($awardConfig));
|
#error_log('awardConfig:' . json_encode($awardConfig));
|
||||||
if (isset($awardConfig)) {
|
if (isset($awardConfig)) {
|
||||||
$checkTimeRet = $this->checkAward($accountid);
|
$checkTimeRet = $this->checkAward($accountid);
|
||||||
if ($checkTimeRet)
|
if ($checkTimeRet)
|
||||||
@ -443,7 +438,7 @@ class KefuController {
|
|||||||
$time = time();
|
$time = time();
|
||||||
$save_ret = $this->saveAwardTimeToDB($accountid, $time);
|
$save_ret = $this->saveAwardTimeToDB($accountid, $time);
|
||||||
if ($save_ret) {
|
if ($save_ret) {
|
||||||
error_log('save_ret:' . $save_ret);
|
#error_log('save_ret:' . $save_ret);
|
||||||
$content = '奖励领取成功,请查收邮件!';
|
$content = '奖励领取成功,请查收邮件!';
|
||||||
$data = array (
|
$data = array (
|
||||||
"touser" => $openid,
|
"touser" => $openid,
|
||||||
@ -485,18 +480,17 @@ class KefuController {
|
|||||||
private function disposeEvent($postArr, $accountid)
|
private function disposeEvent($postArr, $accountid)
|
||||||
{
|
{
|
||||||
|
|
||||||
error_log('disposeEvent');
|
#error_log('disposeEvent');
|
||||||
$openid = $postArr['FromUserName'];
|
$openid = $postArr['FromUserName'];
|
||||||
$CreateTime = $postArr['CreateTime'];
|
$CreateTime = $postArr['CreateTime'];
|
||||||
|
|
||||||
if($postArr['Event'] == 'user_enter_tempsession')
|
if($postArr['Event'] == 'user_enter_tempsession')
|
||||||
{
|
{
|
||||||
$check_ret = $this->checkAccountKefuExist($accountid);
|
$check_ret = $this->checkAccountKefuExist($accountid);
|
||||||
error_log('check_ret:' . json_encode($check_ret));
|
#error_log('check_ret:' . json_encode($check_ret));
|
||||||
if (empty($check_ret)) {
|
if (empty($check_ret)) {
|
||||||
|
|
||||||
error_log('dot save to db');
|
#error_log('dot save to db');
|
||||||
|
|
||||||
$kefu_info = array(
|
$kefu_info = array(
|
||||||
'accountid' => $accountid,
|
'accountid' => $accountid,
|
||||||
'channel' => 6001,
|
'channel' => 6001,
|
||||||
@ -521,8 +515,8 @@ class KefuController {
|
|||||||
{
|
{
|
||||||
$postStr_key = $GLOBALS ["HTTP_RAW_POST_DATA" ];
|
$postStr_key = $GLOBALS ["HTTP_RAW_POST_DATA" ];
|
||||||
|
|
||||||
error_log('!!!begin:' . $postStr_key);
|
#error_log('!!!begin:' . $postStr_key);
|
||||||
error_log('request:' . json_encode($_REQUEST));
|
#error_log('request:' . json_encode($_REQUEST));
|
||||||
$pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID);
|
$pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID);
|
||||||
|
|
||||||
$gameid = $_REQUEST['gameid'];
|
$gameid = $_REQUEST['gameid'];
|
||||||
@ -532,10 +526,10 @@ class KefuController {
|
|||||||
$timeStamp = $_REQUEST['timestamp'];
|
$timeStamp = $_REQUEST['timestamp'];
|
||||||
$nonce = $_REQUEST['nonce'];
|
$nonce = $_REQUEST['nonce'];
|
||||||
$errCode = $pc->decryptJsonMsg($msg_sign, $timeStamp, $nonce, $postStr_key, $postStr);
|
$errCode = $pc->decryptJsonMsg($msg_sign, $timeStamp, $nonce, $postStr_key, $postStr);
|
||||||
error_log('error_log:' . json_encode($errCode));
|
#error_log('#error_log:' . json_encode($errCode));
|
||||||
if ($errCode == 0) {
|
if ($errCode == 0) {
|
||||||
|
|
||||||
error_log("解密后: " . $postStr . "\n");
|
#error_log("解密后: " . $postStr . "\n");
|
||||||
|
|
||||||
if (!empty( $postStr ) && is_string( $postStr )){
|
if (!empty( $postStr ) && is_string( $postStr )){
|
||||||
|
|
||||||
@ -558,7 +552,7 @@ class KefuController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error_log($errCode . "\n");
|
#error_log($errCode . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -568,14 +562,14 @@ class KefuController {
|
|||||||
|
|
||||||
$r = $this->getRedis($accountid);
|
$r = $this->getRedis($accountid);
|
||||||
$access_token = $r->get('kf_token:' . $accountid . ':');
|
$access_token = $r->get('kf_token:' . $accountid . ':');
|
||||||
error_log('acc_token:' . $access_token);
|
##error_log('acc_token:' . $access_token);
|
||||||
if (!empty($access_token)) {
|
if (!empty($access_token)) {
|
||||||
return $access_token;
|
return $access_token;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$gameid = phpcommon\extractGameId($accountid);
|
$gameid = phpcommon\extractGameId($accountid);
|
||||||
$config_name = "../config/game$gameid/weixin/config.php";
|
$config_name = "../config/game$gameid/weixin/config.php";
|
||||||
require $config_name;
|
@require $config_name;
|
||||||
|
|
||||||
$appid = WEIXIN_APP_ID;
|
$appid = WEIXIN_APP_ID;
|
||||||
$appkey = WEIXIN_APP_SECRET;
|
$appkey = WEIXIN_APP_SECRET;
|
||||||
@ -588,7 +582,7 @@ class KefuController {
|
|||||||
phpcommon\sendError(ERR_INTERNAL, '系统繁忙');
|
phpcommon\sendError(ERR_INTERNAL, '系统繁忙');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error_log('response_token:' . $response);
|
#error_log('response_token:' . $response);
|
||||||
$res = json_decode($response, true);
|
$res = json_decode($response, true);
|
||||||
if ( isset($res['access_token']) ) {
|
if ( isset($res['access_token']) ) {
|
||||||
//刚获取的token放到redis中 //微信限制过期时间为两小时
|
//刚获取的token放到redis中 //微信限制过期时间为两小时
|
||||||
|
15
webapp/controller/OpsController.class.php
Normal file
15
webapp/controller/OpsController.class.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class OpsController {
|
||||||
|
|
||||||
|
public function selfChecking()
|
||||||
|
{
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'healthy' => 1,
|
||||||
|
'max_rundelay' => 1,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user