第一个公众微信demo老是运行不成功

WBOY
Release: 2016-06-23 13:42:53
Original
908 people have browsed it

我找了很多代码了,差不多都是如下代码:

<?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 = "<xml>            <ToUserName><![CDATA[%s]]></ToUserName>            <FromUserName><![CDATA[%s]]></FromUserName>            <CreateTime>%s</CreateTime>            <MsgType><![CDATA[%s]]></MsgType>            <Content><![CDATA[%s]]></Content>            <FuncFlag>0<FuncFlag>            </xml>";            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;        }    }}?>
Copy after login


运行时老是提示【该公众号暂时无法提供服务】,请大神看下哪里出了问题?


回复讨论(解决方案)

我的服务器是自己买的阿里云vps主机 php的运行环境

哥们,帮我看看这个问题吧http://bbs.csdn.net/topics/390946850

去我的博客看看吧

微信回复都是要已xml格式返回,怎么判断条件中还有直接echo的。

去我的博客看看吧

v
好的,谢谢
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!