您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

微信公众号开发---微信请求服务端取值问题

2024/5/24 13:13:42发布31次查看
最近开发了微信公众号,学了一些新东西,在这记录一下,也希望能帮助到别人
public function responsemsg() {// $requeststr = $_request['mpxml']; //线下测试放开$requeststr = $globals[http_raw_post_data];//上线放开if($requeststr=='')$requeststr = file_get_contents(php://input);//上线放开$this->log->output('req', 请求报文 . $requeststr);if (!empty($requeststr)) { $postobj = simplexml_load_string($requeststr, 'simplexmlelement', libxml_nocdata);$fromusername = $postobj->fromusername;$tousername = $postobj->tousername;$msgtype = $postobj->msgtype;$keyword = trim($postobj->content);$arr = array('fromusername' => $fromusername, 'tousername' => $tousername, 'msgtype' => $msgtype,'keyword' => $keyword, 'postobj' => $postobj);$responsestr = $this->controllers->index($arr);$this->log->output('res', 应答报文 . $responsestr);echo $responsestr;} else { echo '';exit;} }
以上是处理报文的部分代码
$requeststr = $_request['mpxml'];
这个不用说了,接受name为mpxml的值但是在服务端代码上线之后,这样写应该是接受不到微信发送服务端的请求报文(xml格式)的。
$requeststr = $globals[http_raw_post_data];//上线放开
或者
$requeststr = file_get_contents(php://input);//上线放开
都可以接受到微信的请求报文,推荐第二种方法,它给内存带来的压力较小,并且不需要任何特殊的php.int设置 以上就介绍了微信公众号开发---微信请求服务端取值问题,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product