新聞中心
本文操作環(huán)境:Windows7系統(tǒng),php7.1版,Dell G3電腦。

成都創(chuàng)新互聯(lián)公司主營通化網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都App定制開發(fā),通化h5微信小程序定制開發(fā)搭建,通化網(wǎng)站營銷推廣歡迎通化等地區(qū)企業(yè)咨詢
php 微信收不到post 數(shù)據(jù)怎么辦?
微信官方PHP接口無法獲得postStr數(shù)據(jù)
在微信官方提供的PHP接口文檔中,處理主要業(yè)務(wù)有這么一段代碼
public function getIndex(){
if (ob_get_contents()) ob_end_clean();
$postStr = isset($GLOBALS["http_RAW_POST_DATA"])?$GLOBALS["HTTP_RAW_POST_DATA"]:'';//獲取post過來的數(shù)據(jù)
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->postObj = $postObj;
$this->fromUserName = $postObj->FromUserName;//發(fā)送方
$this->toUserName = $postObj->ToUserName;//接收方(即本公眾賬號)
$this->msgType = trim($postObj->MsgType);//消息類型
$this->content = trim($postObj->Content);
$this->event = trim($postObj->Event);
$this->eventKey = trim($postObj->EventKey);
$this->dealMsg();
}else{
$this->wx->makeInfo(Input::all());
$this->wx->valid();//非消息推送時,默認(rèn)為校驗(yàn)
}
flush();
}
這個方法中通過GLOBALS這個全局變量來獲取原始的Post數(shù)據(jù),但是這個方法也同時存在問題。
要通過Globals來獲取數(shù)據(jù),php.ini中的register_globals必須設(shè)置為ON,在低版本的php中register數(shù)據(jù)默認(rèn)為開啟,但是高版本中,默認(rèn)為關(guān)閉狀態(tài),這是因?yàn)?,設(shè)置為ON后,表單提交過來的變量,會自動變成變量,也就是說在地址欄輸入的變量,都變成全局變量,這個是非常不安全的。
除了$GLOBALS["HTTP_RAW_POST_DATA"]獲取post來的數(shù)據(jù),也可以通過file_get_contents("php://input")方法來獲取post來的數(shù)據(jù).
本文題目:php微信收不到post數(shù)據(jù)怎么辦
文章路徑:http://www.dlmjj.cn/article/dhojgje.html


咨詢
建站咨詢
