From 36f8a9b2cca6e0cfc17796bffb10480ac203f655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=84=86=E7=9A=AE=E9=B8=AD?= <1003092440@qq.com> Date: Wed, 23 Aug 2023 21:42:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jtools/pay/index.js | 165 ++++++++++++++++++ .../questionBank/components/Question.vue | 9 +- src/pages/questionBank/exclusiveExercise.vue | 4 +- src/pages/questionBank/questionBank.vue | 16 +- 4 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 src/jtools/pay/index.js diff --git a/src/jtools/pay/index.js b/src/jtools/pay/index.js new file mode 100644 index 0000000..be3afa3 --- /dev/null +++ b/src/jtools/pay/index.js @@ -0,0 +1,165 @@ +import request from '../request/index.js'; +// #ifdef H5 +import wxsdk from '@/jtools/wechat/sdk' +// #endif +import wechat from '@/jtools/wechat/wechat' +import $platform from '@/jtools/platform'; + +/** + * 支付 + * + * @param {String} payment = ['wechat','alipay','wallet'] - 支付方式 + * @param {Object} order = {} - 订单详情 + * @param {String} orderType = ['goods','recharge'] - 订单类型 + */ + +export default class JtoolsPay { + + + // wxOfficialAccount wxMiniProgram App H5 + // wechat 公众号JSSDK支付 小程序支付 微信开放平台支付 H5网页支付 + // alipay 复制网址 复制网址 支付宝开放平台支付 直接跳转链接 + // wallet v v v v + + + constructor(payment, order, orderType) { + this.payment = payment; + this.order = order; + this.orderType = orderType; + this.platform = $platform.get(); + let payMehod = this.getPayMethod(); + payMehod(); + + } + + getPayMethod() { + var payMethod = { + 'wxMiniProgram': { + 'wechat': () => { + this.wxMiniProgramPay() + }, + }, + 'App': { + 'wechat': () => { + this.wechatPay() + }, + 'alipay': () => { + this.aliPay() + }, + }, + } + return payMethod[this.platform][this.payment]; + } + + + + // 预支付 + prepay() { + let that = this; + return new Promise((resolve, reject) => { + const p = $platform.device() + const tradeInfoType = p == 'android' ? 'Android' : p == 'ios' ? 'iOS' : 'Wap' + let params = { + orderId: this.order.orderId, + orderPayType: this.order.orderPayType, + money: this.order.money, + microServiceName: this.order.microServiceName, + prepayParamUrl: this.order.prepayParamUrl, + paymentType: 'weChatPay', + payType: 'JSAPI', + tradeInfoType: tradeInfoType, + tenantId: '-1', + clientType: 'miniWx' + } + if (uni.getStorageSync('openId')) { + params.openId = uni.getStorageSync('openId'); + } + request({ + url: 'driver-api/applet/pay/prepay', + method: 'POST', + param, + }).then(res => { + if (res.code == 'SUCCESS') { + resolve(res); + } + }) + }); + } + + + // 微信小程序支付 + async wxMiniProgramPay() { + let that = this; + let result = await this.prepay(); + const params = result.data.jsApiResult + uni.requestPayment({ + provider: 'wxpay', + ...{ + appId: params.appId, //公众号名称,由商户传入 + timeStamp: params.timestamp, //时间戳,自1970年以来的秒数 + nonceStr: params.nonceStr, //随机串 + package: `prepay_id=${params.prepay_id}`, + signType: params.signType, //微信签名方式: + paySign: params.paySign, //微信签名 + }, + success: res => { + that.payResult('success', result.data.orderPayNo) + }, + fail: err => { + console.log('支付取消或者失败:', err); + err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') + } + }); + } + + + + // 支付宝支付 + async aliPay() { + let that = this; + let result = await this.prepay(); + if (result.code === 1) { + uni.requestPayment({ + provider: 'alipay', + orderInfo: result.data.pay_data, //支付宝订单数据 + success: res => { + that.payResult('success') + }, + fail: err => { + console.log('支付取消或者失败:', err); + err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') + } + }); + } + } + + // 微信支付 + async wechatPay() { + let that = this; + let result = await this.prepay(); + if (result.code === 1) { + uni.requestPayment({ + provider: 'wxpay', + orderInfo: JSON.parse(result.data.pay_data), //微信订单数据(官方说是string。实测为object) + success: res => { + that.payResult('success') + }, + fail: err => { + err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') + console.log('支付取消或者失败:', err); + } + }); + } + } + + + // 支付结果跳转,success:成功,fail:失败 + payResult(resultType, orderPayNo) { + const that = this; + let path = '' + uni.navigateTo({ + url:path + }) + } + +} diff --git a/src/pages/questionBank/components/Question.vue b/src/pages/questionBank/components/Question.vue index d68574c..185cd26 100644 --- a/src/pages/questionBank/components/Question.vue +++ b/src/pages/questionBank/components/Question.vue @@ -43,7 +43,7 @@ - + 交卷 @@ -117,7 +117,7 @@ - + 交卷 @@ -508,8 +508,9 @@ export default { }, sectionChange(index) { this.tCurrent = index - this.getQuestionList() - this.renderSwiper(0) + // this.getQuestionList() + // this.renderSwiper(0) + this.$emit('changeTab',index) }, getQuestionList(val) { const arr = JSON.parse(val) diff --git a/src/pages/questionBank/exclusiveExercise.vue b/src/pages/questionBank/exclusiveExercise.vue index 760e76a..0da9802 100644 --- a/src/pages/questionBank/exclusiveExercise.vue +++ b/src/pages/questionBank/exclusiveExercise.vue @@ -30,8 +30,8 @@ 常见考点 - - + + {{index+1}} {{item.label}} diff --git a/src/pages/questionBank/questionBank.vue b/src/pages/questionBank/questionBank.vue index 73653e2..668d572 100644 --- a/src/pages/questionBank/questionBank.vue +++ b/src/pages/questionBank/questionBank.vue @@ -3,7 +3,7 @@ {{navTitle}} - + @@ -93,6 +93,20 @@ }, methods: { ...mapActions(useUserStore,['searchUserVip']), + changeTab(val){ + if(val==1){ + let list =JSON.parse(JSON.stringify(this.questionArr)) + list=list.map(item=>{ + return{ + ...item, + clickAnswer:item.trueAnswer + } + }) + this.$refs.question.getQuestionList(JSON.stringify(list)) + }else{ + this.$refs.question.getQuestionList(JSON.stringify(this.questionArr)) + } + }, rightClick() { console.log('返回'); },