How to implement the processing method of PHP micro-credit Payment notification

Source: Internet
Author: User
Tags cdata openid

This article is a supplement to the previous article, mainly the official no notification of the demo, touch the Stone River is really uncomfortable, convenient for everyone to develop, let us see

Notification mechanism implementation, the official only documents do not have the demo code, for the people who did not have to spend a lot of time to do the test. From the point of view of the document, each notification comes over the data, the structure is more complex, is a multi-segment data, in addition to remove the post data, but also to take other data. Here first relates to a question about php://input and $_post value, the simple column is as follows: 1,content-type value is application/x-www-form-urlencoded, PHP will fill in the HTTP request body corresponding data into the array $_post, the data filled into the $_post array is the result of UrlDecode () parsing. (In fact, in addition to the Content-type, there are multipart/form-data that the data is the form data, we will introduce later)

2,php://input data, as long as Content-type is not multipart/form-data (the condition limit is described later). Then the php://input data is consistent with the HTTP entity body part data. The length of the data consistent with this section is specified by Content-length.

3, the $_post data is "consistent" with the Php://input data only if Content-type is application/x-www-form-urlencoded and the method of submission is the Post method (the quotation marks indicate that they are inconsistent in format. Consistent with the content). In other cases, they are inconsistent.

The 4,php://input cannot read $_get data. This is because the $_get data is written as Query_path in the Path field of the HTTP request header (header) instead of the body part of the HTTP request. Help 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 encountered the Multipart/form-data, please refer to RFC1867 description of it. Multipart/form-data also indicates that the form data is submitted by post, and it is accompanied by a file upload, so it is not the same as 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 HTTP request body, Php://input is empty, and PHP will not fill the data in the Php://input stream at this time. Therefore, it can be determined that php://input cannot be used to read enctype=multipart/form-data data.

6. When Content-type is application/x-www-form-urlencoded, the php://input and $_post data are "consistent" for other content-type when PHP://input and $ _post data data is inconsistent. Because only when Content-type is application/x-www-form-urlencoded or multipart/form-data, does PHP fill in the corresponding part of the data in the HTTP request packet $_ Post global variables, PHP is ignored in other cases. and Php://input In addition to the data type of multipart/form-data outside, other circumstances may not be empty above the meaning of such a lot of text, that is, you have to use both methods to read the data passed over. First fetch $post This is the regular payment notification information, such as:

    1. Array (
    2. ' Bank_type ' = ' 3006 ',
    3. ' Discount ' = ' 0 ',
    4. ' Fee_type ' = ' 1 ',
    5. ' Input_charset ' = ' UTF-8 ',
    6. ' notify_id ' = ' yano6cznonzk0agb8njwggvuwssjt7ze7gwrars0r_5w9oxggnkrgxreek0r45yk3i9a2_ Gzo9iqgqmybap6bxc2t3p0o-2c ',
    7. ' Out_trade_no ' = ' 1214284731 ',
    8. ' Partner ' = ' 12xxxxxxxx ',
    9. ' Product_fee ' = ' 3400 ',
    10. ' Sign ' = ' 545fa0e8b594bbxxxx48xx142f084ty ',
    11. ' Sign_type ' = ' MD5 ',
    12. ' Time_end ' = ' 20130223110224 ',
    13. ' Total_fee ' = ' 3400 ',
    14. ' Trade_mode ' = ' 1 ',
    15. ' trade_state ' = ' 0 ',
    16. ' transaction_id ' = ' 12xxx449012014xxx33174005xxx ',
    17. ' Transport_fee ' = ' 0 ',
    18. )
Copy Code

Then use file_get_contents (' Php://input ') to read additional information, such as:

    1. o0pd3jqHaN7b0tVPDFJPzJEkSCLw
    2. wxXXX06XX2cXXX88XX
    3. 1
    4. 1400814743
    5. lqxwMsiY9EXRDpms
    6. c2dxxxe186116b32b06axxxc1a688b671eexxx5e
    7. sha1
Copy Code

Finally, do the corresponding business logic processing, no longer detailed, we study.

  • Related Article

    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.