123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import authorize from '@/common/authorize.js'
- // 调用微信支付
- function wxRequestPayment(payData) {
- return new Promise((resolve, reject) => {
- uni.requestPayment({
- timeStamp: payData.timeStamp,
- nonceStr: payData.nonceStr,
- package: payData.package,
- signType: payData.signType,
- paySign: payData.paySign,
- success: () => {
- resolve(true)
- },
- fail: () => {
- reject({ msg: 'error' })
- }
- })
- })
- }
- // 微信支付
- const wechatCouponPay = {
- data() {
-
- },
- methods: {
- // 获取微信支付payment
- async weChatMiniWxPay(data) {
- try {
- // 获取微信code
- const wechatCode = await authorize.getCode('weixin')
- // 微信支付请求 返回支付信息
- const response = await this.PayService.WeChatCouponMiniWxPay({
- userId: this.listQuery.userId,
- couponId: coupon.couponId,
- payWay: 'WEIXIN',
- code: wechatcode
- })
- // 处理支付信息 调用微信支付
- const payment = JSON.parse(response.data.data.payInfo)
- const payFlag = await wxRequestPayment(payment)
- // debugger
- // console.log(this.hanldOrder)
- // 支付成功重定向
- uni.setStorageSync('orderInfo', this.hanldOrder.order)
- if (payFlag) {
- // 微信支付成功回调 在页面onload中通过this.$on监听orderPaySuccess事件回调
- uni.reLaunch({url: '/pages/tabBar/user/user'})
- } else {
- uni.reLaunch({ url: '/pages/order/error' })
- }
- } catch (error) {
- // 微信支付失败
- this.$util.msg(error.msg, 2000)
- }
- }
- }
- }
- export default {
- wechatCouponPay
- }
|