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:
- Array (
- 'Bank _ type' => '123 ',
- 'Discount' => '0 ',
- 'Partition _ type' => '1 ',
- 'Input _ charset' => 'utf-8 ',
- 'Your y _ id' => 'yano6cznonzk0agb8n?ggvuwssjt7ze7gwrars0r _ done ',
- 'Out _ trade_no '=> '123 ',
- 'Parts' => '12xxxxxxxx ',
- 'Product _ period' => '123 ',
- 'Sign' => '545fa0e8b594bbxxxx48xx142f084ty ',
- 'Sign _ type' => 'md5 ',
- 'Time _ end' => '123 ',
- 'Total _ 0000' => '123 ',
- 'Trade _ mode' => '1 ',
- 'Trade _ state' => '0 ',
- 'Transaction _ id' => '12xxx449012014xxx33174005xx ',
- 'Transport _ upload' => '0 ',
- )
Use file_get_contents ('php: // input') to read additional information, such:
- o0pd3jqHaN7b0tVPDFJPzJEkSCLw
- wxXXX06XX2cXXX88XX
- 1
- 1400814743
- lqxwMsiY9EXRDpms
- c2dxxxe186116b32b06axxxc1a688b671eexxx5e
- sha1
-
Finally, we will not detail the corresponding business logic. |