我找了很多代码了,差不多都是如下代码:
<?phpdefine("TOKEN", "imates");//自己定义的token 就是个通信的私钥$wechatObj = new wechatCallbackapiTest();$wechatObj->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好的,谢谢