Commit 4db97799 by fengzhaoyu

创建分支 鉴权修改 小程序br去掉

parent ecc0c064
...@@ -11,6 +11,9 @@ const $http = (url, data, type, loadingType) => { ...@@ -11,6 +11,9 @@ const $http = (url, data, type, loadingType) => {
let expires_in = hasToken.expires_in || ''; // 过期时效 let expires_in = hasToken.expires_in || ''; // 过期时效
let loginTime = hasToken.expires_in || ''; // 用户登陆时间 let loginTime = hasToken.expires_in || ''; // 用户登陆时间
let token = hasToken.access_token || ''; let token = hasToken.access_token || '';
let refresh_token = hasToken.refresh_token // 刷新token
let mingUserId = dd.getStorageSync({ key: 'mingUserId' }.data)
// 时间戳未过期
if(!!hasToken && ((new Date()).getTime() - hasToken.loginTime < hasToken.expires_in * 1000)){ if(!!hasToken && ((new Date()).getTime() - hasToken.loginTime < hasToken.expires_in * 1000)){
data.orgId = dd.corpId; data.orgId = dd.corpId;
let sendData = ''; let sendData = '';
...@@ -25,11 +28,11 @@ const $http = (url, data, type, loadingType) => { ...@@ -25,11 +28,11 @@ const $http = (url, data, type, loadingType) => {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
}, },
url: `http://${app.globalData.globalUrl}/v1/${url}?${sendData}`, url: `http://${app.globalData.globalUrl}/mingpay-phone/v1/${url}?${sendData}`,
method: type, method: type,
dataType: 'json', dataType: 'json',
success: function(res) { success: function(res) {
if(res.data.resultCode === "0") { if(res.data.resultCode === 0) {
return resolve(res.data.data) return resolve(res.data.data)
} else { } else {
// 修改系统繁忙时loading隐藏 // 修改系统繁忙时loading隐藏
...@@ -49,53 +52,93 @@ const $http = (url, data, type, loadingType) => { ...@@ -49,53 +52,93 @@ const $http = (url, data, type, loadingType) => {
} }
}) })
}) })
} else { }
// 时间戳过期
else {
dd.getNetworkType({ dd.getNetworkType({
success: (res) => { success: (res) => {
// 有网的情况下
if (res.networkAvailable) { if (res.networkAvailable) {
dd.getAuthCode({ dd.httpRequest({
success:function(resultCode){ headers: {
dd.httpRequest({ 'Authorization': 'Basic bWluZ3BheS1waG9uZTptaW5ncGF5LXBob25l',
headers: {"Content-Type": "application/json"}, 'Content-Type': 'application/x-www-form-urlencoded'
url: `http://${app.globalUrl}/v1/auth/token?version=v1&code=${resultCode.authCode}&orgId=${dd.corpId}`, },
method: 'POST', data: {
dataType: 'json', username: mingUserId,
success: function(res) { password: mingUserId,
// 全局存储用户信息token和用户信息 scope: 'server',
const data = res.data.data grant_type: 'password',
// 更新用户内部信息 refresh_token: refresh_token
dd.setStorageSync({ },
key: 'token', url:`http://${app.globalData.globalUrl}/auth/oauth/token`,
data: { method: 'POST',
access_token: data.accessToken.access_token, success: function(res) {
token_type: data.accessToken.token_type, dd.setStorageSync({
expires_in: data.accessToken.expires_in, key: 'token',
loginTime: (new Date()).getTime() data: {
} access_token: res.data.access_token,
}); expires_in: res.data.expires_in,
dd.setStorageSync({ refresh_token: res.data.refresh_token,
key: 'userId', loginTime: (new Date()).getTime()
data: data.oapiUser.userid }
}); })
$http(url, data, type) $http(url, data, type)
}, },
fail: function(res) { fail: function(res) {
console.log(res) console.log('err',res)
} dd.alert({
}); content: '系统繁忙',
}, buttonText: '确定'
fail:function(err){ })
dd.alert({ dd.hideLoading()
content: '系统繁忙', }
buttonText: '确定' })
}); // dd.getAuthCode({
} // success:function(resultCode){
}); // dd.httpRequest({
} else { // headers: {"Content-Type": "application/json"},
// url: `http://${app.globalUrl}/v1/auth/token?version=v1&code=${resultCode.authCode}&orgId=${dd.corpId}`,
// method: 'POST',
// dataType: 'json',
// success: function(res) {
// // 全局存储用户信息token和用户信息
// const data = res.data.data
// // 更新用户内部信息
// dd.setStorageSync({
// key: 'token',
// data: {
// access_token: data.accessToken.access_token,
// token_type: data.accessToken.token_type,
// expires_in: data.accessToken.expires_in,
// loginTime: (new Date()).getTime()
// }
// });
// dd.setStorageSync({
// key: 'userId',
// data: data.oapiUser.userid
// });
// $http(url, data, type)
// },
// fail: function(res) {
// console.log(res)
// }
// });
// },
// fail:function(err){
// dd.alert({
// content: '系统繁忙',
// buttonText: '确定'
// });
// }
// });
}
else {
dd.alert({ dd.alert({
content: '登录超时,请连接网络重新登录', content: '登录超时,请连接网络重新登录',
buttonText: '确定' buttonText: '确定'
}); });
dd.hideLoading()
} }
} }
}); });
......
...@@ -17,8 +17,8 @@ App({ ...@@ -17,8 +17,8 @@ App({
// axios.defaults.baseURL = 'http://139.196.213.18:8400' // beta环境 // axios.defaults.baseURL = 'http://139.196.213.18:8400' // beta环境
globalData: { globalData: {
loadingType: 0, loadingType: 0,
// globalUrl: '192.168.1.106:8400' globalUrl: '192.168.1.101:9999'
// globalUrl: '192.168.1.102:8400' // globalUrl: '192.168.1.102:8400'
globalUrl: '139.196.213.18:8400' // globalUrl: '139.196.213.18:8400'
} }
}); });
...@@ -9,22 +9,28 @@ Page({ ...@@ -9,22 +9,28 @@ Page({
}); });
dd.getNetworkType({ dd.getNetworkType({
success: (res) => { success: (res) => {
// 有网络状态
if (res.networkAvailable) { if (res.networkAvailable) {
// 获取免登授权码
dd.getAuthCode({ dd.getAuthCode({
success:function(res){ success:function(res){
// 获取用户信息 // 根据免登授权码获取用户信息
_that.getUserMsg(res.authCode) _that.getUserMsg(res.authCode)
}, },
// 获取免登授权码失败
fail:function(err){ fail:function(err){
console.log(err) console.log(err)
} }
}); });
} else { }
if (dd.getStorageSync({ key: 'userId' }).data) { // 无网络状态
else {
if (dd.getStorageSync({ key: 'token' }).data) {
dd.redirectTo({ dd.redirectTo({
url: '/pages/index/index' url: '/pages/index/index'
}) })
} else { }
else {
dd.alert({ dd.alert({
content: '系统繁忙', content: '系统繁忙',
buttonText: '确定' buttonText: '确定'
...@@ -34,63 +40,157 @@ Page({ ...@@ -34,63 +40,157 @@ Page({
} }
}); });
}, },
// 有网络的状态更新用户userId和token // 根据免登授权码获取用户的信息并进行全局存储
getUserMsg(code) { getUserMsg(code) {
const _that = this; const _that = this;
let token = dd.getStorageSync({ key: 'token' }).data ? dd.getStorageSync({ key: 'token' }).data.access_token : '';
let orgId = dd.corpId; let orgId = dd.corpId;
dd.httpRequest({ dd.httpRequest({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/x-www-form-urlencoded"
"Authorization": `Bearer ${token}`
}, },
url: `http://${app.globalData.globalUrl}/v1/auth/userToken?version=v1&code=${code}&token=${token}&orgId=${orgId}`, url: `http://${app.globalData.globalUrl}/mingpay-phone/v1/skipAuth/getUserInfoByCode?code=${code}&orgId=${orgId}`,
method: 'POST', method: 'POST',
dataType: 'json', dataType: 'json',
success: function(res) { success: function(res) {
console.log(res)
// 全局存储用户信息token和用户信息 if(res.data.resultCode == 0) {
if(res.data.resultCode === '0'){ const data = res.data.data
const data = res.data.data; dd.setStorageSync({
// 更新用户内部信息 key: 'mingUserId',
dd.setStorageSync({ data: data.mingUserId
key: 'token', })
data: { dd.setStorageSync({
access_token: data.accessToken.access_token, key: 'userId',
token_type: data.accessToken.token_type, data: data.oapiUser.userid
expires_in: data.accessToken.expires_in, })
loginTime: (new Date()).getTime() dd.setStorageSync({
} key: 'avatar',
}); data: data.oapiUser.avatar
dd.setStorageSync({ })
key: 'userId',
data: data.oapiUser.userid _that.getUserToken(data.mingUserId)
}); }
dd.setStorageSync({ else {
key: 'avatar', dd.alert({
data: data.oapiUser.avatar content: '系统繁忙',
}); buttonText: '确定'
dd.hideLoading();
dd.redirectTo({
url: '/pages/index/index'
})
}else{
dd.hideLoading();
dd.redirectTo({
url: '/pages/noPermission/noPermission'
}) })
} dd.hideLoading()
}
}, },
fail: function(res) { fail: function(res) {
console.log('err',res) console.log('err',res)
dd.alert({ dd.alert({
content: '系统繁忙', content: '系统繁忙',
buttonText: '确定' buttonText: '确定'
}); })
dd.hideLoading(); dd.hideLoading();
} }
});
})
}, },
// 获取token接口
getUserToken(mingUserId) {
dd.httpRequest({
headers: {
'Authorization': 'Basic bWluZ3BheS1waG9uZTptaW5ncGF5LXBob25l',
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
username: mingUserId,
password: mingUserId,
scope: 'server',
grant_type: 'password'
},
url:`http://${app.globalData.globalUrl}/auth/oauth/token`,
method: 'POST',
dataType: 'json',
success: function(res) {
dd.setStorageSync({
key: 'token',
data: {
access_token: res.data.access_token,
expires_in: res.data.expires_in,
refresh_token: res.data.refresh_token,
loginTime: (new Date()).getTime()
}
})
dd.hideLoading()
dd.redirectTo({
url: '/pages/index/index'
})
},
fail: function(res) {
console.log('err',res)
dd.alert({
content: '系统繁忙',
buttonText: '确定'
})
dd.hideLoading()
}
})
},
// 有网络的状态更新用户userId和token
// getUserMsg(code) {
// const _that = this;
// let token = dd.getStorageSync({ key: 'token' }).data ? dd.getStorageSync({ key: 'token' }).data.access_token : '';
// let orgId = dd.corpId;
// dd.httpRequest({
// headers: {
// "Content-Type": "application/json",
// "Authorization": `Bearer ${token}`
// },
// url: `http://${app.globalData.globalUrl}/v1/auth/userToken?version=v1&code=${code}&token=${token}&orgId=${orgId}`,
// method: 'POST',
// dataType: 'json',
// success: function(res) {
// console.log(res)
// // 全局存储用户信息token和用户信息
// if(res.data.resultCode === '0'){
// const data = res.data.data;
// // 更新用户内部信息
// dd.setStorageSync({
// key: 'token',
// data: {
// access_token: data.accessToken.access_token,
// token_type: data.accessToken.token_type,
// expires_in: data.accessToken.expires_in,
// loginTime: (new Date()).getTime()
// }
// });
// dd.setStorageSync({
// key: 'userId',
// data: data.oapiUser.userid
// });
// dd.setStorageSync({
// key: 'avatar',
// data: data.oapiUser.avatar
// });
// dd.hideLoading();
// dd.redirectTo({
// url: '/pages/index/index'
// })
// }else{
// dd.hideLoading();
// dd.redirectTo({
// url: '/pages/noPermission/noPermission'
// })
// }
// },
// fail: function(res) {
// console.log('err',res)
// dd.alert({
// content: '系统繁忙',
// buttonText: '确定'
// });
// dd.hideLoading();
// }
// });
// },
onReady() { onReady() {
// 页面加载完成 // 页面加载完成
}, },
......
<view> <view>
<view class="nullImage" a:if="{{recordAlliwanceListData.length === 0}}"> <view class="nullImage" a:if="{{recordAlliwanceListData.length === 0}}">
<image mode="scaleToFill" src="../../../assets/recordNull.png"/><br/> <image mode="scaleToFill" src="../../../assets/recordNull.png"/>
<text>当前暂无账单记录</text> <text>当前暂无账单记录</text>
</view> </view>
<view class="recordList"> <view class="recordList">
......
...@@ -23,9 +23,10 @@ Page({ ...@@ -23,9 +23,10 @@ Page({
} else { } else {
dd.showToast({ dd.showToast({
type: 'fail', type: 'fail',
content: '未网仅支持离线支付', content: '未网仅支持离线支付',
duration: 3000, duration: 3000,
}); });
dd.hideLoading()
} }
} }
}); });
......
...@@ -49,50 +49,6 @@ Page({ ...@@ -49,50 +49,6 @@ Page({
timeRefreshQRcode = setInterval(function () { timeRefreshQRcode = setInterval(function () {
_that.refreshQRcode(); _that.refreshQRcode();
}, 55000); }, 55000);
// dd.connectSocket({
// url: `ws://${app.globalData.globalUrl}/v1/mingpaywebsocket?param=${dd.corpId}_${dd.getStorageSync({ key: 'userId' }).data}`,
// data: {},
// header:{
// 'content-type': 'application/json',
// 'Authorization': `Bearer ${dd.getStorageSync({ key: 'token' }).data.access_token}`
// },
// method:"GET",
// });
// dd.onSocketOpen(function(res) {
// console.log('WebSocket 连接已打开!');
// });
// dd.onSocketError(function(res){
// console.log('WebSocket 连接打开失败,请检查!');
// });
// dd.onSocketMessage(function(res) {
// console.log(JSON.parse(res.data))
// let resData = JSON.parse(res.data)
// if(resData.paymentCode === 0){
// dd.redirectTo({
// url: `./../paySuccess/paySuccess?money=${(JSON.parse(res.data).orderAmount).toFixed(2)}`
// })
// }else if(resData.paymentCode === 10001){
// dd.alert({
// content: '账户状态异常',
// buttonText: '确定'
// });
// }else if(resData.paymentCode === 10002){
// dd.alert({
// content: '卡片状态异常',
// buttonText: '确定'
// });
// }else if(resData.paymentCode === 10003){
// dd.alert({
// content: '账户余额不足',
// buttonText: '确定'
// });
// }else if(resData.paymentCode === 10004){
// dd.alert({
// content: '二维码失效',
// buttonText: '确定'
// });
// }
// })
}, },
onShow() { onShow() {
//刷新二维码 //刷新二维码
...@@ -102,7 +58,7 @@ Page({ ...@@ -102,7 +58,7 @@ Page({
timeRefreshQRcode = setInterval(function () { timeRefreshQRcode = setInterval(function () {
_that.refreshQRcode(); _that.refreshQRcode();
}, 55000); }, 55000);
//页面显示 //页面显示
dd.connectSocket({ dd.connectSocket({
url: `ws://${app.globalData.globalUrl}/v1/mingpaywebsocket?param=${dd.corpId}_${dd.getStorageSync({ key: 'userId' }).data}`, url: `ws://${app.globalData.globalUrl}/v1/mingpaywebsocket?param=${dd.corpId}_${dd.getStorageSync({ key: 'userId' }).data}`,
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</view> </view>
<!-- <text class="money">支出:¥386.00 充值:¥500.00</text> --> <!-- <text class="money">支出:¥386.00 充值:¥500.00</text> -->
<view class="nullImage" a:if="{{recordListData.length === 0}}"> <view class="nullImage" a:if="{{recordListData.length === 0}}">
<image mode="scaleToFill" src="../../../assets/recordNull.png"/><br/> <image mode="scaleToFill" src="../../../assets/recordNull.png"/>
<text>当前暂无账单记录</text> <text>当前暂无账单记录</text>
</view> </view>
<view class="recordList"> <view class="recordList">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment