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 comes a question about php://input and $_post, and the following are some simple columns:
When the 1,content-type value is application/x-www-form-urlencoded, PHP will fill the HTTP request body with the corresponding data into the array $_post, fill in the $_ The data in 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.
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 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, PHP:// Input and $_post data data are inconsistent. because only when Content-type is application/x-www-form-urlencoded or Multipart/form-data, PHP does not populate the $_post global variable with the body part of the HTTP request packet, and PHP ignores it in other cases. While php://input may not be empty except in the case of a data type of Multipart/form-data
The above means of reporting so many words, that is to say, you have to use both methods to read the data passed over.
First fetch $post This is the regular payment notification information, such as:
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 ' = ' and ' 3400 ', ' sign ' = ' 545fa0e8b594bbxxxx48xx142f084ty ', ' sign_type ' = ' MD5 ', ' Time_end ' = ' 20130223110224 ', ' total_fee ' = ' 3400 ', ' trade_mode ' = ' 1 ', ' trade_state ' = > ' 0 ', ' transaction_id ' = ' 12xxx449012014xxx33174005xxx ', ' transport_fee ' and ' 0 ',
Then use file_get_contents (' Php://input ') to read additional information, such as:
<XML><OpenId> </span> <span>o0pd3jqhan7b0tvpdfjpzjeksclw</span><span>
OpenId><AppId> </span> <span>wxxxx06xx2cxxx88xx</span><span>!-- AppId ; < Issubscribe ; 1 !-- issubscribe ; < TimeStamp , 1400814743 ,!-- TimeStamp ; < noncestr ; ! [cdata[ lqxwmsiy9exrdpms ]]> !-- noncestr > < appsignature ;
c2dxxxe186116b32b06axxxc1a688b671eexxx5e ]]> !-- Appsignature , <, signmethod ,
SHA1 ]]> !-- signmethod ; !-- XML ;
Finally, do the corresponding business logic processing, it is not detailed.
http://www.bkjia.com/PHPjc/775945.html www.bkjia.com true http://www.bkjia.com/PHPjc/775945.html techarticle 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 what the document says, the number of each notification comes up ...