Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does PHP handle WeChat Pay's notification?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "PHP how to deal with WeChat Pay notice", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "PHP how to deal with WeChat Pay notice" this article.

The implementation of the notification mechanism, officially only documents but no demo code, for those who have not done it, it takes a lot of time to do testing.

From the point of view of the document, the data notified by Wechat each time, the structure is more complex, is a multi-segment data, in addition to take out POST data, but also take other data.

First of all, there is a question about the values of php://input and $_ POST. The simple list is as follows:

1 when the value of application/x-www-form-urlencoded Contente-Type is application/x-www-form-urlencoded, php will fill the http request body corresponding data into the array $_ POST, and the data entered into the $_ POST array is the result of urldecode () parsing. (in fact, in addition to the Content-Type, there is also multipart/form-data that indicates that the data is form data, which we will cover later.)

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

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

4the GET GET data can not be read by the input php _ hand. This is because the $_ GET data is written as query_path in the PATH field of the http request header (header), not in the body section 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, because the xml_rpc data specification is xml, its Content-Type is text/xml.

5. Php://input encountered multipart/form-data, please refer to RFC1867's description of it. Multipart/form-data also indicates that the form data is submitted in the POST method, which is accompanied by file upload, so it will be different from the application/x- www-form-urlencoded data format. It will be delivered to the server in a more reasonable and efficient data format. When Content-Type is multipart/form-data, even if the data exists in the http request body, php://input is empty. At this time, PHP will not fill the data into the php://input stream. 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, php://input and $_ POST data are "consistent", while when other Content-Type is, php://input and $_ POST data data are inconsistent. Because only when Content-Type is application/x-www-form- urlencoded or multipart/form-data, PHP will fill the corresponding part of the body data in the http request packet into the $_ POST global variable, and the other cases will be ignored by PHP. Php://input may not be empty except when the data type is multipart/form-data.

To paraphrase the meaning of so many words, that is to say, these two ways have to be used to read the data transmitted by Wechat.

Take $POST first. 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' = >' 12xxxxxxxxxx'

'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'

)

Then use file_get_contents ('php://input') to read additional information, such as:

one

1400814743

Finally, do the corresponding business logic processing, do not elaborate.

The above is all the contents of the article "how to deal with WeChat Pay notice by PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report