php 微信 返回,php版微信返回用户text输入的方法
獲得用戶輸入的內(nèi)容,并發(fā)回相同內(nèi)容//獲取post數(shù)據(jù)
//?$PostData?=?$HTTP_RAW_POST_DATA;
$PostData?=?file_get_contents("php://input");
//判斷POST是否為空
if(!$PostData){
echo?"wrong?input!";
exit(0);
}
//解析XML字符串
$xmlObj?=?simplexml_load_string($PostData,?'SimpleXMLElement',?LIBXML_NOCDATA);
if(!$xmlObj){
echo?"wrong?input!";
exit(0);
}
//獲取數(shù)據(jù)
$fromUserName?=?$xmlObj->FromUserName;
$toUserName?=?$xmlObj->ToUserName;
$msgType?=?$xmlObj->MsgType;
//返回用戶輸入
if('text'?!=?$msgType){
//不是文本,輸出錯誤提示消息
$retMsg?=?"只支持文本消息";
}
//用戶輸入文本
else{
$content?=?$xmlObj->Content;
$retMsg?=?$content;
}
//輸出xml模板
$retTmp?=?"
%s
0
";
//對消息中的通配符進行替換
$resultStr?=?sprintf($retTmp,?$fromUserName,?$toUserName,?time(),?$retMsg);
//輸出xml的消息
echo?$resultStr
總結(jié)
以上是生活随笔為你收集整理的php 微信 返回,php版微信返回用户text输入的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php证书格式,常用的证书格式转换 -
- 下一篇: 美国陆军AML无人火箭炮性能分析