客服第一版 base
This commit is contained in:
parent
94cb7822fe
commit
616cade040
@ -8,11 +8,4 @@ return array(
|
|||||||
'user' => 'root',
|
'user' => 'root',
|
||||||
'passwd' => 'keji178',
|
'passwd' => 'keji178',
|
||||||
),
|
),
|
||||||
array(
|
|
||||||
'instance_id' => 2,
|
|
||||||
'host' => '127.0.0.1',
|
|
||||||
'port' => 3306,
|
|
||||||
'user' => 'root',
|
|
||||||
'passwd' => 'keji178',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
10
config/kefu.share.config.php
Normal file
10
config/kefu.share.config.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'1011' => array (
|
||||||
|
"title" => '领取奖励',
|
||||||
|
"pagepath" => "http://mmbiz.qpic.cn/mmbiz_jpg/" .
|
||||||
|
"6zVc6fZKcB3zuNoqEULTjPSHPcaR26qciaSykxSCvw4SSq1I4Y6TAp7udB2BjST4YB9NedeRFfywlUt3AunAcJg/0",
|
||||||
|
"thumb_media_id" => 'h2oYnOGns5T7wcJmjFGWTsYnkz3j9Et3258n9xZ8eezOj-8Dzsk23Ao6SzHgV20A'
|
||||||
|
)
|
||||||
|
);
|
@ -204,7 +204,7 @@ class KefuController {
|
|||||||
$awardtime = $this->getAwardtimeFromDB($accountid);
|
$awardtime = $this->getAwardtimeFromDB($accountid);
|
||||||
if (isset($awardtime) and time() - $awardtime > 60 * 60 * 24 * 1) {
|
if (isset($awardtime) and time() - $awardtime > 60 * 60 * 24 * 1) {
|
||||||
return true;
|
return true;
|
||||||
}else{
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -324,24 +324,23 @@ class KefuController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sendMsg($data, $openid, $accountid)
|
private function sendMsg($data, $accountid)
|
||||||
{
|
{
|
||||||
$postarray = json_encode( $data ,JSON_UNESCAPED_UNICODE);
|
$postarray = json_encode( $data ,JSON_UNESCAPED_UNICODE);
|
||||||
error_log($postarray);
|
error_log("sendData:" . $postarray);
|
||||||
|
|
||||||
//POST发送https请求客服接口api
|
//POST发送https请求客服接口api
|
||||||
$access_token = $this->getAccessToken($openid, $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";
|
||||||
error_log('aturl:' . $url);
|
|
||||||
$response = '';
|
$response = '';
|
||||||
if (!phpcommon\HttpClient::post($url, $postarray, $response)) {
|
if (!phpcommon\HttpClient::post($url, $postarray, $response)) {
|
||||||
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$ret_info = json_decode($response, true);
|
$ret_info = json_decode($response, true);
|
||||||
error_log('sendMsg:' . $response);
|
error_log('sendMsgRet:' . $response);
|
||||||
if ($ret_info['errcode'] == 0) {
|
if ($ret_info['errcode'] == 0) {
|
||||||
exit ;
|
|
||||||
} else {
|
} else {
|
||||||
error_log($response);
|
error_log($response);
|
||||||
echo(json_encode(array(
|
echo(json_encode(array(
|
||||||
@ -353,9 +352,16 @@ class KefuController {
|
|||||||
|
|
||||||
public function mytest()
|
public function mytest()
|
||||||
{
|
{
|
||||||
|
|
||||||
error_log('mytest');
|
error_log('mytest');
|
||||||
|
$openid = $_REQUEST['openid'];
|
||||||
|
$shareInfo = require('../config/kefu.share.config.php');
|
||||||
|
$miniprogrampateInfo = $shareInfo['1011'];
|
||||||
|
$data = array (
|
||||||
|
"touser" => $openid,
|
||||||
|
"msgtype" => "miniprogrampage",
|
||||||
|
"miniprogrampage" => $miniprogrampateInfo
|
||||||
|
);
|
||||||
|
$this->sendMsg($data, $_REQUEST['accountid']);
|
||||||
die();
|
die();
|
||||||
$content = '回复【111】领取奖励!';
|
$content = '回复【111】领取奖励!';
|
||||||
$data = array (
|
$data = array (
|
||||||
@ -364,21 +370,57 @@ class KefuController {
|
|||||||
"text"=> array ("content" => $content)
|
"text"=> array ("content" => $content)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->sendMsg($data, $openid, $accountid);
|
|
||||||
|
$this->sendMsg($data, $_REQUEST['accountid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendMsgSomeUser($arrayInfo)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach($arrayInfo as $userInfo) {
|
||||||
|
|
||||||
|
$shareInfo = require('../config/kefu.share.config.php');
|
||||||
|
$miniprogrampateInfo = $shareInfo['1011'];
|
||||||
|
$data = array (
|
||||||
|
"touser" => $userInfo['openid'],
|
||||||
|
"msgtype" => "miniprogrampage",
|
||||||
|
"miniprogrampage" => $miniprogrampateInfo
|
||||||
|
);
|
||||||
|
error_log('sendmsg11111:' . json_encode($data));
|
||||||
|
$this->sendMsg($data, $userInfo['accountid']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendOneDBInfo($minIdx, $maxIdx, $conn)
|
||||||
|
{
|
||||||
|
$selectOneCount = 20;
|
||||||
|
$selectCount = $maxIdx - $minIdx;
|
||||||
|
$remainderTimes = ($selectCount % $selectOneCount) ? 1 : 0;
|
||||||
|
$selectTimes = floor($selectCount / $selectOneCount) + $remainderTimes;
|
||||||
|
|
||||||
|
error_log('selectCount:' . $selectCount);
|
||||||
|
error_log('selectTimes:' . $selectTimes);
|
||||||
|
|
||||||
|
$selectMin = $minIdx;
|
||||||
|
for ($i = 0; $i < $selectTimes; $i++ ) {
|
||||||
|
error_log('selectMin:' . $selectMin);
|
||||||
|
$arrayInfo = $this->getAccountsKefuInfo($selectMin, $selectMin + $selectOneCount, $conn);
|
||||||
|
$this->sendMsgSomeUser($arrayInfo);
|
||||||
|
$selectMin = $selectMin + $selectOneCount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendMsgAllUser()
|
public function sendMsgAllUser()
|
||||||
{
|
{
|
||||||
error_log('sendMsgAllUser:');
|
error_log('sendMsgAllUser:');
|
||||||
|
|
||||||
|
|
||||||
error_log($maxIdx);
|
|
||||||
$mysqls = $this->getAllMysql();
|
$mysqls = $this->getAllMysql();
|
||||||
foreach($mysqls as $mysql_conf) {
|
foreach($mysqls as $mysql_conf) {
|
||||||
$conn = getAppointMysql($mysql_conf);
|
$conn = $this->getAppointMysql($mysql_conf);
|
||||||
$minIdx = 10000;
|
$minIdx = 10000;
|
||||||
$maxIdx = $this->getAwardDBMaxIdx($conn);
|
$maxIdx = $this->getAwardDBMaxIdx($conn);
|
||||||
$arrayinfo = $this->getAccountsKefuInfo($minIdx, $maxIdx, $conn);
|
$this->sendOneDBInfo($minIdx, $maxIdx, $conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,26 +450,26 @@ class KefuController {
|
|||||||
"msgtype" => "text",
|
"msgtype" => "text",
|
||||||
"text" => array ("content" => $content)
|
"text" => array ("content" => $content)
|
||||||
);
|
);
|
||||||
$this->sendMsg($data, $openid, $accountid);
|
$this->sendMsg($data, $accountid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$content = '一天内只能领取一次奖励!';
|
$content = "一天内只能领取一次奖励!\n请明天再来!";
|
||||||
$data = array (
|
$data = array (
|
||||||
"touser" => $openid,
|
"touser" => $openid,
|
||||||
"msgtype" => "text",
|
"msgtype" => "text",
|
||||||
"text" => array ("content" => $content)
|
"text" => array ("content" => $content)
|
||||||
);
|
);
|
||||||
$this->sendMsg($data, $openid, $accountid);
|
$this->sendMsg($data, $accountid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$content = '回复【111】领取奖励!';
|
$content = '回复指定文字领取奖励!';
|
||||||
$data = array (
|
$data = array (
|
||||||
"touser" => $openid,
|
"touser" => $openid,
|
||||||
"msgtype" => "text",
|
"msgtype" => "text",
|
||||||
"text" => array ("content" => $content)
|
"text" => array ("content" => $content)
|
||||||
);
|
);
|
||||||
$this->sendMsg($data, $openid, $accountid);
|
$this->sendMsg($data, $accountid);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -464,13 +506,13 @@ class KefuController {
|
|||||||
);
|
);
|
||||||
$this->insertKefuInfoToDB($accountid, $kefu_info);
|
$this->insertKefuInfoToDB($accountid, $kefu_info);
|
||||||
}
|
}
|
||||||
$content = '您好,有什么能帮助你? 回复【111】领取奖励。 ' ;
|
$content = "您好,有什么能帮助你? \n回复指定文字领取奖励。 ";
|
||||||
$data = array (
|
$data = array (
|
||||||
"touser" => $openid,
|
"touser" => $openid,
|
||||||
"msgtype" => "text",
|
"msgtype" => "text",
|
||||||
"text" => array ("content" => $content)
|
"text" => array ("content" => $content)
|
||||||
);
|
);
|
||||||
$this->sendMsg($data, $openid, $accountid);
|
$this->sendMsg($data, $accountid);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -519,10 +561,9 @@ class KefuController {
|
|||||||
error_log($errCode . "\n");
|
error_log($errCode . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAccessToken($openid, $accountid)
|
public function getAccessToken($accountid)
|
||||||
{
|
{
|
||||||
|
|
||||||
$r = $this->getRedis($accountid);
|
$r = $this->getRedis($accountid);
|
||||||
@ -532,6 +573,9 @@ class KefuController {
|
|||||||
return $access_token;
|
return $access_token;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$gameid = phpcommon\extractGameId($accountid);
|
||||||
|
$config_name = "../config/game$gameid/weixin/config.php";
|
||||||
|
require $config_name;
|
||||||
|
|
||||||
$appid = WEIXIN_APP_ID;
|
$appid = WEIXIN_APP_ID;
|
||||||
$appkey = WEIXIN_APP_SECRET;
|
$appkey = WEIXIN_APP_SECRET;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user