如题,
我在尝试用php做微信公众号的开发,
用的是微信示例代码,
token验证成功,
可以收到“welcome to wechat world!”这个回复,
但是收不到xml表单是为什么?
还是说xml表单本来就是看不到的?
那我要如何获得表单上的内容?
<?php/** * wechat php test *///define your tokendefine("token", "weixin");$wechatobj = new wechatcallbackapitest();//$wechatobj->valid(); $wechatobj->responsemsg();class wechatcallbackapitest{ public function valid() { $echostr = $_get["echostr"]; //valid signature , option if($this->checksignature()){ echo $echostr; exit; } } public function responsemsg() { //get post data, may be due to the different environments $poststr = $globals["http_raw_post_data"]; //extract post data if (!empty($poststr)){ /* libxml_disable_entity_loader is to prevent xml external entity injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $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 = "welcome to wechat world!"; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; }else{ echo "input something..."; } }else { echo ""; exit; } } private function checksignature() { // you must define token by yourself if (!defined("token")) { throw new exception('token is not defined!'); } $signature = $_get["signature"]; $timestamp = $_get["timestamp"]; $nonce = $_get["nonce"]; $token = token; $tmparr = array($token, $timestamp, $nonce); // use sort_string rule sort($tmparr, sort_string); $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }else{ return false; } }}?>
微信这块你实现他的接口的时候返回值会有xml文档信息,直接回复没有xml文档
你的回复是通过微信服务器转发给你的,微信服务器会解析你发送的xml找到对应的接收人。内容就是
微信这块你实现他的接口的时候返回值会有xml文档信息,直接回复没有xml文档
你的回复是通过微信服务器转发给你的,微信服务器会解析你发送的xml找到对应的接收人。内容就是
微信这块你实现他的接口的时候返回值会有xml文档信息,直接回复没有xml文档
微信这块你实现他的接口的时候返回值会有xml文档信息,直接回复没有xml文档
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号