From d018c154433cd40adbc0c2f8870b8f4e6b66f158 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 25 Jan 2019 17:12:16 +0800 Subject: [PATCH] 1 --- webapp/controller/KefuController.class.php | 39 +++++++++------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/webapp/controller/KefuController.class.php b/webapp/controller/KefuController.class.php index e42d80c..8a92b59 100644 --- a/webapp/controller/KefuController.class.php +++ b/webapp/controller/KefuController.class.php @@ -443,7 +443,7 @@ class KefuController { #error_log('dot save to db'); $kefu_info = array( 'accountid' => $accountid, - 'channel' => 6001, + 'channel' => WEIXIN_CHANNEL, 'gameid' => phpcommon\extractGameId($accountid), 'openid' => $openid, 'awardtime' => '0' @@ -463,32 +463,25 @@ class KefuController { private function responseMsg() { - $postStr_key = $GLOBALS["HTTP_RAW_POST_DATA"]; - $gameid = $_REQUEST['gameid']; - $msg_sign = $_REQUEST['msg_signature']; - $timeStamp = $_REQUEST['timestamp']; - $nonce = $_REQUEST['nonce']; - + $msg_str = ''; $pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID); - $errcode = $pc->decryptJsonMsg($msg_sign, $timeStamp, $nonce, $postStr_key, $postStr); + $errcode = $pc->decryptJsonMsg($_REQUEST['msg_signature'], + $_REQUEST['timestamp'], + $_REQUEST['nonce'], + file_get_contents('php://input'), + $msg); if ($errcode == 0) { - #error_log("解密后: " . $postStr . "\n"); - if (!empty( $postStr ) && is_string( $postStr )){ - $postArr = json_decode( $postStr , true ); - $accountid = phpcommon\createAccountId(6001, $gameid, $postArr['FromUserName']); + $msg = json_decode($msg_str, true); + $accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']); - if (!empty( $postArr ['MsgType']) && $postArr['MsgType'] == 'text'){ // 文本消息 - $this->disposeText($postArr, $accountid); - } elseif (!empty( $postArr ['MsgType']) && $postArr['MsgType'] == 'image'){ // 图文消息 - $this->disposeImage($postArr, $accountid); - } elseif (!empty( $postArr ['MsgType']) && $postArr['MsgType'] == 'event' ){ // 进入客服动作 - $this->disposeEvent($postArr, $accountid); - } else { - exit (); - } + 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 { - echo "" ; - exit ; + exit (); } } else { #error_log($errcode . "\n");