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:
Copy codeThe Code is as follows:
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:
Copy codeThe Code is as follows:
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:
Copy codeThe Code is as follows:
<Xml> <OpenId> <! [CDATA [o0pd3jqhan7b0tv1_jpzjeksclw]> </OpenId>
<AppId> <! [CDATA [wxXXX06XX2cXXX88XX]> </AppId>
<IsSubscribe> 1 </IsSubscribe>
<TimeStamp> 1400814743 </TimeStamp>
<NonceStr> <! [CDATA [lqxwMsiY9EXRDpms]> </NonceStr>
<AppSignature> <! [CDATA [c2dxxxe186492b32b06axxxc1a688b671eexxx5e]> </AppSignature>
<SignMethod> <! [CDATA [sha1]> </SignMethod>
</Xml>
Finally, the corresponding business logic processing will not be detailed.