wechatPay.js 3.5 KB

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