当前位置:网站首页>微信小程序微信支付概述
微信小程序微信支付概述
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通知地址 接收微信支付的结果通知,然后操作数据库
边栏推荐
- Deep learning: gat
- Marvell公布旗下Arm服务器芯片路线图,下一代性能将比ThunderX2高两倍
- How do corporate giants such as Schneider Electric and L'Oreal make open innovation? Uncover secrets of demo World Innovation Summit
- Graphical interface programming
- [MIT 6.S081] Lec 5: Calling conventions and stack frames RISC-V 笔记
- 深度学习:GCN案例
- 展锐鲜苗:赋能全场景应用,海量数据需要AI与IoT融合
- C杂讲 链表初讲
- 宣布收购文晔30%股份,大联大意欲何为?
- "Who is Huawei" documentary film series landing on BBC: exposing a large number of Ren Zhengfei's unknown experience
猜你喜欢

深度学习-视频行为识别:论文阅读——双流网络(Two-stream convolutional networks for action recognition in videos)

深度学习:GCN(图卷积神经网络)理论学习总结

数据库的常用命令2
![[mit 6.s081] LEC 5: calling conventions and stack frames risc-v notes](/img/1f/6384f4831718477f0567540250f352.png)
[mit 6.s081] LEC 5: calling conventions and stack frames risc-v notes
![[mit 6.s081] LEC 1: introduction and examples notes](/img/5d/2fc4bde8eebbb22605d314b5292e05.png)
[mit 6.s081] LEC 1: introduction and examples notes
![[MIT 6.S081] Lab 7: Multithreading](/img/f4/26e513fb8678a88cfba29c1a636b37.png)
[MIT 6.S081] Lab 7: Multithreading

2021.7.22笔记 约束
![[mit 6.s081] LEC 4: page tables notes](/img/30/f1e12d669b656a0b14aa8c7b210085.png)
[mit 6.s081] LEC 4: page tables notes

Dynamic linked list 4 one-way circular linked list (loopsingle Implementation)
![[MIT 6.S081] Lab 4: traps](/img/8b/ca4819f8b1cfc6233745a124790674.png)
[MIT 6.S081] Lab 4: traps
随机推荐
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
After being "expelled" from bitland, the Jank group said for the first time: it will return as soon as possible through legal channels!
Glory and Xiaomi reported on the double 11: they all called themselves champions
浅谈AI深度学习的模型训练和推理
Read only mode of buffer
Marvell announced the roadmap of its arm server chip, and the performance of the next generation will be twice that of thunderx2
rsa加解密(兼容微信小程序环境)
[MIT 6.S081] Lab 11: networking
Deep learning: GCN (graph convolution neural network) theory learning summary
[mit 6.s081] LEC 1: introduction and examples notes
The end of another era!
微信小程序多文件上传
Redis网红高频面试题三连:缓存穿透?缓存击穿?缓存雪崩?
宣布收购文晔30%股份,大联大意欲何为?
深度学习:GAN案例练习-minst手写数字
英伟达发布全球最小边缘AI超算:算力21TOPS,功耗仅10W!
记一次 .NET 某智慧物流 WCS系统 CPU 爆高分析
Here comes the first 5g SOC of MediaTek! A77+g77+apu3.0, officially released on November 26!
LootCode动态数组练习(724,118,766)