Browse Source

feat(提现): 增加H5环境下的微信提现功能支持

在H5环境下使用jWeixin和WeixinJSBridge实现微信提现功能,同时保持原有小程序提现逻辑不变。新增H5环境检测和专门的提现处理方法,确保在不同平台都能正常使用提现功能。
hfll
hflllll 2 weeks ago
parent
commit
a9639de323
3 changed files with 106 additions and 0 deletions
  1. +4
    -0
      main.js
  2. +100
    -0
      subPages/user/promote.vue
  3. +2
    -0
      utils/common.js

+ 4
- 0
main.js View File

@ -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({


+ 100
- 0
subPages/user/promote.vue View File

@ -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) {
// 使VuejWeixin
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({


+ 2
- 0
utils/common.js View File

@ -165,6 +165,8 @@ const wxPay = (paymentData, successCallback, failCallback) => {
// #endif
}
export {
checkPhone,
formatTime,


Loading…
Cancel
Save