hlb_wxMixin.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. 'use strict';
  2. var hlbWechatMixin = function () {
  3. return {
  4. methods: {
  5. hlb_WxRequestPaymentFn:function(){ // 普通订单合利宝公众号支付
  6. var _this = this;
  7. _this.isSubMitStatus=true;
  8. var params={
  9. payType:'GZH',
  10. payAmount:parseFloat(_this.payAmount),
  11. code:_this.wechatcode,
  12. state:_this.rand(1000,9999),
  13. shopOrderId:_this.shopOrderId,
  14. returnUrl:'https://www.caimei365.com/',
  15. };
  16. console.log('=========>普通订单合利宝公众号支付',params)
  17. PayApi.PayOrderPcScanWxPay(params,function(response){
  18. _this.hlb_handlResponse(response)
  19. })
  20. },
  21. hlb_WxRequestPaymentVipFn: function(){ // 超级会员合利宝公众号支付
  22. var _this = this;
  23. _this.isSubMitStatus=true;
  24. var params = {
  25. payType:'GZH',
  26. code: _this.wechatcode,
  27. state: _this.rand(1000, 9999),
  28. vipId: _this.vipId,
  29. vipRecordId: _this.vipRecordId,
  30. returnUrl: 'https://www.caimei365.com/',
  31. };
  32. console.log('=========>超级会员合利宝公众号支付',params)
  33. PayApi.PayVipMiniWxPay(params,function(response){
  34. _this.hlb_handlResponse(response)
  35. });
  36. },
  37. hlb_WxRequestPaymentCouponFn: function(){// 优惠券合利宝公众号支付
  38. var _this = this;
  39. _this.isSubMitStatus=true;
  40. var params = {
  41. payType:'GZH',
  42. code: _this.wechatcode,
  43. state: _this.rand(1000, 9999),
  44. userId: _this.userId,
  45. couponId: _this.couponId,
  46. couponRecordId:_this.couponRecordId,
  47. returnUrl: 'https://www.caimei365.com/',
  48. source:2 //支付来源 1 小程序 2 WWW
  49. };
  50. console.log('=========>优惠券合利宝公众号支付',params)
  51. PayApi.PayCouponMiniWxPay(params,function(response){
  52. _this.hlb_handlResponse(response)
  53. });
  54. },
  55. hlb_WxRequestPaymentAuthVipFn: function(){// 认证通会员合利宝公众号支付
  56. var _this = this;
  57. _this.isSubMitStatus=true;
  58. var params = {
  59. payType:'GZH',
  60. code: _this.wechatcode,
  61. state: _this.rand(1000, 9999),
  62. vipId: _this.vipId,
  63. vipRecordId: _this.vipRecordId,
  64. returnUrl: 'https://www.caimei365.com/',
  65. };
  66. console.log('=========>认证通会员合利宝公众号支付',params)
  67. PayApi.PayAuthVipMiniWxPay(params,function(response){
  68. _this.hlb_handlResponse(response)
  69. });
  70. },
  71. hlb_WxRequestsecondHandPay:function(){ // 二手发布合利宝公众号支付
  72. var _this = this;
  73. _this.isSubMitStatus=true;
  74. var params = {
  75. payType:'GZH',
  76. code: _this.wechatcode,
  77. state: _this.rand(1000, 9999),
  78. productId: _this.productId,
  79. returnUrl: 'https://www.caimei365.com/',
  80. };
  81. console.log('=========>二手发布合利宝公众号支付',params)
  82. PayApi.PayOrdersecondWechat(params,function(response){
  83. _this.hlb_handlResponse(response)
  84. });
  85. },
  86. hlb_handlResponse:function (response) {
  87. var _this = this;
  88. if(response.code === 0){
  89. var PayInfo = JSON.parse(response.data.rt10_payInfo);
  90. if (typeof WeixinJSBridge == "undefined"){
  91. if( document.addEventListener ){
  92. document.addEventListener('WeixinJSBridgeReady', hlb_onBridgeReady, false);
  93. }else if (document.attachEvent){
  94. document.attachEvent('WeixinJSBridgeReady', hlb_onBridgeReady);
  95. document.attachEvent('onWeixinJSBridgeReady', hlb_onBridgeReady);
  96. }
  97. }else{
  98. _this.hlb_onBridgeReady(PayInfo);
  99. }
  100. _this.isSubMitStatus=false;
  101. }else{
  102. CAIMEI.dialog("支付链接已失效,请重新扫码支付");
  103. _this.isSubMitStatus=false;
  104. setTimeout(function(){
  105. WeixinJSBridge.call('closeWindow');
  106. },3000);
  107. }
  108. },
  109. hlb_onBridgeReady:function(data){// 调起微信公众号支付
  110. console.log('支付验证签名',data);
  111. WeixinJSBridge.invoke('getBrandWCPayRequest', {
  112. "appId":data.appId, //公众号名称,由商户传入
  113. "timeStamp":data.timeStamp,//时间戳,自1970年以来的秒数
  114. "nonceStr":data.nonceStr, //随机串
  115. "package":data.package,
  116. "signType":data.signType, //微信签名方式:
  117. "paySign":data.paySign, //微信签名
  118. },
  119. function(res) {
  120. if(res.err_msg == "get_brand_wcpay_request:ok"){
  121. CAIMEI.dialog('支付成功');
  122. window.open("https://www.caimei365.com/");
  123. }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
  124. CAIMEI.dialog("用户取消支付,请重新扫码支付");
  125. setTimeout(function(){
  126. WeixinJSBridge.call('closeWindow');
  127. },3000);
  128. }else{
  129. CAIMEI.dialog("支付失败,请重新扫码支付");
  130. setTimeout(function(){
  131. WeixinJSBridge.call('closeWindow');
  132. },3000);
  133. }
  134. });
  135. },
  136. }
  137. };
  138. }();