Php version of WeChat returns the user text input method, phptext

Source: Internet
Author: User

Php returns the user text input method, phptext

This example describes how php returns text input. We will share this with you for your reference. The details are as follows:

Obtain the content entered by the user and return the same content concurrently.

// Get post data // $ PostData = $ HTTP_RAW_POST_DATA; $ PostData = file_get_contents ("php: // input"); // determine whether POST is empty if (! $ PostData) {echo "wrong input! "; Exit (0);} // parse the XML string $ xmlObj = simplexml_load_string ($ PostData, 'simplexmlelement', LIBXML_NOCDATA); if (! $ XmlObj) {echo "wrong input! "; Exit (0);} // get data $ fromUserName = $ xmlObj-> FromUserName; $ toUserName = $ xmlObj-> ToUserName; $ msgType = $ xmlObj-> MsgType; // return if ('text '! = $ MsgType) {// No text. An error message is returned. $ retMsg = "only text messages are supported ";} // else {$ content = $ xmlObj-> Content; $ retMsg = $ content;} // output xml template $ retTmp = "<xml> <ToUserName> <! [CDATA [% s]> </ToUserName> <FromUserName> <! [CDATA [% S]> </FromUserName> <CreateTime> % s </CreateTime> <MsgType> <! [CDATA [text]> </MsgType> <Content> <! [CDATA [% s]> </Content> <FuncFlag> 0 </FuncFlag> </xml> "; // Replace the wildcards in the message $ resultStr = sprintf ($ retTmp, $ fromUserName, $ toUserName, time (), $ retMsg); // output the xml message echo $ resultStr

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.