Detailed description of the code of the WeChat payment development transaction notification instance

Source: Internet
Author: User
Tags openid
This article mainly introduces how to get the transaction notification when using JSAPI for payment, and provides code instances. I hope this article will be helpful to the development and payment partners. This article mainly introduces how to get the transaction notification when using JS API for payment, and provides code instances to help developers

I. transaction notification

After the payment is successfully completed, the user notifies the background of the payment result of the merchant server (notify_url. Merchants can use the notification results of yy_url to display personalized pages.

During background notification interaction, if the response received by the merchant is not success or timed out and the notification does not fail, the notification will be periodically re-initiated through a certain policy (such as a total of 8 Notifications in 30 minutes, improve the notification success rate as much as possible, but do not guarantee that the notification will succeed.

The background notification uses the POST mechanism through the notify_url in the request.

At the same time, xml data will be included in postData.

II. transaction result acquisition and response

Create notice. php for notification results according to the official documentation.

The program content is as follows:

 $ Value) {logger ("Key: $ key; Value: $ value") ;}$ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; logger ($ postStr ); if (isset ($ _ GET) {echo "success";} // function logger ($ log_content) {$ max_size = 100000; $ log_filename = "log. xml "; if (file_exists ($ log_filename) and (abs (filesize ($ log_filename) >$ max_size) {unlink ($ log_filename);} file_put_contents ($ log_filename, date ('H: I: s '). "". $ log_content. "\ r \ n", FIL E_APPEND) ;}?>

The role of the above program is:

GET the post-to-url notifications in the form of GET variables

Get XML data packets of post

Return successful message success

Add the complete notice. php path to the notice url paid by the js api.

$wxPayHelper->setParameter("notify_url", http://www.doucube.com/wxpay/notice.php);

In this way, after the transaction is completed, the url will receive a notification and be recorded in the log file. our test is as follows:

The GET variable and XML are as follows:

Key: bank_billno; Value: 201405273540085997Key: bank_type; Value: 2011Key: discount; Value: 0Key: fee_type; Value: 1Key: input_charset; Value: GBKKey: notify_id; Value: Gx8ov6tT6_yaARrtKG6RFZ4KiVtKqVnJzvulFlteJ3dhBg38iRtKs0pTXXfgh8WnH15mIhG6j65ggbzzYguh1mutG3B5oHsKKey: out_trade_no; Value: JfuKdiBig4zZnE4nKey: partner; Value: 1234567890Key: product_fee; Value: 1Key: sign; Value: 08876C4A9F7A36A9EA972C211C122362Key: sign_type; Value: MD5Key: time_end; Value: 20140527194139Key: total_fee; Value: 1Key: trade_mode; Value: 1Key: trade_state; Value: 0Key: transaction_id; Value: 1218614901201405273313473135Key: transport_fee; Value: 0
 
  o0pk9uIVnlY-fJkzFKEbQ6LJ4cFc
  wx0000000000000000
  
   1
  
  
   1401190899
  
  iOb2flJ0ILFAmBqJ
  66678894aae680ba140e18e66d1295dfadabd9ab
  sha1
  
 

In the window, an OK pop-up window will be received.

The above are the materials for the payment development and transaction notifications. thank you for your support!

The above is a detailed description of the instance code of the payment development transaction notification. For more information, see other related articles on php Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.