hlb_wxMixin.js 4.1 KB

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