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

WBOY
Release: 2016-06-13 12:12:06
Original
1058 people have browsed it

第一个公众微信demo老是运行不成功
我找了很多代码了,差不多都是如下代码:

<?php<br />define("TOKEN", "imates");//自己定义的token 就是个通信的私钥<br />$wechatObj = new wechatCallbackapiTest();<br />$wechatObj->valid();<br />$wechatObj->responseMsg();<br />class wechatCallbackapiTest<br />{<br />    public function valid()<br />    {<br />        $echoStr = $_GET["echostr"];<br />        if($this->checkSignature()){<br />            echo $echoStr;<br />            exit;<br />        }<br />    }<br />    public function responseMsg()<br />    {<br />        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];<br />        if (!empty($postStr)){<br />            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);<br />            $fromUsername = $postObj->FromUserName;<br />            $toUsername = $postObj->ToUserName;<br />            $keyword = trim($postObj->Content);<br />            $time = time();<br />            $textTpl = "<xml><br />            <ToUserName><![CDATA[%s]]></ToUserName><br />            <FromUserName><![CDATA[%s]]></FromUserName><br />            <CreateTime>%s</CreateTime><br />            <MsgType><![CDATA[%s]]></MsgType><br />            <Content><![CDATA[%s]]></Content><br />            <FuncFlag>0<FuncFlag><br />            </xml>";<br />            if(!empty( $keyword ))<br />            {<br />                $msgType = "text";<br />                $contentStr = '你好啊,屌丝';<br />                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);<br />                echo $resultStr;<br />            }else{<br />                echo '咋不说哈呢';<br />            }<br />        }else {<br />            echo '咋不说哈呢';<br />            exit;<br />        }<br />    }<br /><br />    private function checkSignature()<br />    {<br />        $signature = $_GET["signature"];<br />        $timestamp = $_GET["timestamp"];<br />        $nonce = $_GET["nonce"];<br />        $token =TOKEN;<br />        $tmpArr = array($token, $timestamp, $nonce);<br />        sort($tmpArr);<br />        $tmpStr = implode( $tmpArr );<br />        $tmpStr = sha1( $tmpStr );<br /><br />        if( $tmpStr == $signature ){<br />            return true;<br />        }else{<br />            return false;<br />        }<br />    }<br />}<br />?>
Copy after login


运行时老是提示【该公众号暂时无法提供服务】,请大神看下哪里出了问题?
------解决思路----------------------
哥们,帮我看看这个问题吧http://bbs.csdn.net/topics/390946850
------解决思路----------------------
去我的博客看看吧
------解决思路----------------------
微信回复都是要已xml格式返回,怎么判断条件中还有直接echo的。

Related labels:
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