payMixins.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. orderId:this.shopOrderInfo.orderId,
  41. type:'success'
  42. }
  43. uni.redirectTo({ url: `/pages/user/pay/success?data=${JSON.stringify({ data: linkData })}`})
  44. } else {
  45. // 微信支付失败
  46. this.$util.msg('支付失败~',2000)
  47. }
  48. } catch (error) {
  49. // 微信支付失败
  50. this.$util.msg('支付失败~',2000)
  51. }
  52. },
  53. // 微信支付优惠券
  54. async weChatMiniCouponWxPay(params,UmEvent,UmPageName,UmSourcePage,UmCouponId,UmUserId) {
  55. try {
  56. console.log('params',params)
  57. // 微信支付请求 返回支付信息
  58. const response = await this.PayService.WeChatCouponMiniWxPay(params)
  59. // 处理支付信息 调用微信支付
  60. const payment = JSON.parse(response.data.rt10_payInfo)
  61. // 友盟埋点收集微信支付
  62. if (process.env.NODE_ENV != 'development') {
  63. this.$uma.trackEvent(UmEvent, {
  64. Um_Key_PageName: UmPageName,
  65. Um_Key_SourcePage: UmSourcePage,
  66. Um_Key_CouponId: UmCouponId,
  67. Um_Key_userId: UmUserId
  68. })
  69. }
  70. const payFlag = await wxRequestPayment(payment)
  71. if (payFlag) {
  72. // 微信支付成功回调
  73. uni.reLaunch({url: '/pages/tabBar/user/user'})
  74. } else {
  75. this.$util.msg('支付失败~',2000)
  76. }
  77. } catch (error) {
  78. // 微信支付失败
  79. this.$util.msg('支付失败~',2000)
  80. }
  81. },
  82. // 微信支付超级会员
  83. async weChatMiniVipWxPay(params) {
  84. try {
  85. console.log('params',params)
  86. // 微信支付请求 返回支付信息
  87. const response = await this.PayService.PayOrderVipWechat(params)
  88. // 处理支付信息 调用微信支付
  89. const payment = JSON.parse(response.data.rt10_payInfo)
  90. console.log('payment',payment)
  91. const payFlag = await wxRequestPayment(payment)
  92. console.log('payFlag',this.payFlag)
  93. if (payFlag) {
  94. // 微信支付成功回调
  95. uni.reLaunch({url: '/pages/tabBar/user/user'})
  96. } else {
  97. this.$util.msg('支付失败~',2000)
  98. }
  99. } catch (error) {
  100. // 微信支付失败
  101. this.$util.msg('支付失败~',2000)
  102. }
  103. }
  104. }
  105. }
  106. export default payMixins