当前位置:网站首页>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咨询
作者相关文章
边栏推荐
- MySQL judges the calculation result and divides it by 100
- New function of SuperMap iserver11i -- release and use of legend
- Dqn notes
- JMeter之事务控制器
- 你想要的异常知识点都在这里了
- 市值蒸发650亿后,“口罩大王”稳健医疗,盯上了安全套
- 【驚了】迅雷下載速度竟然比不上虛擬機中的下載速度
- Determining the subject area of data warehouse construction
- Package tronapi wave field interface based on thinkphp5 PHP version -- interface document attached -20220627
- elementui中清除tinymce富文本缓存
猜你喜欢

60 个神级 VS Code 插件!!

Google refutes rumors and gives up tensorflow. It's still alive!
![[surprised] the download speed of Xunlei is not as fast as that of the virtual machine](/img/04/b0d23266b70c9ad6990a5203ef8ddf.png)
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine

Questionnaire star questionnaire packet capturing analysis

FlinkSQL自定义UDTF使用的四种方式

市值蒸发650亿后,“口罩大王”稳健医疗,盯上了安全套

Qt中的数据库使用

Reading the table data of Tencent documents in the applet

Analysis of the whole process of common tilt data processing in SuperMap idesktop

Dark horse notes -- List series collections and generics
随机推荐
RDS MySQL数据迁移PolarDB MySQL费用可以转过去吗?
Videos are stored in a folder every 100 frames, and pictures are transferred to videos after processing
Dqn notes
How to use AI technology to optimize the independent station customer service system? Listen to the experts!
Layout of pyqt5 interface and loading of resource files
Flinksql customizes udatf to implement topn
排查问题的方法论(适用于任何多方合作中产生的问题排查)
Unity脚本的基础语法(1)-游戏对象的常用操作
【驚了】迅雷下載速度竟然比不上虛擬機中的下載速度
[learn awk in one day] operator
【惊了】迅雷下载速度竟然比不上虚拟机中的下载速度
Idea has a new artifact, a set of code to adapt to multiple terminals!
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年6月29日21:59:34
[one day learning awk] Fundamentals
When MySQL judges that the execution condition is null, it returns 0. Correct parameter count in the call to native function 'isnull',
Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
Unity脚本程序的开发
Visual Studio配置Qt并通过NSIS实现项目打包
Spatiotemporal prediction 2-gcn_ LSTM
Can the polardb MySQL fees for RDS MySQL data migration be transferred?