当前位置:网站首页>Wechat applet wechat payment overview
Wechat applet wechat payment overview
2022-07-27 18:39:00 【mr_ cmx】
One 、 Preparation before development
Register a wechat merchant number 、 Wechat applet opens wechat payment , Get and record your merchant number 、 Applet appid、 Applet AppSecret、APIv3 secret key , Download the certificate on the platform , And record Certificate serial number
To be specific, see Official documents
Two 、 client
(1) Get the user's openid And store , You can see me Previous posts Or official documents
(2) Send a request to the background to generate an advance payment transaction order , And adjust wechat payment
// Submit purchase
submitOrder(){
let openid=app.globalData.openid;
// Unified order
// Create purchase advance order
let self=this;
wx.showLoading({
title: ' Loading ',
})
let data={
// According to need
order_number: this.data.order_number,
openid,
user_id: app.globalData.userInfo.id,
//...
}
wx.request({
url: app.globalData.requestUrl+'/wx/prepay',
data,
method:'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success (res) {
wx.hideLoading()
if(res.data.status===0){
// I'm going to pay WeChat
wx.requestPayment(
{
timeStamp: res.data.data.timestamp,// Time stamp
nonceStr: String(res.data.data.nonceStr),// Random string
package: res.data.data.package,// Order details extension string
signType: res.data.data.signType,// Signature method
paySign: res.data.data.paySign,// Signature
success:function(res){
wx.showToast({
icon:'none',
title: ' Successful payment ',
mask:true,
duration:2000
})
},
fail:function(res){
},
})
}else{
wx.showToast({
icon:'none',
title: res.data.msg
})
}
}
})
},
3、 ... and 、 backstage
The background operation is complicated , More need to see Official document
1、 Build and configure the development environment , Use the official development library , Encapsulates signature generation 、 Signature verification 、 Sensitive information plus / Decrypt 、 Media file upload and other basic functions
• wechatpay-apache-httpclient, Suitable for use Apache HttpClient Handle HTTP Of Java developer
• wechatpay-php( recommend )、wechatpay-guzzle-middleware, Apply to PHP developer
• wechatpay-go, Apply to Go developer
2、 Create and load merchant private key 、 Load platform certificate 、 initialization httpClient The general method of ( See the official documents for details , Or look at the development library above GitHub The following usage introduction )
3、 Small program orders
(1) Using the official interface , Official interface document
POST
‘https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi’, // request URL
Must pass parameters :
appid : application ID
mchid : Direct merchant number
description : Commodity Description
out_trade_no : Merchant order number
notify_url : Notice address
amount:{
total: Total sum
}
payer:{
openid : User ID
}
Get parameters prepay_id // Prepaid transaction session ID
(2) Generate signature :paySign Generate rules 、 Please refer to The app starts paying API Interface document ( Use the official development library , Conduct rsa encryption )
(3) Return... To the client
timeStamp: Time stamp
nonceStr: Random string
package: The applet orders the interface to return prepay_id Parameter values , The submission format is as follows :prepay_id=***
signType: The interface V3 Version only supports RSA
paySign: Signature ( The signature generated above )
4、 In the above notify_url Notice address Receive notification of wechat payment results , And then operate the database
边栏推荐
- View port PID and end process
- Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)
- Super practical! After reading the kubernetes study notes hidden by Alibaba P9, call NB directly
- 记一次 .NET 某智慧物流 WCS系统 CPU 爆高分析
- Chained storage structure of dynamic linked list 3 queue (linkedqueue Implementation)
- 解决Jsp级联问题
- mysql视图基本操作
- 常用词词性表
- [MIT 6.S081] Lab8: locks
- pandas的to_sql函数使用
猜你喜欢
![[MIT 6.S081] Lec 6: Isolation & system call entry/exit 笔记](/img/b3/89b3688a06aa39d894376d57acb2af.png)
[MIT 6.S081] Lec 6: Isolation & system call entry/exit 笔记

2021.7.17笔记 mysql其他命令
![[MIT 6.S081] Lec 10: Multiprocessors and locking 笔记](/img/62/ca6362830321feaf450865132cdea9.png)
[MIT 6.S081] Lec 10: Multiprocessors and locking 笔记

机器学习分类任务效果评估指标大全(包含ROC和AUC)

2021.7.30笔记 索引

Deep learning: GCN diagram classification case
![[MIT 6.S081] Lab 4: traps](/img/8b/ca4819f8b1cfc6233745a124790674.png)
[MIT 6.S081] Lab 4: traps

Knowledge map pyhanlp realizes named body recognition (with named body recognition code)

Why don't you like it? It's easy to send mail in ci/cd

Common commands of database 1
随机推荐
[MIT 6.S081] Lec 3: OS organization and system calls 笔记
2021.7.13笔记 子查询
Deep learning: Gan case exercise -minst handwritten digits
2021.8.1 Notes database design
[mit 6.s081] LEC 10: multiprocessors and locking notes
RSA encryption and decryption (compatible with wechat applet environment)
2021.7.12 internal and external connection of notes
Deep learning - VIDEO behavior recognition: paper reading - two stream revolutionary networks for action recognition in videos
Deep learning: Gan optimization method dcgan case
Deep learning: GCN case
[mit 6.s081] LEC 4: page tables notes
[MIT 6.S081] Lab 5: xv6 lazy page allocation
Idea packaging war package and war package location
微信小程序获取手机号
Technology sharing | quick intercom integrated dispatching system
XML学习 Day1 : xml / Jsoup解析器 / selector选择器 /Xpath选择器
2021.8.7笔记 servlet
Why don't you like it? It's easy to send mail in ci/cd
[mit 6.s081] LEC 5: calling conventions and stack frames risc-v notes
Jianan Yunzhi has completed the pre roadshow and is expected to land on NASDAQ on November 20