A brief explanation of the payment notification processing method. 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. From the document, we can see that the implementation of the number notification mechanism in each notification only has no demo code in the official document. 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:
1. when the value of Content-Type is application/x-www-form-urlencoded, php will fill in the corresponding data of the http request body to 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.
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 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 not empty except for multipart/form-data.
These two methods are used to read the transmitted data.
Get $ POST first. this is a regular payment notification, as shown in the following figure:
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',)
Use file_get_contents ('php: // input') to read additional information, such:
o0pd3jqHaN7b0tVPDFJPzJEkSCLw
wxXXX06XX2cXXX88XX
1
1400814743
lqxwMsiY9EXRDpms
c2dxxxe186116b32b06axxxc1a688b671eexxx5e
sha1
Finally, the corresponding business logic processing will not be detailed.
Bytes. From the document, we can see the number of notifications each time...