时间:2021-07-01 10:21:17 帮助过:26人阅读
在echo json_encode之前,加上:header('Content-type:application/json;charset=utf-8');
会不会是这个有错误?%s 0
public function responseMsg(){
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //接收微信发来的XML数据
//extract post data
if(!empty($postStr)){
//解析post来的XML为一个对象$postObj
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName; //请求消息的用户
$toUsername = $postObj->ToUserName; //"我"的公众号id
$keyword = trim($postObj->Content); //用户发送的消息内容
$time = time(); //时间戳
$msgtype = 'text'; //消息类型:文本
$textTpl = "
%s
";
$contentStr = "输入-h查看帮助吧(=?ω?=)";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgtype, $contentStr);
echo $resultStr;