当前位置:网站首页>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咨询
作者相关文章
边栏推荐
- Two batches of pure milk are unqualified? Michael responded that he was conducting a large-scale screening and sampling inspection of products
- Redis configuration files and new data types
- Q-learning notes
- 2022-06-23 帆软部分公式及sql生成(月份、季度取数)
- 【 surprise】 la vitesse de téléchargement de Thunderbolt n'est pas aussi rapide que celle de la machine virtuelle
- Unity的脚本的基础语法(2)-Unity中记录时间
- [learn awk in one day] operator
- FlinkSQL自定义UDTF使用的四种方式
- 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
- MySQL中变量的定义和变量的赋值使用
猜你喜欢

机器学习笔记 - 自相关和偏自相关简介

Qt中的数据库使用

Determining the subject area of data warehouse construction

【一天学awk】正则匹配

Analysis of smart jiangcai login in Jiangxi University of Finance and Economics

Instructions for legend use in SuperMap iclient3d 11i for cesium 3D scene

Android development interview real question advanced version (with answer analysis)

电机控制park变换公式推导

Shell编程概述

黑马笔记---常用日期API
随机推荐
How to use AI technology to optimize the independent station customer service system? Listen to the experts!
Redis configuration files and new data types
Substrate 源码追新导读: 质押额度大幅度削减, RocksDB可以完全被Disable
Why should offline stores do new retail?
SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
江西财经大学智慧江财登录分析
Analysis of smart jiangcai login in Jiangxi University of Finance and Economics
Dataworks synchronizes maxcomputer to sqlserver. Chinese characters become garbled. How can I solve it
数据仓库建设之确定主题域
[QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信
Introduction to the novelty of substrate source code: comprehensive update of Boca system Boca weight calculation, optimization and adjustment of governance version 2.0
Introduction to sub source code updating: mid May: uniques NFT module and nomination pool
JMeter性能测试工作中遇到的问题及剖析,你遇到了几个?
rpm2rpm 打包步骤
【一天学awk】数组的使用
Js根据相同值将数组转换为二维数组
[MySQL] MySQL installation and configuration
Redis-缓存问题
[300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (II)
Package tronapi wave field interface based on thinkphp5 PHP version -- interface document attached -20220627