diff --git a/webapp/controller/KefuController.class.php b/webapp/controller/KefuController.class.php index a55eac9..dda56bc 100644 --- a/webapp/controller/KefuController.class.php +++ b/webapp/controller/KefuController.class.php @@ -237,11 +237,15 @@ class KefuController { public function checkServer() // 校验服务器地址URL { $gameid = $_REQUEST['gameid']; - #error_log($gameid); $config_name = "../config/game$gameid/weixin/config.php"; require $config_name; + if (isset($_REQUEST['echostr'])) { - $this->valid(); + if ($this->checkSignature()) { + echo $_REQUEST['echostr']; + } else { + echo 'signature error'; + } } else { $this->responseMsg(); } @@ -273,18 +277,6 @@ class KefuController { } } - private function valid() - { - $echoStr = $_REQUEST['echostr']; - if ($this->checkSignature()) { - echo $echoStr; - exit; - } else { - echo $echoStr . '+++' . WEIXIN_TOKEN; - exit; - } - } - private function checkSignature() { $signature = $_REQUEST["signature"]; @@ -292,15 +284,15 @@ class KefuController { $nonce = $_REQUEST["nonce"]; $token = WEIXIN_TOKEN; - $tmpArr = array ( $token , $timestamp , $nonce ); - sort( $tmpArr , SORT_STRING); - $tmpStr = implode( $tmpArr ); + $tmpArr = array ($token, $timestamp, $nonce); + sort($tmpArr , SORT_STRING); + $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); - if ( $tmpStr == $signature ){ - return true ; + if ($tmpStr == $signature){ + return true; } else { - return false ; + return false; } } @@ -309,20 +301,20 @@ class KefuController { $pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID); $encryptMsg = ''; $text = $postStr; - $errCode = $pc->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str); - if ($errCode == 0) { + $errcode = $pc->encryptJsonMsg($text, $timeStamp, $nonce, $encryptMsg_str); + if ($errcode == 0) { #error_log("加密后: " . $encryptMsg_str . "\n"); $encryptMsg = json_decode($encryptMsg_str, true); - $errCode = $pc->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce, + $errcode = $pc->decryptJsonMsg($encryptMsg['MsgSignature'], $timeStamp, $nonce, $encryptMsg_str, $postStr2); - #error_log('#error_log:' . json_encode($errCode)); - if ($errCode == 0) { + #error_log('#error_log:' . json_encode($errcode)); + if ($errcode == 0) { #error_log("解密后: " . $postStr2 . "\n"); } } else { - #error_log($errCode . "\n"); + #error_log($errcode . "\n"); } } @@ -472,20 +464,16 @@ class KefuController { private function responseMsg() { $postStr_key = $GLOBALS["HTTP_RAW_POST_DATA"]; - - #error_log('!!!begin:' . $postStr_key); - #error_log('request:' . json_encode($_REQUEST)); $pc = new WXBizMsgCrypt(WEIXIN_TOKEN, WEIXIN_MSG_KEY, WEIXIN_APP_ID); - $gameid = $_REQUEST['gameid']; $msg = ''; $msg_sign = $_REQUEST['msg_signature']; $timeStamp = $_REQUEST['timestamp']; $nonce = $_REQUEST['nonce']; - $errCode = $pc->decryptJsonMsg($msg_sign, $timeStamp, $nonce, $postStr_key, $postStr); - #error_log('#error_log:' . json_encode($errCode)); - if ($errCode == 0) { + $errcode = $pc->decryptJsonMsg($msg_sign, $timeStamp, $nonce, $postStr_key, $postStr); + #error_log('#error_log:' . json_encode($errcode)); + if ($errcode == 0) { #error_log("解密后: " . $postStr . "\n"); if (!empty( $postStr ) && is_string( $postStr )){ $postArr = json_decode( $postStr , true ); @@ -505,7 +493,7 @@ class KefuController { exit ; } } else { - #error_log($errCode . "\n"); + #error_log($errcode . "\n"); } }