remove insertKefuInfoToDB checkAccountKefuExist
This commit is contained in:
parent
d018c15443
commit
70217c5b3d
@ -45,43 +45,6 @@ class KefuController {
|
|||||||
return require('../config/kefu.mysql.cluster.php');
|
return require('../config/kefu.mysql.cluster.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
#kefudb_info = array(accountid, channel, gameid, openid, awardtime)
|
|
||||||
private function insertKefuInfoToDB($accountid, $kefu_info)
|
|
||||||
{
|
|
||||||
$conn = $this->getMysql($accountid);
|
|
||||||
$tbl_name = 'accounts_kefu';
|
|
||||||
$ret = $conn->execScript("INSERT INTO $tbl_name(" .
|
|
||||||
'accountid, channel, gameid, openid, awardtime) ' .
|
|
||||||
'VALUES(:accountid, :channel, :gameid, :openid, :awardtime);',
|
|
||||||
array(
|
|
||||||
':accountid' => $kefu_info['accountid'],
|
|
||||||
':channel' => $kefu_info['channel'],
|
|
||||||
':gameid' => $kefu_info['gameid'],
|
|
||||||
':openid' => $kefu_info['openid'],
|
|
||||||
':awardtime' => $kefu_info['awardtime']
|
|
||||||
));
|
|
||||||
return $ret;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkAccountKefuExist($accountid)
|
|
||||||
{
|
|
||||||
$conn = $this->getMysql($accountid);
|
|
||||||
$select_tbl_name = 'accounts_kefu';
|
|
||||||
|
|
||||||
$row = $conn->execQueryOne('SELECT accountid ' .
|
|
||||||
"FROM $select_tbl_name WHERE accountid = :accountid ;",
|
|
||||||
array(
|
|
||||||
':accountid' => $accountid,
|
|
||||||
));
|
|
||||||
#error_log('check_Exist:' . json_encode($row));
|
|
||||||
if ($row) {
|
|
||||||
return $row;
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveAwardTimeToDB($accountid, $time)
|
private function saveAwardTimeToDB($accountid, $time)
|
||||||
{
|
{
|
||||||
$conn = $this->getMysql($accountid);
|
$conn = $this->getMysql($accountid);
|
||||||
@ -93,9 +56,7 @@ class KefuController {
|
|||||||
':accountid' => $accountid,
|
':accountid' => $accountid,
|
||||||
':awardtime' => $time
|
':awardtime' => $time
|
||||||
));
|
));
|
||||||
#error_log('saveAwartTime:' . json_encode($row));
|
|
||||||
return $row;
|
return $row;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAwardtimeFromDB($accountid)
|
private function getAwardtimeFromDB($accountid)
|
||||||
@ -168,8 +129,8 @@ class KefuController {
|
|||||||
if ($ret['errcode'] == 0) {
|
if ($ret['errcode'] == 0) {
|
||||||
return $ret['items'];
|
return $ret['items'];
|
||||||
} else {
|
} else {
|
||||||
return;
|
|
||||||
die();
|
die();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +282,6 @@ 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);
|
|
||||||
//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";
|
||||||
@ -374,15 +334,13 @@ class KefuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function disposeText($postArr, $accountid)
|
private function processText($msg, $accountid)
|
||||||
{
|
{
|
||||||
#error_log('text');
|
$openid = $msg['FromUserName'];
|
||||||
$openid = $postArr['FromUserName'];
|
$CreateTime = $msg['CreateTime'];
|
||||||
$CreateTime = $postArr['CreateTime'];
|
$text = $msg['Content'];
|
||||||
$text = $postArr['Content'];
|
|
||||||
$gameid = phpcommon\extractGameId($accountid);
|
$gameid = phpcommon\extractGameId($accountid);
|
||||||
$awardConfig = $this->getAwardConfig($gameid, $text);
|
$awardConfig = $this->getAwardConfig($gameid, $text);
|
||||||
#error_log('awardConfig:' . json_encode($awardConfig));
|
|
||||||
if (isset($awardConfig)) {
|
if (isset($awardConfig)) {
|
||||||
$checkTimeRet = $this->checkAward($accountid);
|
$checkTimeRet = $this->checkAward($accountid);
|
||||||
if ($checkTimeRet) {
|
if ($checkTimeRet) {
|
||||||
@ -421,35 +379,31 @@ class KefuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function disposeImage($postArr, $accountid)
|
private function processImage($msg, $accountid)
|
||||||
{
|
{
|
||||||
$openid = $postArr['FromUserName'];
|
$openid = $msg['FromUserName'];
|
||||||
$CreateTime = $postArr['CreateTime'];
|
$CreateTime = $msg['CreateTime'];
|
||||||
|
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function disposeEvent($postArr, $accountid)
|
private function processEvent($msg, $accountid)
|
||||||
{
|
{
|
||||||
#error_log('disposeEvent');
|
$openid = $msg['FromUserName'];
|
||||||
$openid = $postArr['FromUserName'];
|
$CreateTime = $msg['CreateTime'];
|
||||||
$CreateTime = $postArr['CreateTime'];
|
|
||||||
|
|
||||||
if ($postArr['Event'] == 'user_enter_tempsession') {
|
if ($msg['Event'] == 'user_enter_tempsession') {
|
||||||
$check_ret = $this->checkAccountKefuExist($accountid);
|
$conn = $this->getMysql($accountid);
|
||||||
#error_log('check_ret:' . json_encode($check_ret));
|
$ret = $conn->execScript('INSERT INTO accounts_kefu(accountid, channel, gameid, openid, awardtime) ' .
|
||||||
if (empty($check_ret)) {
|
'SELECT :accountid, :channel, :gameid, :openid, :awardtime ' .
|
||||||
|
'FROM accounts_kefu ' .
|
||||||
#error_log('dot save to db');
|
'WHERE NOT EXISTS(SELECT accountid FROM accounts_kefu WHERE accoutid=:accountid);',
|
||||||
$kefu_info = array(
|
array(
|
||||||
'accountid' => $accountid,
|
':accountid' => $accountid,
|
||||||
'channel' => WEIXIN_CHANNEL,
|
':channel' => WEIXIN_CHANNEL,
|
||||||
'gameid' => phpcommon\extractGameId($accountid),
|
':gameid' => phpcommon\extractGameId($accountid),
|
||||||
'openid' => $openid,
|
':openid' => $openid,
|
||||||
'awardtime' => '0'
|
':awardtime' => 0
|
||||||
);
|
));
|
||||||
$this->insertKefuInfoToDB($accountid, $kefu_info);
|
|
||||||
}
|
|
||||||
$content = "您好,有什么能帮助你? \n回复指定文字领取奖励。 ";
|
$content = "您好,有什么能帮助你? \n回复指定文字领取奖励。 ";
|
||||||
$data = array (
|
$data = array (
|
||||||
"touser" => $openid,
|
"touser" => $openid,
|
||||||
@ -457,7 +411,6 @@ class KefuController {
|
|||||||
"text" => array ("content" => $content)
|
"text" => array ("content" => $content)
|
||||||
);
|
);
|
||||||
$this->sendMsg($data, $accountid);
|
$this->sendMsg($data, $accountid);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,19 +422,30 @@ class KefuController {
|
|||||||
$_REQUEST['timestamp'],
|
$_REQUEST['timestamp'],
|
||||||
$_REQUEST['nonce'],
|
$_REQUEST['nonce'],
|
||||||
file_get_contents('php://input'),
|
file_get_contents('php://input'),
|
||||||
$msg);
|
$msg_str);
|
||||||
if ($errcode == 0) {
|
if ($errcode == 0) {
|
||||||
$msg = json_decode($msg_str, true);
|
$msg = json_decode($msg_str, true);
|
||||||
$accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']);
|
$accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']);
|
||||||
|
|
||||||
if (!empty( $msg ['MsgType']) && $msg['MsgType'] == 'text'){ // 文本消息
|
switch ($msg['MsgType']) {
|
||||||
$this->disposeText($msg, $accountid);
|
case 'text':
|
||||||
} elseif (!empty( $msg ['MsgType']) && $msg['MsgType'] == 'image'){ // 图文消息
|
{
|
||||||
$this->disposeImage($msg, $accountid);
|
// 文本消息
|
||||||
} elseif (!empty( $msg ['MsgType']) && $msg['MsgType'] == 'event' ){ // 进入客服动作
|
$this->processText($msg, $accountid);
|
||||||
$this->disposeEvent($msg, $accountid);
|
break;
|
||||||
} else {
|
}
|
||||||
exit ();
|
case 'image':
|
||||||
|
{
|
||||||
|
// 图文消息
|
||||||
|
$this->processImage($msg, $accountid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'event':
|
||||||
|
{
|
||||||
|
// 进入客服动作
|
||||||
|
$this->processEvent($msg, $accountid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#error_log($errcode . "\n");
|
#error_log($errcode . "\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user