parent
ddf354921b
commit
39c4716fc1
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
let domain = 'http://localhost:8080'
|
let domain = 'http://127.0.0.1:8080'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// 请求域名 格式: https://您的域名
|
// 请求域名 格式: https://您的域名
|
||||||
|
|
|
@ -153,37 +153,12 @@ class AuthWechat {
|
||||||
/**
|
/**
|
||||||
* 自动去授权
|
* 自动去授权
|
||||||
*/
|
*/
|
||||||
oAuth(snsapiBase,url) {
|
oAuth() {
|
||||||
if (uni.getStorageSync(WX_AUTH) && store.state.app.token && snsapiBase == 'snsapi_base') return;
|
if (uni.getStorageSync(WX_AUTH) && store.state.app.token) return;
|
||||||
const {
|
const {
|
||||||
code
|
code
|
||||||
} = parseQuery();
|
} = parseQuery();
|
||||||
if (!code || code == uni.getStorageSync('snsapiCode')){
|
if (!code) return this.toAuth();
|
||||||
return this.toAuth(snsapiBase,url);
|
|
||||||
}else{
|
|
||||||
if(Cache.has('snsapiKey'))
|
|
||||||
return this.auth(code).catch(error=>{
|
|
||||||
uni.showToast({
|
|
||||||
title:error,
|
|
||||||
icon:'none'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// if (uni.getStorageSync(WX_AUTH) && store.state.app.token) return;
|
|
||||||
// const {
|
|
||||||
// code
|
|
||||||
// } = parseQuery();
|
|
||||||
// if (!code){
|
|
||||||
// return this.toAuth(snsapiBase,url);
|
|
||||||
// }else{
|
|
||||||
// if(Cache.has('snsapiKey'))
|
|
||||||
// return this.auth(code).catch(error=>{
|
|
||||||
// uni.showToast({
|
|
||||||
// title:error,
|
|
||||||
// icon:'none'
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearAuthStatus() {
|
clearAuthStatus() {
|
||||||
|
@ -213,7 +188,7 @@ class AuthWechat {
|
||||||
Cache.clear(STATE_KEY);
|
Cache.clear(STATE_KEY);
|
||||||
// Cache.clear('spread');
|
// Cache.clear('spread');
|
||||||
loginType && Cache.clear(LOGINTYPE);
|
loginType && Cache.clear(LOGINTYPE);
|
||||||
resolve(data);
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
|
@ -223,43 +198,32 @@ class AuthWechat {
|
||||||
* 获取跳转授权后的地址
|
* 获取跳转授权后的地址
|
||||||
* @param {Object} appId
|
* @param {Object} appId
|
||||||
*/
|
*/
|
||||||
getAuthUrl(appId,snsapiBase,backUrl) {
|
getAuthUrl(appId) {
|
||||||
let url = `${location.origin}${backUrl}`
|
const redirect_uri = encodeURIComponent(
|
||||||
if(url.indexOf('?') == -1){
|
`${location.origin}/pages/auth/index?back_url=` +
|
||||||
url = url+'?'
|
encodeURIComponent(
|
||||||
}else{
|
encodeURIComponent(
|
||||||
url = url+'&'
|
uni.getStorageSync(BACK_URL) ?
|
||||||
}
|
uni.getStorageSync(BACK_URL) :
|
||||||
const redirect_uri = encodeURIComponent(
|
location.pathname + location.search
|
||||||
`${url}scope=${snsapiBase}&back_url=` +
|
)
|
||||||
encodeURIComponent(
|
)
|
||||||
encodeURIComponent(
|
);
|
||||||
uni.getStorageSync(BACK_URL) ?
|
uni.removeStorageSync(BACK_URL);
|
||||||
uni.getStorageSync(BACK_URL) :
|
const state = encodeURIComponent(
|
||||||
location.pathname + location.search
|
("" + Math.random()).split(".")[1] + "authorizestate"
|
||||||
)
|
);
|
||||||
)
|
uni.setStorageSync(STATE_KEY, state);
|
||||||
);
|
return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`;
|
||||||
uni.removeStorageSync(BACK_URL);
|
}
|
||||||
const state = encodeURIComponent(
|
|
||||||
("" + Math.random()).split(".")[1] + "authorizestate"
|
|
||||||
);
|
|
||||||
uni.setStorageSync(STATE_KEY, state);
|
|
||||||
return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
|
|
||||||
// if(snsapiBase==='snsapi_base'){
|
|
||||||
// return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`;
|
|
||||||
// }else{
|
|
||||||
// return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 跳转自动登录
|
* 跳转自动登录
|
||||||
*/
|
*/
|
||||||
toAuth(snsapiBase,backUrl) {
|
toAuth() {
|
||||||
let that = this;
|
let that = this;
|
||||||
this.wechat().then(wx => {
|
this.wechat().then(wx => {
|
||||||
location.href = this.getAuthUrl(that.initConfig.appId,snsapiBase,backUrl);
|
location.href = this.getAuthUrl(that.initConfig.appId);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,4 +272,4 @@ class AuthWechat {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new AuthWechat();
|
export default new AuthWechat();
|
||||||
// #endif
|
// #endif
|
Loading…
Reference in New Issue