public function responseMsg(){<br /> <br /> //get post data, May be due to the different environments<br /> $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //接收微信发来的XML数据<br /><br /> //extract post data<br /> if(!empty($postStr)){<br /> <br /> //解析post来的XML为一个对象$postObj<br /> $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);<br /> <br /> $fromUsername = $postObj->FromUserName; //请求消息的用户<br /> $toUsername = $postObj->ToUserName; //"我"的公众号id<br /> $keyword = trim($postObj->Content); //用户发送的消息内容<br /> $time = time(); //时间戳<br /> $msgtype = 'text'; //消息类型:文本<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 /> </xml>";<br /> $contentStr = "输入-h查看帮助吧(=?ω?=)";<br /> $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgtype, $contentStr);<br /> echo $resultStr;<br />
Statement:
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