PHP WeChat payment notification handling method implementation

Source: Internet
Author: User
Tags openid
PHP payment notification handling method implementation

This article is a supplement to the previous article. it is mainly because the official website does not have a demo about the notification. it is really uncomfortable to touch the stone and cross the river. it is convenient for you to develop and release it for you.

For the implementation of the notification mechanism, only official documents do not have demo code. for those who have not done so, it takes a lot of time for testing. According to the document, the structure of the data sent from each notification is complicated. it is a multi-segment data. in addition to the POST data, it also needs to take other data. The following describes the values of php: // input and $ _ POST, when the Content-Type value is application/x-www-form-urlencoded, php will fill in the corresponding data of the http request body in the array $ _ POST, the data filled in the $ _ POST array is the result of urldecode () parsing. (In fact, in addition to the Content-Type, there is also multipart/form-data indicating that the data is form data. we will introduce it later)

2, php: // input data, as long as the Content-Type is not multipart/form-data (this condition will be described later ). Php: // the input data is consistent with the part of the http entity body. The consistent data Length is specified by Content-Length.

3. only when the Content-Type is application/x-www-form-urlencoded and the submission method is POST, $ _ POST data and php: // the input data is "consistent" (with quotation marks, indicating that the formats are inconsistent and the content is consistent. In other cases, they are inconsistent.

4. php: // input cannot read $ _ GET data. The reason is that the $ _ GET data is written in the PATH field of the http request header as query_path, rather than in the http request body. It 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 Type is xml, and its Content-Type is text/xml.

5. php: // input has encountered multipart/form-data. please refer to RFC1867's description. Multipart/form-data also means to submit form data using the POST method. it is also accompanied by file upload, so it will be different from the data format of application/x-www-form-urlencoded. It is passed to the server in a more reasonable and efficient data format. When the Content-Type is multipart/form-data, php: // input is empty even if there is data in the http request body. PHP does not enter the data in php at this time: // input stream. Therefore, php: // input cannot be used to read data from enctype = multipart/form-data.

6. when the Content-Type is application/x-www-form-urlencoded, the php: // input and $ _ POST data are "consistent". when the Content-Type is another Content-Type, php: // the input and $ _ POST data are inconsistent. Because only when the Content-Type is application/x-www-form-urlencoded or multipart/form-data, PHP will fill in the corresponding part of the body of the http request packet in the $ _ POST global variable. PHP will ignore this in other cases. Php: // input is null except for the data type multipart/form-data. In other cases, it may not be empty, these two methods are used to read the data. Get $ POST first. this is a regular payment notification, as shown in the following figure:

  1. Array (
  2. 'Bank _ type' => '123 ',
  3. 'Discount' => '0 ',
  4. 'Partition _ type' => '1 ',
  5. 'Input _ charset' => 'utf-8 ',
  6. 'Your y _ id' => 'yano6cznonzk0agb8n?ggvuwssjt7ze7gwrars0r _ done ',
  7. 'Out _ trade_no '=> '123 ',
  8. 'Parts' => '12xxxxxxxx ',
  9. 'Product _ period' => '123 ',
  10. 'Sign' => '545fa0e8b594bbxxxx48xx142f084ty ',
  11. 'Sign _ type' => 'md5 ',
  12. 'Time _ end' => '123 ',
  13. 'Total _ 0000' => '123 ',
  14. 'Trade _ mode' => '1 ',
  15. 'Trade _ state' => '0 ',
  16. 'Transaction _ id' => '12xxx449012014xxx33174005xx ',
  17. 'Transport _ upload' => '0 ',
  18. )

Use file_get_contents ('php: // input') to read additional information, such:

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

Finally, we will not detail the corresponding business logic.

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.