代码格式重构

This commit is contained in:
aozhiwei 2019-01-25 16:29:37 +08:00
parent 76ca871aa3
commit 78991bc863

View File

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