From a9afac506808bab029914449f75efe68b3488670 Mon Sep 17 00:00:00 2001 From: wuxw <928255095@qq.com> Date: Sat, 27 Aug 2022 14:35:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=B9=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/user/userApi.js | 26 +++++++ lib/java110/utils/EnvUtil.js | 22 +++--- pages/tempParkingFee/tempParkingFee.vue | 98 +++++++++++++++++-------- 3 files changed, 103 insertions(+), 43 deletions(-) diff --git a/api/user/userApi.js b/api/user/userApi.js index 568b33d..35b7650 100644 --- a/api/user/userApi.js +++ b/api/user/userApi.js @@ -169,3 +169,29 @@ export function refreshUserOpenId(_objData){ }); }) } + +/** + * 刷新用户 + * @param {Object} _objData + */ +export function getOpenIdFromAliPay(_objData){ + return new Promise((resolve, reject) => { + requestNoAuth({ + url: url.getOpenIdFromAliPay, + method: "GET", + data: _objData, //动态数据 + success: function(res) { + if (res.statusCode == 200) { + resolve(res.data); + return; + } + reject(); + }, + fail: function(e) { + reject(); + } + }); + }) +} + + diff --git a/lib/java110/utils/EnvUtil.js b/lib/java110/utils/EnvUtil.js index a386ad6..f2b9390 100644 --- a/lib/java110/utils/EnvUtil.js +++ b/lib/java110/utils/EnvUtil.js @@ -1,13 +1,11 @@ -export default function isWxOrAli() { - var ua = window.navigator.userAgent.toLowerCase(); - console.log(ua.match(/MicroMessenger/i)); - //判断是不是微信 - if (ua.match(/MicroMessenger/i) == "micromessenger") { - return "Wechat"; - } - console.log(ua.match(/AlipayClient/i)); - //判断是不是支付宝 - if (ua.match(/AlipayClient/i) == "alipayclient") { - return "AliPay"; - } +export default function isWxOrAli() { + let _env = "WECHAT" + if (/MicroMessenger/.test(window.navigator.userAgent)) { + _env = "WECHAT" + } else if (/AlipayClient/.test(window.navigator.userAgent)) { + _env = "ALI" + } else { + _env = "OTHER" + } + return _env; } diff --git a/pages/tempParkingFee/tempParkingFee.vue b/pages/tempParkingFee/tempParkingFee.vue index 704e66a..9e8cbe0 100644 --- a/pages/tempParkingFee/tempParkingFee.vue +++ b/pages/tempParkingFee/tempParkingFee.vue @@ -45,13 +45,14 @@ - + - 往期记录 - - {{item.carNum}} + 往期记录 + + {{item.carNum}} + - {{carNumBtn}} @@ -61,13 +62,13 @@ - - - - 临停支付说明 - 1、若因特殊原因无法查询车辆信息,请联系停车场人工处理: - 2、查询缴费前请仔细核对停车场及车牌号: - 3、若长时间无法加载页面,请检查网络是否畅通或扫码重试。 + + + + 临停支付说明 + 1、若因特殊原因无法查询车辆信息,请联系停车场人工处理: + 2、查询缴费前请仔细核对停车场及车牌号: + 3、若长时间无法加载页面,请检查网络是否畅通或扫码重试。 @@ -87,7 +88,8 @@ isNotNull } from '../../lib/java110/utils/StringUtil.js' import { - refreshUserOpenId + refreshUserOpenId, + getOpenIdFromAliPay } from '../../api/user/userApi.js' import { isWxOrAli @@ -113,23 +115,40 @@ carNum: '', paId: '', appId: '', + aliAppId: '', openId: '', - machineId: '', + machineId: '', + communityId:'', carNums: [] } }, components: { selectCarNum }, + mounted() { + // #ifdef H5 + if (isWxOrAli() == "ALIPAY") { + const oScript = document.createElement('script'); + oScript.type = 'text/javascript'; + oScript.src = 'https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js'; + document.body.appendChild(oScript); + } + // #endif + }, onLoad(options) { this.paId = options.paId; this.appId = options.appId; this.openId = options.openId; - this.machineId = options.machineId; + this.machineId = options.machineId; + this.communityId = options.communityId; uni.setStorageSync(mapping.W_APP_ID, this.appId) if (!isNotNull(this.openId)) { //刷新 openId - this._refreshWechatOpenId(); + if (isWxOrAli() == 'ALIPAY') { + this._refreshAliPayOpenId(); + } else { + this._refreshWechatOpenId(); + } return; } this._loadExistsCarNum(); @@ -206,16 +225,28 @@ }) }) }, + _refreshAliPayOpenId: function() { + // console.log("判断微信还是支付宝"); + // console.log(isWxOrAli()); + let _that = this; + ap.getAuthCode({ + appId: this.aliAppId, + scopes: ['auth_base'], + }, function(res) { + ap.alert(JSON.stringify(res)); + getOpenIdFromAliPay({ + authCode:res.authCode, + communityId:_that.communityId + }).then(_data=>{ + _that.openId = _data.data; + _that._loadExistsCarNum(); + }) + }); + + }, _refreshWechatOpenId: function() { // console.log("判断微信还是支付宝"); // console.log(isWxOrAli()); - // if (isWxOrAli() == 'AliPay') { - // uni.showToast({ - // icon: 'none', - // title: '支付宝暂时未开通,敬请期待' - // }) - // return; - // } let _redirectUrl = window.location.href; refreshUserOpenId({ redirectUrl: _redirectUrl, @@ -229,14 +260,19 @@ }); }, _loadExistsCarNum: function() { - let _that = this; + let _that = this; + let _openType = "WECHAT"; + if(isWxOrAli == 'ALIPAY'){ + _openType = 'ALIPAY' + } queryWaitPayFeeTempCar({ openId: this.openId, - machineId: this.machineId + machineId: this.machineId, + openType:_openType }).then(_json => { _that.carNums = _json.data; - if (_json.data && _json.data.length == 1) { - _that.carNum = _json.data[0].carNum; + if (_json.data && _json.data.length == 1) { + _that.carNum = _json.data[0].carNum; _that._queryCarNum(); } }) @@ -260,14 +296,14 @@ } if (_carNum.length > 5) { this.inputPlates.index5 = _carNum[5]; - } + } if (_carNum.length > 6) { this.inputPlates.index6 = _carNum[6]; - } + } if (_carNum.length > 7) { this.inputPlates.index7 = _carNum[7]; - } - //查询 + } + //查询 this._queryCarNum(); } }