/** *Created by ZHJY on 2020/7/14. */ var payContainer = new Vue({ el:"#payContainer", data: { orderID:'', pageType:'',//页面跳转类型 1为二手 0为订单 payAmount:0,//本次支付金额 wechatcode:'',//微信code state:0,//随机数 isRequest:false, productId:'',//二手商品ID vipId: null, // vip套餐id vipRecordId: undefined }, computed: { }, methods: { infoPayOrderCheckoutCounter:function(){//初始化订单数据 var _this = this; _this.wechatcode = CAIMEI.getUrlParam('code'); _this.state = JSON.parse(decodeURIComponent(CAIMEI.getUrlParam('state'))); _this.payAmount = _this.state.payAmount; _this.pageType = _this.state.pageType; _this.isRequest = true; if( _this.pageType == 1){ _this.productId = _this.state.productId; }else if(_this.pageType == 2){ _this.vipId = _this.state.vipId; _this.vipRecordId = _this.state.vipRecordId; }else{ _this.orderID = _this.state.orderID; } }, WxPaySubmit:function(){ if (this.pageType == 1) { this.WxRequestsecondHandPay(); } else if (this.pageType == 2) { this.WxRequestPaymentVipFn(); } else { this.WxRequestPaymentFn(); } }, // 会员支付 WxRequestPaymentVipFn: function(){ var _this = this; var params = { code: _this.wechatcode, state: _this.rand(1000, 9999), vipId: _this.vipId, vipRecordId: _this.vipRecordId, returnUrl: 'https://www.caimei365.com/', }; PayApi.PayVipMiniWxPay(params,function(response){ if(response.code == 0){ var PayInfo = JSON.parse(response.data.data.payInfo); if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ _this.onBridgeReady(PayInfo); } }else{ CAIMEI.dialog("支付链接已失效,请重新扫码支付"); setTimeout(function(){ WeixinJSBridge.call('closeWindow'); },3000); } }); }, WxRequestsecondHandPay:function(){ // 二手商品支付 var _this = this; var params = { code: _this.wechatcode, state: _this.rand(1000, 9999), productId: _this.productId, returnUrl: 'https://www.caimei365.com/', }; PayApi.PayOrdersecondWechat(params,function(response){ if(response.code == 0){ var PayInfo = JSON.parse(response.data.data.payInfo); if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ _this.onBridgeReady(PayInfo); } }else{ CAIMEI.dialog("支付链接已失效,请重新扫码支付"); setTimeout(function(){ WeixinJSBridge.call('closeWindow'); },3000); } }); }, WxRequestPaymentFn:function(){ // 普通订单支付 var _this = this; var params={ payAmount:Math.round(_this.payAmount*100), code:_this.wechatcode, state:_this.rand(1000,9999), orderId:_this.orderID, returnUrl:'https://www.caimei365.com/', }; PayApi.PayOrderMiniWxPay(params,function(response){ if(response.code == 0){ var PayInfo = JSON.parse(response.data.data.payInfo); if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ _this.onBridgeReady(PayInfo); } }else{ CAIMEI.dialog('支付链接已失效,请重新扫码支付'); setTimeout(function(){ WeixinJSBridge.call('closeWindow'); },3000); } }) }, onBridgeReady:function(data){ console.log('支付验证签名',data); WeixinJSBridge.invoke('getBrandWCPayRequest', { "appId":data.appId, //公众号名称,由商户传入 "timeStamp":data.timeStamp,//时间戳,自1970年以来的秒数 "nonceStr":data.nonceStr, //随机串 "package":data.package, "signType":data.signType, //微信签名方式: "paySign":data.paySign, //微信签名 }, function(res) { if(res.err_msg == "get_brand_wcpay_request:ok"){ CAIMEI.dialog('支付成功'); window.open("https://www.caimei365.com/"); }else if(res.err_msg == "get_brand_wcpay_request:cancel"){ CAIMEI.dialog("用户取消支付,请重新扫码支付"); setTimeout(function(){ WeixinJSBridge.call('closeWindow'); },3000); }else{ CAIMEI.dialog("支付失败,请重新扫码支付"); setTimeout(function(){ WeixinJSBridge.call('closeWindow'); },3000); } }); }, rand:function (min,max) {//随机数 return Math.floor(Math.random()*(max-min))+min; }, toFixedFn:function(text){//处理小数点后两位数 return Number(text).toFixed(2); }, }, mounted: function () { var _this = this; _this.infoPayOrderCheckoutCounter(); } });