The dynamic link of WeChat development native payment

Source: Internet
Author: User
Tags openid
This paper mainly introduces the payment realization process of native payment based on dynamic link QR code, hoping to provide help to the small partners who develop the payment.

Attention:

Payment is now divided into V2 version and V3 version, the application for the V2 version before September 10, 2014, after the application for the V3 version. The V3 version of the payment does not have Paysignkey parameters. Please refer to the other articles in V2 studio for more information. This article describes the payment v3.

First, generate product information

During the dynamic link payment process, it is the trade of the goods that is made by Mr. Cheng to carry out the payment transaction.

1. Product Information Preparation

The first is to define the name and price of the product, and the transaction number. The code is as follows.

Include_once (".. /wxpaypubhelper/wxpaypubhelper.php ");  Use the unified payment interface  $unifiedOrder = new Unifiedorder_pub ();    Set the unified Payment interface parameters  //settings Required Parameters  //appid is filled, the merchant does not need to fill in  //mch_id, the merchant does not need to fill in the  //noncestr, the merchant does not need to fill in the duplicate  // Spbill_create_ip has been filled, merchants do not need  to fill in//sign, merchants do not need to fill in the  $unifiedOrder->setparameter ("Body", "contribution of a Penny");//Product Description  $timeStamp = time ();  $out _trade_no = wxpayconf_pub::appid. " $timeStamp ";  $unifiedOrder->setparameter ("Out_trade_no", "$out _trade_no");//Merchant Order number   $unifiedOrder->setparameter (" Total_fee "," 1 ");//Total Amount  $unifiedOrder->setparameter (" Notify_url ", wxpayconf_pub::notify_url);//Notification address   $unifiedOrder->setparameter ("Trade_type", "NATIVE");//transaction type  //non-mandatory parameters, the merchant can be selected according to the actual situation  $unifiedOrder- Setparameter ("Device_info", "100001");//device number

The above parameters are eventually encapsulated as XML-like parameters

<xml> <body><! [cdata[contribute a penny]]></body> <out_trade_no><! [cdata[100001_1433009089]]></out_trade_no> <total_fee>1</total_fee> <notify_url><! [cdata[http://www.doucube.com/weixin/demo/notify_url.php]]></notify_url> <trade_type><! [cdata[native]]></trade_type> <device_info>100001</device_info> <appid><! [cdata[wx1d065b0628e21103]]></appid> <mch_id>1237905502</mch_id> <spbill_create_ip> <! [cdata[61.129.47.79]]></spbill_create_ip> <nonce_str><! [cdata[gwpdlnn0zlfih21gipjj5z53i7vea8e8]]></nonce_str> <sign><! [cdata[c5a1e210f9b4402d8254f731882f41ac]]></sign></xml>

2. Call a unified payment request

Send the XML above to the unified payment interface

Https://api.mch.weixin.qq.com/pay/unifiedorder

Get the following XML data

<xml> <return_code><! [cdata[success]]></return_code>  <return_msg><![ Cdata[ok]]></return_msg>  <appid><![ Cdata[wx1d065b0628e21103]]></appid>  <mch_id><![ Cdata[1237905502]]></mch_id>  <device_info><![ Cdata[100001]]></device_info>  <nonce_str><![ Cdata[6u8ovttfuptagsiy]]></nonce_str>  <sign><![ Cdata[e84d8bc2331766dd685591f908367ff1]]></sign>  <result_code><![ Cdata[success]]></result_code>  <prepay_id><![ Cdata[wx20150531020450bb586eb2f70717331240]]></prepay_id>  <trade_type><![ Cdata[native]]></trade_type>  <code_url><![ Cdata[weixin://wxpay/bizpayurl?pr=dnp7omd]]></code_url> </xml>

So we get a code_url.

The program generates a QR code for the Code_url, which is then provided to the user to sweep

Second, the user pays

1. User Payment

After the

User pays successfully, an XML notification is sent to Notify_url, as follows

<xml> <appid><! [cdata[wx1d065b0628e21103]]></appid> <bank_type><! [cdata[cft]]></bank_type> <cash_fee><! [cdata[1]]></cash_fee> <device_info><! [cdata[100001]]></device_info> <fee_type><! [cdata[cny]]></fee_type> <is_subscribe><! [cdata[n]]></is_subscribe> <mch_id><! [cdata[1237905502]]></mch_id> <nonce_str><! [cdata[gwpdlnn0zlfih21gipjj5z53i7vea8e8]]></nonce_str> <openid><! [cdata[omnkhubtw4ywgngavqw00twk6aum]]></openid> <out_trade_no><! [cdata[100001_1433009089]]></out_trade_no> <result_code><! [cdata[success]]></result_code> <return_code><! [cdata[success]]></return_code> <sign><! [cdata[03eede7ade2abb7916795f37f19a3d13]]></sign> <time_end><! [cdata[20150531020838]]></time_end> <total_fee>1</total_fee> <trade_type><! [cdata[native]]></trade_type> <transaction_id><! [cdata[1002750205201505310187709542]]></transaction_id> </xml>

Notify_url received, and then returned to confirm the success of the message to the server

<xml> <return_code><! [cdata[success]]></return_code></xml>

In this way, a dynamic link native is complete.

Related recommendations:

Example of a refund function for PHP payment development

Laravel to pay development examples

5-Minute Payment access tutorial

Related Article

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.