WeChat public account development-WeChat request server value problems

Source: Internet
Author: User
: This article mainly introduces the public account development-the question of requesting the server value. if you are interested in the PHP Tutorial, please refer to it. I recently developed a public account and learned some new things. here, I want to help others.

Public function responseMsg () {// $ requestStr = $ _ REQUEST ['mpxml']; // open offline test $ requestStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; // release if ($ requestStr = '') $ requestStr = file_get_contents (" php: // input "); // open $ this-> Log-> output ('req', "request message ". $ requestStr); if (! Empty ($ requestStr) {$ postObj = simplexml_load_string ($ requestStr, 'simplexmlelement ',LIBXML_NOCDATA); $ FromUsername = $ postObj-> FromUserName; $ toUsername = $ postObj-> ToUserName; $ msgType = $ postObj-> MsgType; $ keyword = trim ($ postObj-> Content); $ arr = array ('fromusername' => $ fromUsername, 'tousername' => $ toUsername, 'msgtype' => $ msgType, 'keyword' => $ keyword, 'postobj '=> $ postObj ); $ responseStr = $ this-> controllers-> index ($ arr); $ this-> Log-> output ('res', "response message ". $ responseStr); echo $ responseStr;} else {echo ''; exit ;}}

The above is part of the code for processing packets

$requestStr = $_REQUEST['mpxml']; 
Needless to say, accept the value whose name is mpxml.

However, after the server code goes online, this write should fail to accept the request message (in xml format) sent to the server.

$ RequestStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; // release
Or
$ RequestStr = file_get_contents ("php: // input"); // release
The second method is recommended for request packets that are acceptable to all users. it puts less pressure on the memory and does not require any special php.int settings.

The above introduces the public number development-the question of requesting the value of the server, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.