From be0443b4a258b7706eed0055a35a3a03346191a4 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 27 Jan 2019 19:48:35 +0800 Subject: [PATCH] remove responseMsg --- webapp/controller/KefuController.class.php | 94 ++++++++++------------ 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/webapp/controller/KefuController.class.php b/webapp/controller/KefuController.class.php index 384bae5..391c2d9 100644 --- a/webapp/controller/KefuController.class.php +++ b/webapp/controller/KefuController.class.php @@ -207,8 +207,43 @@ class KefuController { } else { echo 'signature error'; } + die(); + return; + } + + $msg_str = ''; + $pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID); + $errcode = $pc->decryptJsonMsg($_REQUEST['msg_signature'], + $_REQUEST['timestamp'], + $_REQUEST['nonce'], + file_get_contents('php://input'), + $msg_str); + if ($errcode == 0) { + $msg = json_decode($msg_str, true); + $accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']); + + 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 { - $this->responseMsg(); + #error_log($errcode . "\n"); } } @@ -374,16 +409,11 @@ class KefuController { private function processImage($msg, $accountid) { - $openid = $msg['FromUserName']; - $CreateTime = $msg['CreateTime']; - die(); + die('not implement'); } private function processEvent($msg, $accountid) { - $openid = $msg['FromUserName']; - $CreateTime = $msg['CreateTime']; - if ($msg['Event'] == 'user_enter_tempsession') { $conn = $this->getMysql($accountid); $ret = $conn->execScript('INSERT INTO accounts_kefu(accountid, channel, gameid, openid, awardtime) ' . @@ -394,52 +424,16 @@ class KefuController { ':accountid' => $accountid, ':channel' => WEIXIN_CHANNEL, ':gameid' => phpcommon\extractGameId($accountid), - ':openid' => $openid, + ':openid' => $msg['FromUserName'], ':awardtime' => 0 )); - $this->sendMsg($accountid, array( - "touser" => $openid, - "msgtype" => "text", - "text" => array ("content" => "您好,有什么能帮助你? \n回复指定文字领取奖励。 ") - )); - } - } - - private function responseMsg() - { - $msg_str = ''; - $pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID); - $errcode = $pc->decryptJsonMsg($_REQUEST['msg_signature'], - $_REQUEST['timestamp'], - $_REQUEST['nonce'], - file_get_contents('php://input'), - $msg_str); - if ($errcode == 0) { - $msg = json_decode($msg_str, true); - $accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']); - - switch ($msg['MsgType']) { - case 'text': - { - // 文本消息 - $this->processText($msg, $accountid); - break; + if ($ret) { + $this->sendMsg($accountid, array( + "touser" => $msg['FromUserName'], + "msgtype" => "text", + "text" => array("content" => "您好,有什么能帮助你? \n回复指定文字领取奖励。 ") + )); } - case 'image': - { - // 图文消息 - $this->processImage($msg, $accountid); - break; - } - case 'event': - { - // 进入客服动作 - $this->processEvent($msg, $accountid); - break; - } - } - } else { - #error_log($errcode . "\n"); } }