diff --git a/js/lock.js b/js/lock.js new file mode 100644 index 0000000..a9ac2a3 --- /dev/null +++ b/js/lock.js @@ -0,0 +1,566 @@ +/* +@songcxa +@2018-12-14 +@移动支付 +*/ +var webAppParams = null; +var $btnObj = null; +var $btnLoad = null; +var flag = 0; +var webAppCode = null;//如果是微信,先获取微信code +//var $btnLoad = document.getElementById("loading"); +window.onload = function () { + //var root = document.getElementById("root"); + $btnObj = document.getElementById("btnPayOK"); + $btnLoad = document.getElementById("loading"); + + // $discountBtn = document.getElementById("discountBtn"); + $linkPayDetail = getObjectByID("linkPayDetail"); + $linkPayDetail.onclick = webAppClass.linkPayDetailClick; + var webRoot = window.location.href; + //设置当前客户端浏览器模式[微信、支付宝、其他] + webAppClass.clientBrowser(); + //绑定事件 + var ali = document.getElementById("rowAliPay"); + var wx = document.getElementById("rowWxPay"); + ali.onclick = webAppClass.aliClick; + wx.onclick = webAppClass.wxClick; + $btnObj.onclick = webAppClass.okClick; + document.getElementById("payTip").innerHTML = ""; + //参数 + webAppParams = getQueryString(window.location); + console.log(webAppParams.carNumber) + console.log(webAppParams.plNo) + if (webAppParams!=null) { + //设置UI参数 + var url = 'http://39.98.54.240:8090/queryParkOrder/queryToPayOrderIdByCarNumber'; + var discountParams = { + app_id:'1', + salt:'1', + deviceInfo:'1', + sign_type:'1', + sign:'1', + token:'1', + terminalSource:7, + carNumber:webAppParams.carNumber, + plNo:webAppParams.plNo, + codeType:0 + } + // var discountParams = JSON.stringify(discountParams) + postRequest(url, discountParams, function (res) { + console.log(res) + + var url1 = 'http://39.98.54.240:8090/queryParkOrder/billQuery'; + var discountParams1 = { + app_id:'1', + salt:'1', + deviceInfo:'1', + sign_type:'1', + sign:'1', + token:'1', + carNumber:webAppParams.carNumber, + parkCode:webAppParams.plNo, + terminalSource:7, + orderId:res.data, + codeType:0 + } + // var discountParams = JSON.stringify(discountParams) + postRequest(url1, discountParams1, function (res) { + console.log(res) + + + + + // // if(res.code==0){ + // // + // document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100) + // document.getElementById("parkName").innerHTML = (res.data.parkName) + // document.getElementById("staytime").innerHTML = (res.data.staytime) + // + // document.getElementById("inparktime").innerHTML = (res.data.inparktime) + // document.getElementById("due").innerHTML = (res.data.orderTotalFee/100) + // + // document.getElementById("paid").innerHTML = (res.data.paid/100) + // document.getElementById("discountFee").innerHTML = (res.data.discountFee) + // + // document.getElementById("discountDesc").innerHTML = (res.data.discountDesc) + // + // document.getElementById("orderNum").innerHTML = (res.data.orderId) + // + // // 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);//唤醒支付 + + webAppClass.setUI(res.data); + }) + + + + }) + } else { + alertMsg("暂无订单信息"); + } + + //获取微信code + //webAppClass.getCode(); + var state = clientBrowserEx(); + if (state == "wxPay") { + webAppCode = webAppClass.getCode(); + } + // $discountBtn.onclick = webAppClass.discountClick; +} +/**/ +var webAppClass = { + + + //OK + okClick: function (ev) { + document.getElementById("payTip").innerHTML = ""; + if (webAppParams == null) { + alertMsg("暂无订单信息");return; + } + //先校验停车费用后缴费提交 + webAppClass.checkParkCost(); + }, + //校验该订单当前支付时的费用(排除扫描订单后不支付时长) + checkParkCost: function () { + $btnObj.style.display = "none"; + $btnLoad.style.display = "block"; + if (typeof(webAppParams.queryOrderInfo) == "undefined") {//没有queryOrderInfo返回第一页 + window.history.back(-1); + } + var tmpParams = JSON.parse(webAppParams.queryOrderInfo); + var url = webAppRoot + window.webAppH5.comServer; + postRequest(url, tmpParams, function (res) { + //btnObj.style.display = "block"; //$btnLoad.style.display = "none"; + //$btnObj.style.display = "block"; + 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);//唤醒支付 + } + + console.log(tmpObj) + // webAppClass.okPay(tmpObj);//唤醒支付 + } else { + alertMsg("没有找到相应订单"); + } + } else {//其他情况如【该卡号场内已存在】 + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + console.log(res.message); alertMsg(res.message); + } + }, function (err) { + console.log("网络服务超时..." + url); + alertMsg("网络服务超时"); + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + //$btnLoad.style.display = "none"; + }); + }, + + //确定支付 + okPay: function (params) { + var orderID = params.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 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 { + 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 = {}; + //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) { + 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 () { + var appID = appWxID; + var code = getUrlParam('code'); + var local = window.location.href; + //alert("local:" + local); + if (code == null || code === '') { + //alert(code); + window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appID + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect' + //window.event.returnValue = false; + //window.open('https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appID + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'); + //alert("22"); + } else { + //getOpenId(code); //把code传给后台获取用户信息 + //alert(code); + //webAppCode = code; + return code; + } + + function getUrlParam(name) { + var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); + var r = window.location.search.substr(1).match(reg) + if (r != null) return unescape(r[2]) + return null + } + }, + //Ali + aliClick: function (ev) { + console.log("AliClick"); + document.getElementById("aliPay").checked = true; + ev.preventDefault(); + }, + //Wx + wxClick: function (ev) { + console.log("wxClick"); + document.getElementById("wxPay").checked = true; + ev.preventDefault(); + }, + //浏览器 + clientBrowser: function () { + if (/MicroMessenger/.test(window.navigator.userAgent)) { + console.log("微信客户端"); + this.switchShow("wxPay"); + } else if (/AlipayClient/.test(window.navigator.userAgent)) { + console.log("支付宝客户端"); + this.switchShow("aliPay"); + } else { + console.log("其他浏览器"); + this.switchShow("other"); + } + }, + //根据浏览器显示内容[aliPay、wxPay、other] + switchShow: function (type) { + var aliObj = document.getElementById("rowAliPay"); + var wxObj = document.getElementById("rowWxPay"); + var lineObj = document.getElementById("splitLine"); + switch (type) { + case "aliPay": + lineObj.style.display = "none"; + wxObj.style.display = "none"; + document.getElementById("aliPay").checked = true; + break; + case "wxPay": + lineObj.style.display = "none"; + aliObj.style.display = "none"; + document.getElementById("wxPay").checked = true; + break; + default://其他浏览器[浏览器暂时屏蔽微信] + lineObj.style.display = "none"; + wxObj.style.display = "none"; + document.getElementById("aliPay").checked = true; + break; + } + }, + + //异步请求-微信H5页面 + payAjax: function (url, params) { + var btnOBj = $btnObj; + postRequest(url, params, function (res) { + btnOBj.style.display = "block"; + $btnLoad.style.display = "none"; + //debugger; + if (res.code == 0) {//进场 + //alertMsg("出场成功"); + if (res.data) { + var tmpObj = res.data; + if (typeof (tmpObj.mwebUrl)!="undefined") { + window.location.href = tmpObj.mwebUrl + "&redirect_url=" + webAppPayResult; + } else { + alertMsg("没有返回支付地址mwebUrl"); + } + console.log(JSON.stringify(tmpObj)); + } else { + alertMsg("没有找到返回值"); + } + } else {//其他情况如【该卡号场内已存在】 + console.log(res.message); + alertMsg(res.message); + } + }, function (err) { + console.log("网络地址出错..."); + alertMsg("网络地址出错..."); + $btnLoad.style.display = "none"; + btnOBj.style.display = "block"; + }); + }, + //异步请求-微信JDK调用 + payAjaxJDK: function (orderID) { + var btnOBj = $btnObj; + //0:页面初始化获取code[webAppCode] + var codeParams = { code: webAppCode, appId: appWxID }; + var openIdUrl = webAppRoot + window.webAppH5.wxGetOpenIdServer; + + //1:有code获取OpenId + postRequest(openIdUrl, codeParams, function (res) { + //alert(JSON.stringify(res)); + if (res.code == 0) { + //alert(res.data); + webAppClass.getPayParams(res.data, orderID); + } + 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 { + alertMsg(res.message); + $btnObj.style.display = "block"; + $btnLoad.style.display = "none"; + } + }, function (err) { + console.log("网络地址出错..." + openIdUrl); + $btnObj.style.display = "block"; + $btnLoad.style.display = "none"; + }); + //2:获取支付参数 + //function getPayParams(openId) { + + //} + }, + getPayParams: function (openId, orderID) { + var wxPay = window.webAppH5.wxPayServer; + var wxParams = window.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); + wxParams.openId = openId; + wxParams.appId = appWxID; + var payParamsUrl = webAppRoot + window.webAppH5.wxPayServer; + //alert(payParamsUrl);alert(orderID); + postRequest(payParamsUrl, wxParams, function (res) { + $btnObj.style.display = "block"; + $btnLoad.style.display = "none"; + //debugger; + if (res.code == 0) {//进场 + //alertMsg("出场成功"); + if (res.data) { + var tmpObj = res.data; + webAppClass.weixinJSBridge(res.data); + console.log(JSON.stringify(tmpObj)); + //alert(JSON.stringify(tmpObj)); + } else { + alertMsg("没有找到返回值"); + } + } else { + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + console.log(res.message); alertMsg(res.message); + } + }, function (err) { + console.log("网络地址出错..."); + alertMsg("网络地址出错..." + payParamsUrl); + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + }); + }, + + //调用微信内置WeixinJSBridge对象发起支付 + weixinJSBridge: function (params) { + 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); + } + }); + } + 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 { + onBridgeReady(); + } + }, + + //异步请求-支付宝 + payAliAjax: function (url, params) { + var btnOBj = $btnObj; + postRequest(url, params, function (res) { + btnOBj.style.display = "block"; + $btnLoad.style.display = "none"; + if (res.code == 0) {//进场 + document.write(res.data);//打开支付表单 + } else {//其他情况如【该卡号场内已存在】 + console.log(res.message); + alertMsg(res.message); + } + }, function (err) { + console.log("网络地址出错...");alertMsg("网络地址出错..."); + $btnLoad.style.display = "none"; + btnOBj.style.display = "block"; + }); + }, + + //设置UI + setUI: function (params) { + console.log(params) + var $carNum = getObjectByID("carNum"),//车牌号 + $orderNum = getObjectByID("orderNum"),//订单号 + $sumMoney = getObjectByID("sumMoney"),//实际应付金额 + $outtime = getObjectByID("outtime"),//实际出场时间 + $payTip = getObjectByID("payTip"),//支付提示 + + $parkName = getObjectByID("parkName"),//车场名称 + $inparktime = getObjectByID("inparktime"),//进场时间 + $staytime = getObjectByID("staytime"),//停车时长 + $due = getObjectByID("due"),//停车总费用 + + $paid = getObjectByID("paid"),//已支付金额 + $discountDesc = getObjectByID("discountDesc"),//8折优惠折扣费用 + $discountFee = getObjectByID("discountFee");//优惠金额 + + if (params != null && params!="") { + var price = keepTwoDecimalFull((params.orderFee / 100));//(params.orderFee / 100); + $carNum.innerHTML = params.plateno;//手机号 + $orderNum.innerHTML = params.orderId;//订单号 + $sumMoney.innerHTML = price;///params.orderFee//缴费金额 + $outtime.innerHTML = params.outtime;//实际出场时间 + //.appOrderTimeout + $payTip.innerHTML = "注意: " + params.appOrderTimeout;//请在支付完成10分钟内出场,如超时未出场,会继续计费。 + + $parkName.innerHTML = params.parkName; + $inparktime.innerHTML = params.inparktime; + $staytime.innerHTML = formatSeconds(params.staytime); + + $due.innerHTML = keepTwoDecimalFull((params.due / 100));//停车总费用 + $paid.innerHTML = params.paid; + // $discountFee.innerHTML = keepTwoDecimalFull((params.discountFee / 100));//优惠金额 + $discountFee.innerHTML = (params.discountFee ) + $discountDesc.innerHTML = params.discountDesc; + } else { + console.log("没有接受到参数"); + } + }, + + //查看详情 + linkPayDetailClick: function (ev) { + var $payDetail = getObjectByID("payDetail"); + var $linkPayDetail = getObjectByID("linkPayDetail"); + if ($linkPayDetail.innerHTML == "详情+") { + $linkPayDetail.innerHTML = "详情-"; + $payDetail.style.height = "195px"; + } else { + $linkPayDetail.innerHTML = "详情+"; + $payDetail.style.height = "55px"; + } + } +} diff --git a/lockpay.html b/lockpay.html new file mode 100644 index 0000000..681b039 --- /dev/null +++ b/lockpay.html @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + 地锁支付 + + + + + + + +
+
车场名称:详情+
+
停车时长:
+
进场时间:
+
停车总费用:
+
已支付金额:
+
优惠金额:
+
订单编号: 1234567890
+
+ + + + + + + +
+
+ 选择支付方式 出场时间: +
+
+ +
+ + 支付宝支付 + +
+
+ +
+ + 微信支付 + +
+
+
+ +
+
支付成功,请立即离场
+ + + +