微信公众平台接口
<?php <br />/**<br> * wechat php test<br> */<br><br>//define your token<br>define("TOKEN", "qianshou");<br>$wechatObj = new wechatCallbackapiTest();<br>$wechatObj->valid();<br>$wechatObj->responseMsg();<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><br> }else {<br> echo "qianshouerror";<div class="clear"> </div>