当前位置:网站首页>微信小程序微信支付概述
微信小程序微信支付概述
2022-07-27 16:11:00 【mr_cmx】
一、开发前的准备
注册一个微信商户号、微信小程序开通微信支付,获取并记录你的商户号、小程序appid、小程序AppSecret、APIv3密钥,在平台下载证书,并记录 证书序列号
具体看官方文档
二、客户端
(1)获取用户的openid并存储,可以看我之前的博文或官方的文档
(2)向后台发起请求生成预支付交易单,并调起微信支付
//提交购买
submitOrder(){
let openid=app.globalData.openid;
//统一下单
//创建购买预订单
let self=this;
wx.showLoading({
title: '加载中',
})
let data={
//根据需要
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){
//调起微信支付
wx.requestPayment(
{
timeStamp: res.data.data.timestamp,//时间戳
nonceStr: String(res.data.data.nonceStr),//随机字符串
package: res.data.data.package,//订单详情扩展字符串
signType: res.data.data.signType,//签名方式
paySign: res.data.data.paySign,//签名
success:function(res){
wx.showToast({
icon:'none',
title: '支付成功',
mask:true,
duration:2000
})
},
fail:function(res){
},
})
}else{
wx.showToast({
icon:'none',
title: res.data.msg
})
}
}
})
},
三、后台
后台操作比较复杂,更多的需要看官方的文档
1、搭建和配置开发环境,使用官方提供的开发库,封装了签名生成、签名验证、敏感信息加/解密、媒体文件上传等基础功能
• wechatpay-apache-httpclient,适用于使用Apache HttpClient处理HTTP的Java开发者
• wechatpay-php(推荐)、wechatpay-guzzle-middleware,适用于PHP开发者
• wechatpay-go,适用于Go开发者
2、创建加载商户私钥、加载平台证书、初始化httpClient的通用方法(具体看官方文档,或者看上边开发库GitHub下面的使用介绍)
3、小程序下单
(1)使用官方接口,官方接口文档
POST
‘https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi’, //请求URL
必传参数:
appid :应用ID
mchid : 直连商户号
description :商品描述
out_trade_no :商户订单号
notify_url : 通知地址
amount:{
total:总金额
}
payer:{
openid :用户标识
}
获得参数 prepay_id //预支付交易会话标识
(2)生成签名:paySign生成规则、响应详情请参见小程序调起支付API接口文档(使用官方提供的开发库,进行rsa加密)
(3)给客户端返回
timeStamp: 时间戳
nonceStr: 随机字符串
package: 小程序下单接口返回的prepay_id参数值,提交格式如:prepay_id=***
signType: 该接口V3版本仅支持RSA
paySign: 签名(上面生成的签名)
4、在上边的notify_url通知地址 接收微信支付的结果通知,然后操作数据库
边栏推荐
- [mit 6.s081] LEC 1: introduction and examples notes
- [MIT 6.S081] Lab8: locks
- Together with Samsung, vivo will promote exynos980 dual-mode 5g mobile phone!
- Intel releases a new generation of movidius Vpu: 10 times higher performance and 30W power consumption
- Deep learning - paper reading: action structural graph convolution network as-gcn
- @Datetimeformat received less than minutes and seconds, conversion times type exception
- Lotcode dynamic array exercise (724118766)
- Dynamic linked list 4 one-way circular linked list (loopsingle Implementation)
- Let's move forward together, the 10th anniversary of Google play!
- "Who is Huawei" documentary film series landing on BBC: exposing a large number of Ren Zhengfei's unknown experience
猜你喜欢
随机推荐
[MIT 6.S081] Lab 7: Multithreading
On recommend mechanism in distributed training
微信小程序 wxacode.getUnlimited生成小程序码
Binary tree concept
二叉树概念
Hackers use lasers to attack, and voice assistants can be activated from a distance of 100 meters
深度学习:GCN案例
Publish your own NPM component library
Deep learning: installation package records
How do corporate giants such as Schneider Electric and L'Oreal make open innovation? Uncover secrets of demo World Innovation Summit
Let's move forward together, the 10th anniversary of Google play!
动态链表4单向循环链表(LoopSingle实现)
深度学习:GAN优化方法-DCGAN案例
Marvell公布旗下Arm服务器芯片路线图,下一代性能将比ThunderX2高两倍
Glory and Xiaomi reported on the double 11: they all called themselves champions
[mit 6.s081] LEC 4: page tables notes
浅谈AI深度学习的模型训练和推理
嘉楠耘智已完成预路演,预计11月20日登陆纳斯达克
[MIT 6.S081] Lab 11: networking
动态链表2栈的链表存储结构(LinkedStack实现)




![[MIT 6.S081] Lab 9: file system](/img/f5/ea30b1fe5b6d73c86f2509c690ca20.png)
![[MIT 6.S081] Lab 4: traps](/img/8b/ca4819f8b1cfc6233745a124790674.png)


