An analysis of the processing mode of _php payment notice in PHP

Source: Internet
Author: User
Tags cdata openid

Notification mechanism to achieve, the official only document without the demo code, for those who have not done, it will take a lot of time to do the test.

From the point of view of the document, the micro-letter each notice over the data, the structure is more complex, is a lot of data, in addition to the post data to be taken out, but also to take other data.

Here first involves a question about php://input and $_post, a few simple columns are as follows:

Copy Code code as follows:

1,content-type value is application/x-www-form-urlencoded, PHP will fill the HTTP request body corresponding data into the array $_post, fill in the $_ The data in the post array is the result of UrlDecode () parsing. (In fact, in addition to the Content-type, there are multipart/form-data to represent the data is form data, later we introduce)
2,php://input data, as long as the Content-type is not multipart/form-data (this condition is described later). Then the php://input data is consistent with the HTTP entity body part data. The length of the consistent data in this section is specified by Content-length.
3, the $_post data is "consistent" with the Php://input data only when Content-type is application/x-www-form-urlencoded and the Submit method is a post method (quotes, indicating that they are inconsistent in format, Content). In other cases, they are inconsistent.
4,php://input cannot read $_get data. This is because the $_get data is written in the path field of the HTTP request header (header) as Query_path, rather than in the body portion of the HTTP request.

This also helps us understand why the XML_RPC server reads data through file_get_contents (' Php://input ', ' R '). Instead of reading from $_post, it is because the XML_RPC data specification is XML and its content-type is text/xml.
5. Php://input met Multipart/form-data, please refer to RFC1867 's description of it. Multipart/form-data also indicates that the form data is submitted by post and is accompanied by a file upload, so it will be different from the application/x-www-form-urlencoded data format. It will be delivered to the server in a more reasonable, more efficient data format. When Content-type is multipart/form-data, even if there is data in the body of the HTTP request, Php://input is empty, PHP will not fill the data into the Php://input stream at this time. Therefore, you can determine that: Php://input cannot be used to read enctype=multipart/form-data data.

6. When Content-type is application/x-www-form-urlencoded, php://input and $_post data are "consistent" for other content-type times, PHP://input and $ _post data data is inconsistent. Because only when Content-type is application/x-www-form-urlencoded or Multipart/form-data, PHP fills in the corresponding part of the body data in the HTTP request packet $_ In the post global variable, PHP is ignored in other cases. Php://input except for the fact that the data type is multipart/form-data, other things may not be empty

The above is the meaning of so many words, that is, you have to use these two ways to read the data transmitted by the micro-letters.

First Take $post this is the regular payment notification information, in the form of:

Copy Code code as follows:

Array (
' Bank_type ' => ' 3006 ',
' Discount ' => ' 0 ',
' Fee_type ' => ' 1 ',
' Input_charset ' => ' UTF-8 ',
' notify_id ' => ' yano6cznonzk0agb8njwggvuwssjt7ze7gwrars0r_5w9oxggnkrgxreek0r45yk3i9a2_ Gzo9iqgqmybap6bxc2t3p0o-2c ',
' Out_trade_no ' => ' 1214284731 ',
' Partner ' => ' 12xxxxxxxx ',
' Product_fee ' => ' 3400 ',
' Sign ' => ' 545fa0e8b594bbxxxx48xx142f084ty ',
' Sign_type ' => ' MD5 ',
' Time_end ' => ' 20130223110224 ',
' Total_fee ' => ' 3400 ',
' Trade_mode ' => ' 1 ',
' trade_state ' => ' 0 ',
' transaction_id ' => ' 12xxx449012014xxx33174005xxx ',
' Transport_fee ' => ' 0 ',
)

Then use file_get_contents (' Php://input ') to read additional information, in the form of:

Copy Code code as follows:

<xml><openid><! [cdata[o0pd3jqhan7b0tvpdfjpzjeksclw]]></openid>
<appid><! [cdata[wxxxx06xx2cxxx88xx]]></appid>
<IsSubscribe>1</IsSubscribe>
<TimeStamp>1400814743</TimeStamp>
<noncestr><! [cdata[lqxwmsiy9exrdpms]]></noncestr>
<appsignature><! [cdata[c2dxxxe186116b32b06axxxc1a688b671eexxx5e]]></appsignature>
<signmethod><! [cdata[sha1]]></signmethod>
</xml>

Finally, do the corresponding business logic processing, it is not detailed.

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.