微信公众号最基础的,被动回复文本问题,我不知道哪里出错了?
发布于 5 年前 作者 xiejing 11401 次浏览 来自 官方Issues

就是不回复消息,服务器配置也正确。

       public function responseMsg()
 {
        //get post data, May be due to the different environments
        //$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
        $postStr = file_get_contents('php://input');
if (empty($postStr)) {
    file_put_contents('wx.log','post数据为空'.FILE_APPEND."\n",FILE_APPEND);
}
else{
	 file_put_contents('wx.log','post123'.FILE_APPEND."\n",FILE_APPEND);
}
file_put_contents('wx.log',$postStr,FILE_APPEND);
        //extract post data
        if (!empty($postStr)) {

            $postObj = simplexml_load_string($postStr,'SimpleXMLElement',LIBXML_NOCDATA);

            $fromUsername = $postObj->FromUserName;
            $toUsername = $postObj->ToUserName;
            $keyword = trim($postObj->Content);
            $time = time();
            $textTpl = "<xml>
                            <ToUserName><![CDATA[%s]]></ToUserName>
                            <FromUserName><![CDATA[%s]]></FromUserName>
                            <CreateTime>%d</CreateTime>
                            <MsgType><![CDATA[%s]]></MsgType>
                            <Content><![CDATA[%s]]></Content>
                            <FuncFlag>0</FuncFlag>
                            </xml>";
            if (!empty($keyword)) {
                $msgType = "text";
                $contentStr = "Welcome to wechat world!";
                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                echo $resultStr;
            } else {
                echo "Input something...";
            }

        } else {
            echo "";
            exit;
        }
    }
1 回复

给你参考一下java的

回到顶部