Rumah >pembangunan bahagian belakang >tutorial php >用过微信大众账号的要小心了
用过微信公众账号的要小心了
新用户订阅,将由之前推送一条“Hello2BizUser”文本,变化为推送一条“subscribe”的事件。
这个在php里怎么写啊,我现在有一个公众账号,可是别人关注我后,不能马上发一条消息。
<br><?php <br />/**<br> * wechat php test<br> */<br><br>//define your token<br>define("TOKEN", "weixin");<br>$wechatObj = new wechatCallbackapiTest();<br>$wechatObj->valid();<br><br>class wechatCallbackapiTest<br>{<br> public function valid()<br> {<br> $echoStr = $_GET["echostr"];<br><br> //valid signature , option<br> if($this->checkSignature()){<br> echo $echoStr;<br> exit;<br> }<br> }<br><br> public function responseMsg()<br> {<br> //get post data, May be due to the different environments<br> $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];<br><br> //extract post data<br> if (!empty($postStr)){<br> <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></tousername><br> <fromusername></fromusername><br> <createtime>%s</createtime><br> <msgtype></msgtype><br> <content></content><br> <funcflag>0</funcflag><br> </xml>"; <br> if(!empty( $keyword ))<br> {<br> $msgType = "text";<br> $contentStr = "Welcome to wechat world!";<br> $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);<br> echo $resultStr;<br> }else{<br> echo "Input something...";<br> }<br><div class="clear"> </div>