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