payMixins.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import authorize from '@/common/config/authorize.js'
  2. // 调用微信支付
  3. function wxRequestPayment(payData) {
  4. return new Promise((resolve, reject) => {
  5. uni.requestPayment({
  6. timeStamp: payData.timeStamp,
  7. nonceStr: payData.nonceStr,
  8. package: payData.package,
  9. signType: payData.signType,
  10. paySign: payData.paySign,
  11. success: () => {
  12. resolve(true)
  13. },
  14. fail: () => {
  15. reject({ msg: 'error' })
  16. }
  17. })
  18. })
  19. }
  20. // 微信支付
  21. const payMixins = {
  22. data() {
  23. },
  24. methods: {
  25. // 微信支付正常订单
  26. async weChatMiniOrderWxPay(params) {
  27. try {
  28. // 微信支付请求 返回支付信息
  29. const response = await this.PayService.WeChatScanMiniWxPay(params)
  30. // 处理支付信息 调用微信支付
  31. const payment = JSON.parse(response.data.rt10_payInfo)
  32. console.log('payment',payment)
  33. const payFlag = await wxRequestPayment(payment)
  34. console.log('payFlag',payFlag)
  35. uni.setStorageSync('shopOrderInfo', this.shopOrderInfo)
  36. if (payFlag) {
  37. // 微信支付成功回调
  38. let linkData = {
  39. payAmount:this.payAmount,
  40. shopOrderId:this.shopOrderInfo.shopOrderId,
  41. orderId:this.shopOrderInfo.orderId,
  42. type:'success'
  43. }
  44. uni.redirectTo({ url: `/pages/user/order/order-success?data=${JSON.stringify({ data: linkData })}`})
  45. } else {
  46. // 微信支付失败
  47. this.$util.msg('支付失败~',2000)
  48. }
  49. } catch (error) {
  50. // 微信支付失败
  51. this.$util.msg('支付失败~',2000)
  52. }
  53. },
  54. // 微信支付优惠券
  55. async weChatMiniCouponWxPay(params,UmEvent,UmPageName,UmSourcePage,UmCouponId,UmUserId) {
  56. try {
  57. console.log('params',params)
  58. // 微信支付请求 返回支付信息
  59. const response = await this.PayService.WeChatCouponMiniWxPay(params)
  60. // 处理支付信息 调用微信支付
  61. const payment = JSON.parse(response.data.rt10_payInfo)
  62. // 友盟埋点收集微信支付
  63. if (process.env.NODE_ENV != 'development') {
  64. this.$uma.trackEvent(UmEvent, {
  65. Um_Key_PageName: UmPageName,
  66. Um_Key_SourcePage: UmSourcePage,
  67. Um_Key_CouponId: UmCouponId,
  68. Um_Key_userId: UmUserId
  69. })
  70. }
  71. const payFlag = await wxRequestPayment(payment)
  72. if (payFlag) {
  73. // 微信支付成功回调
  74. uni.reLaunch({url: '/pages/tabBar/user/user'})
  75. } else {
  76. this.$util.msg('支付失败~',2000)
  77. }
  78. } catch (error) {
  79. // 微信支付失败
  80. this.$util.msg('支付失败~',2000)
  81. }
  82. },
  83. // 微信支付超级会员
  84. async weChatMiniVipWxPay(params) {
  85. try {
  86. console.log('params',params)
  87. // 微信支付请求 返回支付信息
  88. const response = await this.PayService.PayOrderVipWechat(params)
  89. // 处理支付信息 调用微信支付
  90. const payment = JSON.parse(response.data.rt10_payInfo)
  91. console.log('payment',payment)
  92. const payFlag = await wxRequestPayment(payment)
  93. console.log('payFlag',this.payFlag)
  94. if (payFlag) {
  95. // 微信支付成功回调
  96. uni.reLaunch({url: '/pages/tabBar/user/user'})
  97. } else {
  98. this.$util.msg('支付失败~',2000)
  99. }
  100. } catch (error) {
  101. // 微信支付失败
  102. this.$util.msg('支付失败~',2000)
  103. }
  104. }
  105. }
  106. }
  107. export default payMixins