From c334155877549d803b6a0fa17b649abfd1178577 Mon Sep 17 00:00:00 2001 From: xiejianpeng Date: Thu, 14 Nov 2019 11:34:35 +0800 Subject: [PATCH] 格式化 --- js/pay.js | 381 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 200 insertions(+), 181 deletions(-) diff --git a/js/pay.js b/js/pay.js index f83149d..e536d1a 100644 --- a/js/pay.js +++ b/js/pay.js @@ -27,12 +27,12 @@ window.onload = function () { wx.onclick = webAppClass.wxClick; //$btnObj.onclick = webAppClass.okClick; - $btnObj.onclick = webAppClass.okPay; + $btnObj.onclick = webAppClass.okPay; document.getElementById("payTip").innerHTML = ""; //参数 webAppParams = getQueryString(window.location); - if (webAppParams!=null) { + if (webAppParams != null) { //设置UI参数 webAppClass.setUI(webAppParams); } else { @@ -50,111 +50,112 @@ window.onload = function () { /**/ var webAppClass = { //优惠券兑换 - codediscountClick:function(tmpObj){ - discountVal = document.getElementById("discountBox").value; - // console.log(discountVal) - // console.log(discountVal.length) - if(discountVal.length > 0){ - $btnObj.style.display = "none"; - $btnLoad.style.display = "block"; - $discountBtn.disabled = true - console.log(webAppParams.orderId) - var url = webAppRoot + window.webAppH5.discountServer; - var discountParams = { - app_id:'1', - salt:'1', - deviceInfo:'1', - sign_type:'1', - sign:'1', - token:'1', - terminalSource:7, - orderId:webAppParams.orderId, - cardNo:discountVal, - codeType:0 - } - postRequest(url, discountParams, function (res) { - console.log(res) - if(res.code==0){ - - document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100) - document.getElementById("discountTip").innerHTML = res.data.couponDescribe - document.getElementById("discountFee").innerHTML = (res.data.discountFee/100) - document.getElementById("discountDesc").style.display="none" - $btnLoad.style.display = "none"; - $btnObj.style.display = "block"; - flag = 1; - webAppClass.okPay(tmpObj);//唤醒支付 - }else{ - $btnLoad.style.display = "none"; - $btnObj.style.display = "block"; - $discountBtn.disabled = false; - document.getElementById("discountTip").innerHTML = res.message - } - }) + codediscountClick: function (tmpObj) { + discountVal = document.getElementById("discountBox").value; + // console.log(discountVal) + // console.log(discountVal.length) + if (discountVal.length > 0) { + $btnObj.style.display = "none"; + $btnLoad.style.display = "block"; + $discountBtn.disabled = true + console.log(webAppParams.orderId) + var url = webAppRoot + window.webAppH5.discountServer; + var discountParams = { + app_id: '1', + salt: '1', + deviceInfo: '1', + sign_type: '1', + sign: '1', + token: '1', + terminalSource: 7, + orderId: webAppParams.orderId, + cardNo: discountVal, + codeType: 0 + } + postRequest(url, discountParams, function (res) { + console.log(res) + if (res.code == 0) { + + document.getElementById("sumMoney").innerHTML = (res.data.orderFee / 100) + document.getElementById("discountTip").innerHTML = res.data.couponDescribe + document.getElementById("discountFee").innerHTML = (res.data.discountFee / 100) + document.getElementById("discountDesc").style.display = "none" + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + flag = 1; + webAppClass.okPay(tmpObj);//唤醒支付 + } else { + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + $discountBtn.disabled = false; + document.getElementById("discountTip").innerHTML = res.message + } + }) - }else{ - return - } - }, - discountClick: function(){ - discountVal = document.getElementById("discountBox").value; - // console.log(discountVal) - // console.log(discountVal.length) - if(discountVal.length > 0){ - $btnObj.style.display = "none"; - $btnLoad.style.display = "block"; - $discountBtn.disabled = true - // console.log(webAppParams.orderId); - if(webAppParams===null ||webAppParams==='null'||webAppParams===undefined){ - document.getElementById("discountTip").innerHTML = '缺少参数'; - $btnLoad.style.display = "none"; - $btnObj.style.display = "block"; - return false; - } - var url = webAppRoot + window.webAppH5.discountServer; - var discountParams = { - app_id:'1', - salt:'1', - deviceInfo:'1', - sign_type:'1', - sign:'1', - token:'1', - terminalSource:7, - orderId:webAppParams.orderId, - cardNo:discountVal, - codeType:0 + } else { + return } - postRequest(url, discountParams, function (res) { - console.log(res) - if(res.code==0){ - - document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100) - document.getElementById("discountTip").innerHTML = res.data.couponDescribe - document.getElementById("discountFee").innerHTML = (res.data.discountFee/100) - document.getElementById("discountDesc").style.display="none" + }, + discountClick: function () { + discountVal = document.getElementById("discountBox").value; + // console.log(discountVal) + // console.log(discountVal.length) + if (discountVal.length > 0) { + $btnObj.style.display = "none"; + $btnLoad.style.display = "block"; + $discountBtn.disabled = true + // console.log(webAppParams.orderId); + if (webAppParams === null || webAppParams === 'null' || webAppParams === undefined) { + document.getElementById("discountTip").innerHTML = '缺少参数'; + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + return false; + } + var url = webAppRoot + window.webAppH5.discountServer; + var discountParams = { + app_id: '1', + salt: '1', + deviceInfo: '1', + sign_type: '1', + sign: '1', + token: '1', + terminalSource: 7, + orderId: webAppParams.orderId, + cardNo: discountVal, + codeType: 0 + } + postRequest(url, discountParams, function (res) { + console.log(res) + if (res.code == 0) { + + document.getElementById("sumMoney").innerHTML = (res.data.orderFee / 100) + document.getElementById("discountTip").innerHTML = res.data.couponDescribe + document.getElementById("discountFee").innerHTML = (res.data.discountFee / 100) + document.getElementById("discountDesc").style.display = "none" + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + document.getElementById("discountBox").setAttribute('readonly', 'readonly'); + flag = 1 + } else { + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + $discountBtn.disabled = false; + document.getElementById("discountTip").innerHTML = res.message + } + }) + + } else { $btnLoad.style.display = "none"; $btnObj.style.display = "block"; - document.getElementById("discountBox").setAttribute('readonly','readonly'); - flag = 1 - }else{ - $btnLoad.style.display = "none"; - $btnObj.style.display = "block"; - $discountBtn.disabled = false; - document.getElementById("discountTip").innerHTML = res.message - } - }) - - }else{ - $btnLoad.style.display = "none"; - $btnObj.style.display = "block"; - return false; - } + return false; + } }, //OK okClick: function (ev) { document.getElementById("payTip").innerHTML = ""; if (webAppParams == null) { - alertMsg("暂无订单信息");return; + alertMsg("暂无订单信息"); + return; } //先校验停车费用后缴费提交 webAppClass.checkParkCost(); @@ -163,7 +164,7 @@ var webAppClass = { checkParkCost: function () { $btnObj.style.display = "none"; $btnLoad.style.display = "block"; - if (typeof(webAppParams.queryOrderInfo) == "undefined") {//没有queryOrderInfo返回第一页 + if (typeof (webAppParams.queryOrderInfo) == "undefined") {//没有queryOrderInfo返回第一页 window.history.back(-1); } var tmpParams = JSON.parse(webAppParams.queryOrderInfo); @@ -174,23 +175,24 @@ var webAppClass = { if (res.code == 0) {//进场 var tmpObj = res.data; if (tmpObj) { - if(flag == 1){ - webAppClass.codediscountClick(tmpObj); - }else{ - webAppClass.setUI(tmpObj); - webAppParams = tmpObj;//重新赋值 - webAppClass.okPay(tmpObj);//唤醒支付 + if (flag == 1) { + webAppClass.codediscountClick(tmpObj); + } else { + webAppClass.setUI(tmpObj); + webAppParams = tmpObj;//重新赋值 + webAppClass.okPay(tmpObj);//唤醒支付 } - console.log(tmpObj) - // webAppClass.okPay(tmpObj);//唤醒支付 + console.log(tmpObj) + // webAppClass.okPay(tmpObj);//唤醒支付 } else { alertMsg("没有找到相应订单"); } } else {//其他情况如【该卡号场内已存在】 $btnLoad.style.display = "none"; $btnObj.style.display = "block"; - console.log(res.message); alertMsg(res.message); + console.log(res.message); + alertMsg(res.message); } }, function (err) { console.log("网络服务超时..." + url); @@ -204,18 +206,22 @@ var webAppClass = { //确定支付 okPay: function (params) { var orderID = webAppParams.orderId;//订单号 - // alert(orderID) + // alert(orderID) //var moneyID = document.getElementById("sumMoney").innerHTML = webAppParams.orderId;//订单号 var val = document.getElementById("sumMoney").innerText; //var couponPersonId = document.getElementById("discountBox").value; var url = webAppRoot + window.webAppH5.zeroPayServer; - var _paySrcType = getQueryString(window.location)._paySrcType + var _paySrcType = getQueryString(window.location)._paySrcType var _mon = document.getElementById("sumMoney").innerText var discountParams = { - payOrderType : _paySrcType, - recordArreaInfos:JSON.stringify([{"orderId":webAppParams.orderId,"orderNotPayFee":_mon*100,"parkId":getQueryString(window.location).parkCode}]), - terminalSource:7, + payOrderType: _paySrcType, + recordArreaInfos: JSON.stringify([{ + "orderId": webAppParams.orderId, + "orderNotPayFee": _mon * 100, + "parkId": getQueryString(window.location).parkCode + }]), + terminalSource: 7, orderId: webAppParams.orderId, //couponPersonId:couponPersonId, app_id: '123', @@ -224,10 +230,10 @@ var webAppClass = { deviceInfo: '123', sign: '123', } - if(val == '0.00' || val=='0'){ + if (val == '0.00' || val == '0') { postRequest(url, discountParams, function (res) { console.log(res) - if(res.code==0){ + if (res.code == 0) { document.getElementById("paySuccess").style.display = 'block' // // document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100) @@ -238,13 +244,13 @@ var webAppClass = { // $btnObj.style.display = "block"; // document.getElementById("discountBox").setAttribute('readonly','readonly'); // flag = 1 - }else{ + } else { alert(res.message) // $discountBtn.disabled = false // document.getElementById("discountTip").innerHTML = res.message } }) - }else { + } else { var root = webAppRoot; //第一首先判断当前哪种浏览器方式[微信内置、支付宝内置、第三方浏览器] var clientType = clientBrowserEx(); @@ -259,24 +265,22 @@ var webAppClass = { //debugger; - - - // //新增start - // - // var url = " https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx20161110163838f231619da20804912345&package=1037687096"; - // //window.location.href = url; - // var wxPay = webAppH5.wxPayServer; - // var wxParams = webAppH5.comParams; - // wxParams.carNumber = getQueryString(window.location).carnum; - // wxParams.orderId = orderID; - // wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 - // wxParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 - // - // wxParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 - // - // wxParams.recordArreaInfos= JSON.stringify([{"orderId":webAppParams.orderId,"orderNotPayFee":_mon*100,"parkId":getQueryString(window.location).parkCode}]); - // - // //新增end + // //新增start + // + // var url = " https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx20161110163838f231619da20804912345&package=1037687096"; + // //window.location.href = url; + // var wxPay = webAppH5.wxPayServer; + // var wxParams = webAppH5.comParams; + // wxParams.carNumber = getQueryString(window.location).carnum; + // wxParams.orderId = orderID; + // wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 + // wxParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 + // + // wxParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 + // + // wxParams.recordArreaInfos= JSON.stringify([{"orderId":webAppParams.orderId,"orderNotPayFee":_mon*100,"parkId":getQueryString(window.location).parkCode}]); + // + // //新增end // if (webAppCode == null || webAppCode == "") {//code检测 // alertMsg(appState.codeNullTip); @@ -300,7 +304,11 @@ var webAppClass = { aliParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 aliParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 - aliParams.recordArreaInfos= JSON.stringify([{"orderId":webAppParams.orderId,"orderNotPayFee":_mon*100,"parkId":getQueryString(window.location).parkCode}]); + aliParams.recordArreaInfos = JSON.stringify([{ + "orderId": webAppParams.orderId, + "orderNotPayFee": _mon * 100, + "parkId": getQueryString(window.location).parkCode + }]); webAppClass.payAliAjax(root + aliPay, aliParams); break; default://第三方浏览器other @@ -313,12 +321,16 @@ var webAppClass = { var aliPay = webAppH5.aliPayServer; var aliParams = webAppH5.comParams; aliParams.orderId = orderID; - aliParams.carNumber = getQueryString(window.location).carnum; + aliParams.carNumber = getQueryString(window.location).carnum; aliParams.payType = 1;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 aliParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 - aliParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 + aliParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 - aliParams.recordArreaInfos= JSON.stringify([{"orderId":webAppParams.orderId,"orderNotPayFee":_mon*100,"parkId":getQueryString(window.location).parkCode}]); + aliParams.recordArreaInfos = JSON.stringify([{ + "orderId": webAppParams.orderId, + "orderNotPayFee": _mon * 100, + "parkId": getQueryString(window.location).parkCode + }]); webAppClass.payAliAjax(root + aliPay, aliParams); } else {//微信页面支付 @@ -331,9 +343,13 @@ var webAppClass = { wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 wxParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 - wxParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 + wxParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 - wxParams.recordArreaInfos= JSON.stringify([{"orderId":webAppParams.orderId,"orderNotPayFee":_mon*100,"parkId":getQueryString(window.location).parkCode}]); + wxParams.recordArreaInfos = JSON.stringify([{ + "orderId": webAppParams.orderId, + "orderNotPayFee": _mon * 100, + "parkId": getQueryString(window.location).parkCode + }]); webAppClass.payAjax(root + wxPay, wxParams); console.log("wxPay"); } @@ -428,7 +444,7 @@ var webAppClass = { //alertMsg("出场成功"); if (res.data) { var tmpObj = res.data; - if (typeof (tmpObj.mwebUrl)!="undefined") { + if (typeof (tmpObj.mwebUrl) != "undefined") { window.location.href = tmpObj.mwebUrl + "&redirect_url=" + webAppPayResult; } else { alertMsg("没有返回支付地址mwebUrl"); @@ -452,7 +468,7 @@ var webAppClass = { payAjaxJDK: function (orderID) { var btnOBj = $btnObj; //0:页面初始化获取code[webAppCode] - var codeParams = { code: webAppCode, appId: appWxID }; + var codeParams = {code: webAppCode, appId: appWxID}; var openIdUrl = webAppRoot + window.webAppH5.wxGetOpenIdServer; //1:有code获取OpenId @@ -461,15 +477,13 @@ var webAppClass = { if (res.code == 0) { //alert(res.data); webAppClass.getPayParams(res.data, orderID); - } - else if (res.code == 40163) {//code been used, hints[重复code问题] + } else if (res.code == 40163) {//code been used, hints[重复code问题] alertMsg(appState.codeNullTip); console.log(res.message); $btnObj.style.display = "block"; $btnLoad.style.display = "none"; - } - else { + } else { alertMsg(res.message); $btnObj.style.display = "block"; $btnLoad.style.display = "none"; @@ -494,16 +508,20 @@ var webAppClass = { //webAppClass.payAjax(root + wxPay, wxParams); - //新增start + //新增start - wxParams.carNumber = getQueryString(window.location).carnum; + wxParams.carNumber = getQueryString(window.location).carnum; - wxParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 + wxParams.paySrcType = getQueryString(window.location)._paySrcType;//101停车支付 - wxParams.recordArreaInfos= JSON.stringify([{"orderId":webAppParams.orderId,"orderNotPayFee":_mon*100,"parkId":getQueryString(window.location).parkCode}]); + wxParams.recordArreaInfos = JSON.stringify([{ + "orderId": webAppParams.orderId, + "orderNotPayFee": _mon * 100, + "parkId": getQueryString(window.location).parkCode + }]); - //新增end + //新增end wxParams.openId = openId; @@ -511,10 +529,10 @@ var webAppClass = { var payParamsUrl = webAppRoot + window.webAppH5.wxPayServer; alert('调接口之前') alert(payParamsUrl) - alert(JSON.stringify(wxParams)) + alert(JSON.stringify(wxParams)) //alert(payParamsUrl);alert(orderID); postRequest(payParamsUrl, wxParams, function (res) { - alert('走了微信支付接口') + alert('走了微信支付接口') $btnObj.style.display = "block"; $btnLoad.style.display = "none"; //debugger; @@ -531,7 +549,8 @@ var webAppClass = { } else { $btnLoad.style.display = "none"; $btnObj.style.display = "block"; - console.log(res.message); alertMsg(res.message); + console.log(res.message); + alertMsg(res.message); } }, function (err) { console.log("网络地址出错..."); @@ -546,30 +565,29 @@ var webAppClass = { function onBridgeReady() { WeixinJSBridge.invoke( 'getBrandWCPayRequest', params, - //'getBrandWCPayRequest', { - // "appId": appWxID, //公众号名称,由商户传入 - // "timeStamp": "1395712654", //时间戳,自1970年以来的秒数 - // "nonceStr": "e61463f8efa94090b1f366cccfbbb444", //随机串 - // "package": "prepay_id=u802345jgfjsdfgsdg888", - // "signType": "MD5", //微信签名方式: - // "paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 - //}, - function (res) { - //alert(res.err_msg); - if (res.err_msg == "get_brand_wcpay_request:ok") { - // 使用以上方式判断前端返回,微信团队郑重提示: - //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 - window.location.href = webAppPayResult+"?trade_no=" + "success"; - } - else if (res.err_msg == 'get_brand_wcpay_request:cancel') { - window.location.href = webAppPayResult + "?trade_no=" + "fail"; - } - else { - alertMsg(JSON.stringify(res)); - //alert(res.err_msg); - } - }); + //'getBrandWCPayRequest', { + // "appId": appWxID, //公众号名称,由商户传入 + // "timeStamp": "1395712654", //时间戳,自1970年以来的秒数 + // "nonceStr": "e61463f8efa94090b1f366cccfbbb444", //随机串 + // "package": "prepay_id=u802345jgfjsdfgsdg888", + // "signType": "MD5", //微信签名方式: + // "paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 + //}, + function (res) { + //alert(res.err_msg); + if (res.err_msg == "get_brand_wcpay_request:ok") { + // 使用以上方式判断前端返回,微信团队郑重提示: + //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 + window.location.href = webAppPayResult + "?trade_no=" + "success"; + } else if (res.err_msg == 'get_brand_wcpay_request:cancel') { + window.location.href = webAppPayResult + "?trade_no=" + "fail"; + } else { + alertMsg(JSON.stringify(res)); + //alert(res.err_msg); + } + }); } + if (typeof WeixinJSBridge == "undefined") { if (document.addEventListener) { document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); @@ -595,7 +613,8 @@ var webAppClass = { alertMsg(res.message); } }, function (err) { - console.log("网络地址出错...");alertMsg("网络地址出错..."); + console.log("网络地址出错..."); + alertMsg("网络地址出错..."); $btnLoad.style.display = "none"; btnOBj.style.display = "block"; }); @@ -619,7 +638,7 @@ var webAppClass = { $discountDesc = getObjectByID("discountDesc"),//8折优惠折扣费用 $discountFee = getObjectByID("discountFee");//优惠金额 - if (params != null && params!="") { + if (params != null && params != "") { var price = keepTwoDecimalFull((params.orderFee / 100));//(params.orderFee / 100); $carNum.innerHTML = params.carnum;//手机号 $orderNum.innerHTML = params.orderId;//订单号 @@ -633,7 +652,7 @@ var webAppClass = { $staytime.innerHTML = formatSeconds(params.staytime); $due.innerHTML = keepTwoDecimalFull((params.due / 100));//停车总费用 - $paid.innerHTML = keepTwoDecimalFull(params.paid/100); + $paid.innerHTML = keepTwoDecimalFull(params.paid / 100); $discountFee.innerHTML = params.discountFee;//优惠金额 // $discountDesc.innerHTML = params.discountDesc; } else { -- libgit2 0.21.4