时间:2021-07-01 10:21:17 帮助过:6人阅读
valid();$wechatObj->responseMsg();class wechatCallbackapiTest{ public function valid() { $echoStr = $_GET["echostr"]; if($this->checkSignature()){ echo $echoStr; exit; } } public function responseMsg() { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)){ $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $textTpl = ""; if(!empty( $keyword )) { $msgType = "text"; $contentStr = '你好啊,?丝'; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo '咋不说哈呢'; } }else { echo '咋不说哈呢'; exit; } } private function checkSignature() { $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token =TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; } }}?> %s 0
我的服务器是自己买的阿里云vps主机 php的运行环境
哥们,帮我看看这个问题吧http://bbs.csdn.net/topics/390946850
去我的博客看看吧
微信回复都是要已xml格式返回,怎么判断条件中还有直接echo的。
去我的博客看看吧
v