当前位置:网站首页>【uniapp调用微信支付】uniapp开发小程序-调用微信支付
【uniapp调用微信支付】uniapp开发小程序-调用微信支付
2022-07-16 17:17:00 【马小跳的Coding进阶之路】
哈喽大家好~我是马小跳。一名进阶中的程序媛。
在这里记录下自己成长的每一次进步,希望遇到志同道合的猿友
一起努力,一起把技术up up up!!!

使用uniapp开发小程序时,调用微信支付的步骤如下:
一、manifest.json里配置相关参数
1.在manifest.json - App模块权限选择 中勾选 payment(支付)
2.在 manifest.json - App SDK配置 中,勾选需要的支付平台,目前有微信支付、支付宝支付、苹果应用内支付(IAP),其中微信支付需要填写从微信开放平台获取的

二、微信小程序支付-代码:
这里的timeStamp, nonceStr, package, signType, paySign是由后端与微信交互生成后,通过接口传递过来的,调用接口直接取出来即可。
uni.requestPayment({
provider: 'wxpay', //支付类型-固定值
timeStamp: res.data.wechat.timeStamp, // 时间戳(单位:秒)
nonceStr: res.data.wechat.nonceStr, // 随机字符串
package: res.data.wechat.package, // 固定值
signType: res.data.wechat.signType, //固定值
paySign: res.data.wechat.paySign, //签名
success: function (res) {
// console.log('success:' + JSON.stringify(res));
console.log("支付成功");
uni.showToast({
icon: 'success',
title: '支付成功'
})
//清空输入框
that.name = ''
that.idcard = ''
},
fail: function (err) {
// console.log('fail:' + JSON.stringify(err));
console.log("支付失败");
uni.showToast({
icon: 'none',
title: '支付失败'
})
}
});
三、APP支付代码:
//订单对象,从服务器获取
var orderInfo = {
"appid": res.data.orderInfo.appId, // 应用ID(AppID)
"partnerid": res.data.orderInfo.partnerId, // 商户号(PartnerID)
"prepayid": res.data.orderInfo.prepayId, // 预支付交易会话ID
"package": res.data.orderInfo.packageValue, // 固定值
"noncestr": res.data.orderInfo.nonceStr, // 随机字符串
"timestamp": res.data.orderInfo.timeStamp, // 时间戳(单位:秒)
"sign": res.data.orderInfo.sign, // 签名,这里用的 MD5 签名
};
uni.requestPayment({
provider: "wxpay",
orderInfo: orderInfos,
success(res) {
console.log('success:' + JSON.stringify(res));
console.log("支付成功");
},
fail(err) {
console.log('fail:' + JSON.stringify(err));
console.log("支付失败");
});
ending~
边栏推荐
- 1. Use Jekyll to build a personal blog
- BUCK 电路PSIM仿真模型搭建之二 (传递函数模块的使用)
- 1.3.2-sql injection - SQL blind injection - time blind injection
- leetcode 43. String multiplication (string + simulation)
- 1.线程与进程
- Parallel and distributed framework
- [sword finger offer II 041. Average value of sliding window]
- [chance enlightenment -45]: Guiguzi - Chapter 9 - because people talk, like them
- [200 opencv routines] 232 Spectral method of feature description
- 8. Island issue
猜你喜欢

12.快速排序

The 20th anniversary of Beijing Hyundai: Streamline product layout and strive to achieve 520000 vehicles by 2025

Network disk + download method of the first nuscenes dataset in the whole network

Virtualization architecture

11.滑动窗口的最大值——重要结构双端队列

OpenGL ES学习(4)——投影和绘制

Horizon 8 test environment deployment (6): UAG load balancing configuration-2

Parallel and distributed framework

死锁预防、死锁避免、死锁检测

Horizon 8 test environment deployment (8): app volumes managers load balancing configuration
随机推荐
4. Connect terminated threads (recycle threads)
Nc20566 [scoi2010] games
Nc20583 [sdoi2016] gear
支付流程面试思路
World Tour Finals 2019 D - Distinct Boxes 题解
电力系统经济调度(Matlab完整代码实现)
LeetCode第82场双周赛
The first large-scale Chinese video multimodal similarity data set
报错:cannot read properties of undefined(reading ‘forEach‘)
Deadlock prevention, deadlock avoidance, deadlock detection
Récemment trouvé la Bibliothèque d'animation lottie
【C语言】条件编译的深入理解
6. Thread cancellation
OpenGL ES学习(4)——投影和绘制
Eventbus is used temporarily
7.9 hash table (hash table)
First experience of raspberry pie
OpenGL es learning (6) -- recognizing textures
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
MySQL六十六问,两万字+五十图详解!有点六!