From dbd86cb20e35fda390901d676d9dadec5741f124 Mon Sep 17 00:00:00 2001 From: chenbiao Date: Wed, 10 Apr 2019 21:38:52 +0800 Subject: [PATCH] add 0元支付功能 --- billCodePay.html | 15 ++++++++++++++- config.js | 3 +++ dynCodePay.html | 15 ++++++++++++++- js/billCodePay.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- js/dynCodePay.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- js/pay.js | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------ pay.html | 15 ++++++++++++++- 7 files changed, 218 insertions(+), 55 deletions(-) diff --git a/billCodePay.html b/billCodePay.html index 36d1c1a..8981eeb 100644 --- a/billCodePay.html +++ b/billCodePay.html @@ -68,6 +68,19 @@ font-size: 14px; color: #EB453B; } + .paySuccess{ + width: 100%; + height: 100%; + text-align: center; + line-height: 100px; + font-size: 20px; + color: #fff; + background: rgba(0,0,0,.7); + position: fixed; + top:0; + left: 0; + display: none; + } @@ -130,7 +143,7 @@
- +
支付成功,请立即离场
- +
支付成功,请立即离场
diff --git a/js/billCodePay.js b/js/billCodePay.js index 299092c..fcf2ba5 100644 --- a/js/billCodePay.js +++ b/js/billCodePay.js @@ -8,7 +8,11 @@ var $btnObj = null; var $btnLoad = null; var webAppCode = null;//如果是微信,先获取微信code var flag = 0; -window.onload = function () { +function trim(str) { + + return str.replace(/(^\s*)|(\s*$)/g, ""); +} + window.onload = function () { //var root = document.getElementById("root"); $btnObj = document.getElementById("btnPayOK"); $btnLoad = document.getElementById("loading"); @@ -130,7 +134,45 @@ var webAppClass = { //[方式二,倒计时支付] $btnObj.style.display = "none"; $btnLoad.style.display = "block"; - webAppClass.okPay(webAppParams);//唤醒支付 + var val = document.getElementById("sumMoney").innerText; + var couponPersonId = trim(document.getElementById("discountBox").value); + var url = webAppRoot + window.webAppH5.zeroPayServer; + var discountParams = { + payOrderType : 101, + terminalSource:7, + orderId: webAppParams.orderId, + couponPersonId:couponPersonId, + app_id: '123', + sign_type: '123', + salt: '123', + deviceInfo: '123', + sign: '123', + } + if(val == '0.00' || val=='0'){ + postRequest(url, discountParams, function (res) { + console.log(res) + if(res.code==0){ + document.getElementById("paySuccess").style.display = 'block' + // + // 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{ + alert(res.message) + // $discountBtn.disabled = false + // document.getElementById("discountTip").innerHTML = res.message + } + }) + }else{ + webAppClass.okPay(webAppParams);//唤醒支付 + } + + }, //优惠券兑换 codediscountClick:function(tmpObj){ diff --git a/js/dynCodePay.js b/js/dynCodePay.js index 56256b1..a9fbe65 100644 --- a/js/dynCodePay.js +++ b/js/dynCodePay.js @@ -9,6 +9,10 @@ var $btnObj = null; var $btnLoad = null; var webAppCode = null;//如果是微信,先获取微信code // var flag = 0; +function trim(str) { + + return str.replace(/(^\s*)|(\s*$)/g, ""); +} window.onload = function () { $btnObj = getObjectByID("btnPayOK"); $btnLoad = getObjectByID("loading"); @@ -108,8 +112,46 @@ var webAppClass = { if (webAppParams == null) { alertMsg("暂无订单信息");return; } - //支付方式判断 - webAppClass.okPay(webAppParams); + $btnObj.style.display = "none"; + $btnLoad.style.display = "block"; + var val = document.getElementById("sumMoney").innerText; + var couponPersonId = trim(document.getElementById("discountBox").value); + var url = webAppRoot + window.webAppH5.zeroPayServer; + var discountParams = { + payOrderType : 101, + terminalSource:7, + orderId: webAppParams.orderId, + couponPersonId:couponPersonId, + app_id: '123', + sign_type: '123', + salt: '123', + deviceInfo: '123', + sign: '123', + } + if(val == '0.00' || val=='0'){ + postRequest(url, discountParams, function (res) { + console.log(res) + if(res.code==0){ + document.getElementById("paySuccess").style.display = 'block' + // + // 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{ + alert(res.message) + // $discountBtn.disabled = false + // document.getElementById("discountTip").innerHTML = res.message + } + }) + }else{ + webAppClass.okPay(webAppParams);//唤醒支付 + } + }, //确定支付 diff --git a/js/pay.js b/js/pay.js index 73a2fd5..da12d97 100644 --- a/js/pay.js +++ b/js/pay.js @@ -202,43 +202,63 @@ var webAppClass = { okPay: function (params) { var orderID = params.orderId;//订单号 //var moneyID = document.getElementById("sumMoney").innerHTML = webAppParams.orderId;//订单号 - var root = webAppRoot; - //第一首先判断当前哪种浏览器方式[微信内置、支付宝内置、第三方浏览器] - var clientType = clientBrowserEx(); - //alert(clientType); - switch (clientType) { - case "wxPay"://微信[内置浏览器] - //var wxPay = webAppH5.wxPayServer; - //var wxParams = webAppH5.comParams; - //wxParams.orderId = orderID; - //wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 - //wxParams.terminalSource = 3;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 - //debugger; - if (webAppCode == null || webAppCode == "") {//code检测 - alertMsg(appState.codeNullTip); - $btnObj.style.display = "block"; - $btnLoad.style.display = "none"; - return; + var val = document.getElementById("sumMoney").innerText; + var couponPersonId = document.getElementById("discountBox").value; + var url = webAppRoot + window.webAppH5.zeroPayServer; + var discountParams = { + payOrderType : 101, + terminalSource:7, + orderId: webAppParams.orderId, + couponPersonId:couponPersonId, + app_id: '123', + sign_type: '123', + salt: '123', + deviceInfo: '123', + sign: '123', + } + if(val == '0.00' || val=='0'){ + postRequest(url, discountParams, function (res) { + console.log(res) + if(res.code==0){ + document.getElementById("paySuccess").style.display = 'block' + // + // 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{ + alert(res.message) + // $discountBtn.disabled = false + // document.getElementById("discountTip").innerHTML = res.message } - webAppClass.payAjaxJDK(orderID); - console.log("wxPay");//微信支付 - break; - case "aliPay"://支付宝 - console.log("aliPay"); - //订单号 - var obj = {}; - //this.payAjax(url, { orderId: "11111", price: 0.01 }); - var aliPay = webAppH5.aliPayServer; - var aliParams = webAppH5.comParams; - aliParams.orderId = orderID; - aliParams.payType = 1;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 - aliParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 - aliParams.paySrcType = 101;//101停车支付 - webAppClass.payAliAjax(root + aliPay, aliParams); - break; - default://第三方浏览器other - //默认支付宝 - if (document.getElementById("aliPay").checked) { + }) + }else { + var root = webAppRoot; + //第一首先判断当前哪种浏览器方式[微信内置、支付宝内置、第三方浏览器] + var clientType = clientBrowserEx(); + //alert(clientType); + switch (clientType) { + case "wxPay"://微信[内置浏览器] + //var wxPay = webAppH5.wxPayServer; + //var wxParams = webAppH5.comParams; + //wxParams.orderId = orderID; + //wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 + //wxParams.terminalSource = 3;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 + //debugger; + if (webAppCode == null || webAppCode == "") {//code检测 + alertMsg(appState.codeNullTip); + $btnObj.style.display = "block"; + $btnLoad.style.display = "none"; + return; + } + webAppClass.payAjaxJDK(orderID); + console.log("wxPay");//微信支付 + break; + case "aliPay"://支付宝 console.log("aliPay"); //订单号 var obj = {}; @@ -250,19 +270,36 @@ var webAppClass = { aliParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 aliParams.paySrcType = 101;//101停车支付 webAppClass.payAliAjax(root + aliPay, aliParams); - } else {//微信页面支付 - 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.orderId = orderID; - wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 - wxParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 - webAppClass.payAjax(root + wxPay, wxParams); - console.log("wxPay"); - } - break; + break; + default://第三方浏览器other + //默认支付宝 + if (document.getElementById("aliPay").checked) { + console.log("aliPay"); + //订单号 + var obj = {}; + //this.payAjax(url, { orderId: "11111", price: 0.01 }); + var aliPay = webAppH5.aliPayServer; + var aliParams = webAppH5.comParams; + aliParams.orderId = orderID; + aliParams.payType = 1;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 + aliParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 + aliParams.paySrcType = 101;//101停车支付 + webAppClass.payAliAjax(root + aliPay, aliParams); + } else {//微信页面支付 + 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.orderId = orderID; + wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 + wxParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 + webAppClass.payAjax(root + wxPay, wxParams); + console.log("wxPay"); + } + break; + } } + }, getCode: function () { diff --git a/pay.html b/pay.html index 0e9a7c5..2748d4f 100644 --- a/pay.html +++ b/pay.html @@ -68,6 +68,19 @@ font-size: 14px; color: #EB453B; } + .paySuccess{ + width: 100%; + height: 100%; + text-align: center; + line-height: 100px; + font-size: 20px; + color: #fff; + background: rgba(0,0,0,.7); + position: fixed; + top:0; + left: 0; + display: none; + } @@ -129,7 +142,7 @@
- +
支付成功,请立即离场