当前位置:网站首页>uniapp支付之APP微信支付unicloud版(附源码)
uniapp支付之APP微信支付unicloud版(附源码)
2022-06-30 12:23:00 【《源码好优多》】
1 先上效果图

为啥要用 unicloud ? 不用搭建自己的服务器,不用买域名,不用备案域名,不用支持https。只需要一个简单的云函数,就可以轻松的实现微信支付功能
问:服务端语言是什么,有框架限制吗?
答:服务端基于uniCloud开发,无框架限制,使用任何框架都可以集成。
问:我的项目不是uniCloud,是java、php等语言,可以使用吗?
答:可以,支付环节部署在云开发环境,支付成功后通知你的服务器接口。
2 准备工作
- 1, appid,要在微信开放平台(https://open.weixin.qq.com)注册申请账号。注这里公司使用需300元认证费。在应用详情中申请开通微信支付功能。
- 2,已经申请微信支付的商户号(商户id,商户秘钥)。
- 3,appid和你的商户号关联

3 配置
1、在manifest.json文件“App模块配置”项的“Payment(支付)”下,勾选“微信支付”项

参数说明
- appid
微信开放平台申请的应用ID(AppID) - iOS平台通用链接(Universal Link)
在iOS平台微信支付使用的通用链接,必须与微信开放平台 “管理中心” > “应用详情” > “开发信息” 中的“Universal Links”项中配置一致
注:关于通用链接,如果没有配置一致,iOS是无法在支付完成后回到APP的。
2、找到 uniCloud -> cloudfunctions -> common 云函数 uni-config-center -> uni-pay -> config.json->wxConfigApp修改为你自己的appId,商户号和秘钥
应用内发起支付——API使用
调用 uni.requestPayment(OBJECT)发起支付,OBJECT参数中provider属性值固定为wxpay
这里是orderInfo,该属性值为订单对象。依然值得注意的是package,微信直传过来的值是packageValue。
partnerid,微信传过来的是partnerId。
prepayid,微信传过来是prepayId。
noncestr,微信传过来的是nonceStr。
timestamp,微信传过来的是timeStamp。
这里一定一定要注意大小写,不然订单请求失败,让你找问题,找到痛不欲生。
//订单对象,从uniCloud获取
let 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("支付失败");
});
源码地址
https://ext.dcloud.net.cn/plugin?id=8612
下载源码只要把appid、微信商户号、密钥换成自己的就可以使用了
帮助
大家支付有问题有不懂的地方加我qq2214904953咨询
作者相关文章
边栏推荐
- ffmpeg 杂项
- 机器学习笔记 - 自相关和偏自相关简介
- Analysis of the whole process of common tilt data processing in SuperMap idesktop
- Problems and analysis in JMeter performance testing. How many problems have you encountered?
- Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions
- Vision based robot grasping: from object localization, object pose estimation to parallel gripper grasping estimation
- MySQL中变量的定义和变量的赋值使用
- [surprised] the download speed of Xunlei is not as fast as that of the virtual machine
- 解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matchin问题
- 【一天学awk】内置变量的使用
猜你喜欢

Database usage in QT

Redis configuration files and new data types

Three ways for flinksql to customize udaf

【OpenGL】OpenGL Examples

Reading the table data of Tencent documents in the applet

【一天学awk】数组的使用

Efficient elliptic curve point addition and multiplication in scrypt

Dqn notes

SuperMap iclient3d for webgl loading TMS tiles
![[one day learning awk] array usage](/img/75/4333452142a3c7325e0712f3306985.png)
[one day learning awk] array usage
随机推荐
Dark horse notes - common date API
项目中遇到一个有趣的事情
Event handling in QT
[one day learning awk] use of built-in variables
如何利用AI技术优化独立站客服系统?听听专家怎么说!
Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions
Visual studio configures QT and implements project packaging through NSIS
SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
MySQL implements the division of two query results
问卷星问卷抓包分析
Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
基于ThinkPHP5封装tronapi-波场接口-PHP版本--附接口文档-20220627
JMeter性能测试之相关术语及性能测试通过标准
60 个神级 VS Code 插件!!
【一天学awk】正则匹配
Double dqn notes
Shell基础入门
常用的ui组件
Flink SQL console, group not recognized_ Concat function?
How to select an OLAP database engine?