feat: 新增华为支付SDK调起逻辑,微信小程序、H5、华为快应用均已适配,并完成测试验证

This commit is contained in:
Zhukj
2025-12-11 08:55:07 +08:00
parent f1c01833e4
commit b633125cc3
2 changed files with 190 additions and 31 deletions

View File

@@ -56,7 +56,7 @@ import {
} from 'common/js/wx-jssdk.js';
// #endif
// 引入统一支付工具类
// 引入统一支付工具类(真实调用)
import { invokeWechatPay, invokeAlipay, invokeHuaweiPay } from '../../common/js/payCore.js';
export default {
@@ -76,32 +76,36 @@ export default {
return {
payIndex: 0,
payTypeList: [
// #ifdef H5 || MP-ALIPAY
{
name: '支付宝支付',
icon: 'icon-zhifubaozhifu-',
type: 'alipay'
},
// #endif
// #ifdef H5 || MP-WEIXIN
{
name: '微信支付',
icon: 'icon-weixin1',
type: 'wechatpay'
type: 'wechatpay',
description: '推荐微信用户使用'
},
{
name: '支付宝支付',
icon: 'icon-zhifubaozhifu-',
type: 'alipay',
description: '推荐支付宝用户使用'
},
// #endif
// #ifdef H5 || QUICKAPP-HUAWEI
{
name: '华为支付',
icon: 'icon-zhekou',
type: 'huaweipay'
icon: 'icon-huawei-pay',
type: 'huaweipay',
description: '华为用户专属支付'
},
// #endif
{
name: '线下支付',
icon: 'icondiy icon-yuezhifu',
type: 'offlinepay'
type: 'offlinepay',
description: '到店支付或银行转账'
},
{
name: '余额支付',
icon: 'icon-balance',
type: 'balancepay',
description: '使用账户余额支付'
}
],
// #ifdef H5
timer: null,
@@ -270,12 +274,12 @@ export default {
return;
}
// 使用统一支付工具类进行支付
// 使用统一支付工具类进行真实支付调用
this.invokeUnifiedPay(payType.type);
},
/**
* 统一支付调用方法(使用新的支付工具类
* 统一支付调用方法(恢复真实后端调用
*/
async invokeUnifiedPay(payType) {
try {
@@ -284,7 +288,7 @@ export default {
const outTradeNo = this.payInfo.out_trade_no;
const subject = '订单支付';
// 根据支付类型调用对应的支付方法
// 恢复真实支付方法调用(对接后端)
switch (payType) {
case 'wechatpay':
payResult = await invokeWechatPay(outTradeNo, amount, subject);
@@ -299,24 +303,38 @@ export default {
throw new Error('不支持的支付方式');
}
// 处理H5支付跳转
// 验证支付结果
if (!payResult) {
throw new Error('支付结果为空');
}
if (typeof payResult.code === 'undefined') {
throw new Error('缺少code属性');
}
// 真实调起逻辑
if (payResult.code === 0 && payResult.data?.payUrl) {
// H5端直接跳转其他端需要在WebView中显示
// 关闭支付中弹窗
uni.hideLoading();
const systemInfo = uni.getSystemInfoSync();
// H5端直接跳转
if (systemInfo.platform === 'web') {
window.location.href = payResult.data.payUrl;
this.checkPayStatus();
} else {
// 微信小程序/华为快应用中显示WebView
// 小程序/快应用WebView
this.showPayWebView(payResult.data.payUrl);
}
} else if (payResult.code === 0) {
// 原生支付成功
// 关闭支付中弹窗
uni.hideLoading();
this.paySuccess();
} else {
throw new Error(payResult.msg || '支付失败');
}
} catch (error) {
// 关闭支付中弹窗
uni.hideLoading();
this.repeatFlag = false;
this.$util.showToast({
title: error.message || '支付失败'
@@ -325,11 +343,9 @@ export default {
},
/**
* 显示支付WebView用于微信小程序/华为快应用的H5支付
* 显示支付WebView真实跳转逻辑
*/
showPayWebView(payUrl) {
// 这里可以打开一个新的WebView页面来显示支付
// 或者使用现有的跳转逻辑
this.$util.redirectTo('/pages/Pay/Pay', {
payUrl: payUrl,
outTradeNo: this.payInfo.out_trade_no
@@ -378,12 +394,12 @@ export default {
return;
}
// 小程序端也使用统一支付工具类
// 小程序端真实调用统一支付工具类
this.invokeUnifiedPay(payType.type);
},
// #endif
/**
* 支付成功之后跳转
* 支付成功之后跳转(真实业务逻辑)
*/
paySuccess() {
if (this.payInfo.event == 'BlindboxGoodsOrderPayNotify') {
@@ -400,7 +416,7 @@ export default {
}
},
/**
* 重置支付单据
* 重置支付单据(真实业务逻辑)
*/
resetpay() {
this.resetPayComplete = false;
@@ -527,8 +543,9 @@ export default {
.icon-zhifubaozhifu- {
color: #00a0e9;
}
.icon-huawei-pay {
color: #c7000b; // 华为支付品牌色
}
.icon-checkboxblank {
font-size: 40rpx;