唤起微信支付核心代码
async weixinPayApp() {
const self = this;
let postApi = '';
if (this.checkWexin) {
postApi = 'getOpenWeixinSignOrderInfo';
} else if (this.checkAliPay) {
postApi = 'getAlipaySignOrderInfoForApp';
}
let option = '';
if (this.entry) {
// 如果是从订单列表跳转 取orderId
option = {
orderId: this.orderId
};
if (this.isSpell) {
option.fightgroupOrderId = this.orderId;
}
} else {
// 走下单流程 去 orderGroudid
option = {
orderId: this.payOrderId
};
if (this.isSpell) {
option.fightgroupOrderId = this.payOrderId;
}
}
this.$u.api.pay[postApi](option).then(res => {
console.log('PAY', res);
let orderInfo = '';
if (this.checkWexin) {
const { appId, nonceStr, partnerId, prepayId, sign, timeStamp } = res.signOrderInfo;
orderInfo = {
appid: appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
noncestr: nonceStr, // 随机字符串
package: res.signOrderInfo.package, // 固定值
partnerid: partnerId, // 微信支付商户号
prepayid: prepayId, // 统一下单订单号
timestamp: timeStamp, // 时间戳(单位:秒)
sign: sign // 签名,这里用的 MD5 签名
};
} else if (this.checkAliPay) {
orderInfo = res.orderString;
}
uni.requestPayment({
provider: this.checkWexin ? 'wxpay' : 'alipay',
orderInfo: orderInfo,
success: function(res) {
uni.showModal({
title: '提示',
content: '支付成功',
showCancel: false,
success: ({ confirm, cancel }) => {
self.$go(`pages/pay/success?orderId=${self.orderId}`, {
type: 'redirectTo'
});
}
});
console.log('success:' + JSON.stringify(res));
},
fail: function(err) {
console.log('fail:' + JSON.stringify(err));
self.$go(`pages/pay/fail?orderId=${self.orderId}`, {
type: 'redirectTo'
});
}
});
});
},
上面代码核心就是从服务端获取支付信息,然后通过uni.requestPayment 唤起支付即可
uniapp hbuild配置
appid:
需要微信后台申请
ios Universal Links :
一个链接代表本app标识,hbuild可以自动生成,直接点击自动生成按钮
生成方式参考:
https://zh.uniapp.dcloud.io/api/plugins/universal-links.html
微信后台配置
应用签名就是应用包名的32位md5哈希值
参考文章
https://juejin.cn/post/6965038146773843976
安卓一个app唤另外一个app示例代码:https://developer.aliyun.com/article/12533
前端工程师、程序员
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
2017-06-17 php namespace use 研究