????public?function?responseMsgs()
????{
????????//1.獲取到微信推送過來post的數(shù)據(jù)(xml格式)
//????????$postArr?=?file_get_contents('php://input');
????????$postArr?=?isset($GLOBALS["HTTP_RAW_POST_DATA"])???$GLOBALS["HTTP_RAW_POST_DATA"]?:?file_get_contents("php://input");
????????//2.處理消息類型,并設(shè)置回復(fù)類型和內(nèi)容
????????libxml_disable_entity_loader(true);
????????$postObj?=?simplexml_load_string($postArr,?'SimpleXMLElement',?LIBXML_NOCDATA);
????????//判斷該數(shù)據(jù)包是否是訂閱的事件推送
????????if?(strtolower($postObj->MsgType)?==?'event')?{
????????????//如果是關(guān)注subscribe事件
????????????if?(strtolower($postObj->Event?==?'subscribe'))?{
????????????????//和收到的from、to是相反的
????????????????$toUser???=?$postObj->FromUserName;
????????????????$fromUser?=?$postObj->ToUserName;
????????????????$time?????=?time();
????????????????$content??=?"歡迎關(guān)注,常聯(lián)系。";
????????????????$template?=?"<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[%s]]></Content></xml>";
????????????????$info?????=?sprintf($template,?$toUser,?$fromUser,?$time,?$content);
????????????????//回復(fù)用戶消息
????????????????$info?????=?preg_replace('/[?]/',?'',?$info);//去掉空格
????????????????echo?$info;
????????????}
????????}
????}
2018-08-30
去了空格也不行
2018-11-02
可以了 謝謝? 真的是空格, , 好坑.. 用你的responseMsgs()? 方法就可以了
2018-09-01
我是看別人博客才知道的,
地址:https://blog.csdn.net/king_jie0210/article/details/72598511
2018-07-27
怎么換的 我也是一臉蒙蔽
2018-07-26
從代碼上我真的看不出哪里有bug,但是我換一下代碼結(jié)構(gòu)就可以了,真坑。
2018-07-24
我的是tp5框架的