This commit is contained in:
aozhiwei 2019-01-24 15:30:00 +08:00
parent 0b8e67ddd9
commit f4c7928fed
3 changed files with 68 additions and 53 deletions

6
config/kefu_robot.json Normal file
View 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
}

View File

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

View File

@ -0,0 +1,15 @@
<?php
class OpsController {
public function selfChecking()
{
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'healthy' => 1,
'max_rundelay' => 1,
));
}
}