Heim  >  Artikel  >  Backend-Entwicklung  >  第一个公众微信demo老是运行不成功

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

WBOY
WBOYOriginal
2016-06-23 13:42:53910Durchsuche

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

<?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;        }    }}?>


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


回复讨论(解决方案)

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

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

去我的博客看看吧

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

去我的博客看看吧

v
好的,谢谢
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn