WeChat payment development dynamic link Native payment example code

高洛峰
Release: 2017-03-27 14:12:39
Original
2812 people have browsed it

This article mainly introduces the Native payment implementation process based on dynamic link QR code under WeChat payment, hoping to provide help to partners who develop WeChat payment

Note:

WeChat Pay is currently divided into v2 and v3 versions. Those who applied before September 10, 2014 will be in v2 version, and those who applied after that will be in v3 version. The V3 version of WeChat Pay does not have the paySignKey parameter. This article introduces WeChat Pay v3.

1. Generate product information

During the dynamic link payment process, the product transaction is generated first, and then the payment transaction is performed.

1. Product information preparation

The main thing is to first define the name and price of the product, as well as the transaction number. code show as below.

include_once("../WxPayPubHelper/WxPayPubHelper.php"); //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("body","贡献一分钱");//商品描述 $timeStamp = time(); $out_trade_no = WxPayConf_pub::APPID."$timeStamp"; $unifiedOrder->setParameter("out_trade_no","$out_trade_no");//商户订单号 $unifiedOrder->setParameter("total_fee","1");//总金额 $unifiedOrder->setParameter("notify_url",WxPayConf_pub::NOTIFY_URL);//通知地址 $unifiedOrder->setParameter("trade_type","NATIVE");//交易类型 //非必填参数,商户可根据实际情况选填 $unifiedOrder->setParameter("device_info","100001");//设备号
Copy after login

The above parameters are finally encapsulated into the following similar XML parameters

   1   100001  1237905502    
Copy after login

2. Call the unified payment request

Send the above XML to the unified payment interface

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

Get the following XML data

            
Copy after login

In this way, you will get a code_url

The program generates a QR code from the code_url, and then provides it to the user to scan

2. User payment

1. User payment

User payment is successful Afterwards, WeChat will send an XML notification to notify_url with the following content:

               1   
Copy after login

After notification_url is received, it will return a confirmation success message to the WeChat server

  
Copy after login

In this way, a dynamic link Native is completed.

Use the order query interface to query the order and return the following

Transaction status: SUCCESS
Equipment number: 100001
User ID: oMNKHuBTW4YWgNGAVQW00tWK6auM
Whether to follow the public account: N
Transaction type: NATIVE
Payment bank: CFT
Total amount: 1
Cash coupon amount:
Currency type: CNY
WeChat payment order number: 1002750205201505310187709542
Merchant order number: 100001_1433009089
Merchant data package: Array
Payment completion time: 20150531020837

The above is the collection of information on WeChat payment dynamic link Native payment. I hope it can help friends who develop WeChat payment.

The above is the detailed content of WeChat payment development dynamic link Native payment example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!