From a9639de3231a8c994b92ad98b7938f1c8d23e8ad Mon Sep 17 00:00:00 2001 From: hflllll Date: Thu, 9 Oct 2025 21:21:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8F=90=E7=8E=B0):=20=E5=A2=9E=E5=8A=A0H?= =?UTF-8?q?5=E7=8E=AF=E5=A2=83=E4=B8=8B=E7=9A=84=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8F=90=E7=8E=B0=E5=8A=9F=E8=83=BD=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在H5环境下使用jWeixin和WeixinJSBridge实现微信提现功能,同时保持原有小程序提现逻辑不变。新增H5环境检测和专门的提现处理方法,确保在不同平台都能正常使用提现功能。 --- main.js | 4 ++ subPages/user/promote.vue | 100 ++++++++++++++++++++++++++++++++++++++++++++++ utils/common.js | 2 + 3 files changed, 106 insertions(+) diff --git a/main.js b/main.js index d128259..f5e53f4 100644 --- a/main.js +++ b/main.js @@ -23,6 +23,10 @@ Vue.mixin(MixinConfig) Vue.prototype.$api = api Vue.prototype.$utils = utils Vue.prototype.$config = config // 这里是静态config +// #ifdef H5 +import jWeixin from '@/utils/lib/jweixin-module.js' +Vue.prototype.$jWeixin = jWeixin // 这里偷偷挂载 +// #endif App.mpType = 'app' const app = new Vue({ diff --git a/subPages/user/promote.vue b/subPages/user/promote.vue index 9a0d985..08c5b5f 100644 --- a/subPages/user/promote.vue +++ b/subPages/user/promote.vue @@ -199,6 +199,33 @@ export default { return } // 提现 + + // #ifdef H5 + // H5环境下检查微信环境 + if (!this.isInWechat()) { + uni.showToast({ + title: '请在微信中打开', + icon: 'none' + }) + return + } + + // H5环境下使用专门的H5提现方法 + this.requestMerchantTransferH5(item.packageInfo, async () => { + const withdrawRes = await this.$api.promotion.withdrawSuccess({ + id : item.id + }) + if (withdrawRes.code === 200) { + uni.showToast({ + title: '提现成功', + icon: 'success' + }) + } + }) + return + // #endif + + // #ifdef MP-WEIXIN wx.requestMerchantTransfer({ mchId: '1724993508',// appId: wx.getAccountInfoSync().miniProgram.appId, @@ -223,7 +250,80 @@ export default { // this.getData() }, }); + // #endif + }, + + // #ifdef H5 + // H5环境下的微信收款确认 + requestMerchantTransferH5(packageInfo, callback) { + // 使用Vue原型上的jWeixin + const jWeixin = this.$jWeixin + if (!jWeixin) { + console.error('jWeixin未初始化') + uni.showToast({ + title: '微信环境异常', + icon: 'none' + }) + return + } + + jWeixin.ready(() => { + jWeixin.checkJsApi({ + jsApiList: ['requestMerchantTransfer'], + success: (res) => { + if (res.checkResult['requestMerchantTransfer']) { + // H5环境下使用WeixinJSBridge + if (typeof WeixinJSBridge !== 'undefined') { + WeixinJSBridge.invoke('requestMerchantTransfer', { + mchId: '1724993508', + appId: wx.getAccountInfoSync().miniProgram.appId, + package: packageInfo, + }, (res) => { + if (res.err_msg === 'requestMerchantTransfer:ok') { + + callback && callback() + } else { + console.log('提现失败:', res) + uni.showToast({ + title: '提现失败,请稍后再试', + icon: 'none' + }) + } + }) + } else { + console.error('WeixinJSBridge未找到') + uni.showToast({ + title: '请在微信中打开', + icon: 'none' + }) + } + } else { + uni.showToast({ + title: '你的微信版本过低,请更新至最新版本', + icon: 'none' + }) + } + }, + fail: (error) => { + console.error('checkJsApi失败:', error) + uni.showToast({ + title: '微信接口检查失败', + icon: 'none' + }) + } + }) + }) + + jWeixin.error((res) => { + console.error('微信配置失败:', res) + uni.showToast({ + title: '微信配置失败', + icon: 'none' + }) + }) }, + // #endif + // 去二维码 goQrcode() { uni.navigateTo({ diff --git a/utils/common.js b/utils/common.js index 67e1b18..df09fe2 100644 --- a/utils/common.js +++ b/utils/common.js @@ -165,6 +165,8 @@ const wxPay = (paymentData, successCallback, failCallback) => { // #endif } + + export { checkPhone, formatTime,