Home > Backend Development > PHP Tutorial > WeChat public account development xml: Xml fields error, please check your response xml!

WeChat public account development xml: Xml fields error, please check your response xml!

不言
Release: 2023-03-01 07:52:01
Original
2862 people have browsed it

php code is as follows tp framework

responseMsg();
      }
    }
    public function responseMsg()
    {
    //get post data, May be due to the different environments
    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
    // $tmpstr = $postStr;
    libxml_disable_entity_loader(true);
    $postObj = simplexml_load_string($postStr,'SimpleXMLElement', LIBXML_NOCDATA);
    //extract post data
    if (strtolower( $postObj->MsgType ) == 'event'){
                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
                   the best way is to check the validity of xml by yourself */
                   if (strtolower( $postObj->Event == 'subscribe')) {
                     $toUsername = $postObj->FromUserName;
                     $fromUsername = $postObj->ToUserName;
                     $time = time();
                     $MsgType = 'text';
                     $content = "欢迎访问我的公众号";
                     $textTpl = "%s";
                     $info = sprintf($textTpl,$toUsername,$fromUsername,$time,$MsgType,$content);
                     echo $info;
                   }
        }
    }
}
Copy after login
Copy after login

The test results are as follows:

http://120.27.115.59/wechat.php/Home/Index/wechat
成功或失败:
Decrypt Fail!  
错误原因:
Xml fields error, please check your response xml! 
状态码:
200    OK 
Headers:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Date: Tue, 23 Aug 2016 10:23:34 GMT
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Set-Cookie: PHPSESSID=4tlrj4jd7cgoo3ueaigc6753q7; path=/
Pragma: no-cache
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Content-Type: text/html
Content-Length: 239
 
解密前xml:1471947814解密后xml:
Copy after login
Copy after login

Reply content:

php code is as follows tp framework

responseMsg();
      }
    }
    public function responseMsg()
    {
    //get post data, May be due to the different environments
    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
    // $tmpstr = $postStr;
    libxml_disable_entity_loader(true);
    $postObj = simplexml_load_string($postStr,'SimpleXMLElement', LIBXML_NOCDATA);
    //extract post data
    if (strtolower( $postObj->MsgType ) == 'event'){
                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
                   the best way is to check the validity of xml by yourself */
                   if (strtolower( $postObj->Event == 'subscribe')) {
                     $toUsername = $postObj->FromUserName;
                     $fromUsername = $postObj->ToUserName;
                     $time = time();
                     $MsgType = 'text';
                     $content = "欢迎访问我的公众号";
                     $textTpl = "%s";
                     $info = sprintf($textTpl,$toUsername,$fromUsername,$time,$MsgType,$content);
                     echo $info;
                   }
        }
    }
}
Copy after login
Copy after login

test results are as follows:

http://120.27.115.59/wechat.php/Home/Index/wechat
成功或失败:
Decrypt Fail!  
错误原因:
Xml fields error, please check your response xml! 
状态码:
200    OK 
Headers:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Date: Tue, 23 Aug 2016 10:23:34 GMT
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Set-Cookie: PHPSESSID=4tlrj4jd7cgoo3ueaigc6753q7; path=/
Pragma: no-cache
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Content-Type: text/html
Content-Length: 239
 
解密前xml:1471947814解密后xml:
Copy after login
Copy after login

Solved. . It seems to be a problem with TP

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template