parent
ddf354921b
commit
39c4716fc1
|
@ -1,5 +1,5 @@
|
|||
|
||||
let domain = 'http://localhost:8080'
|
||||
let domain = 'http://127.0.0.1:8080'
|
||||
|
||||
module.exports = {
|
||||
// 请求域名 格式: https://您的域名
|
||||
|
|
|
@ -153,37 +153,12 @@ class AuthWechat {
|
|||
/**
|
||||
* 自动去授权
|
||||
*/
|
||||
oAuth(snsapiBase,url) {
|
||||
if (uni.getStorageSync(WX_AUTH) && store.state.app.token && snsapiBase == 'snsapi_base') return;
|
||||
oAuth() {
|
||||
if (uni.getStorageSync(WX_AUTH) && store.state.app.token) return;
|
||||
const {
|
||||
code
|
||||
} = parseQuery();
|
||||
if (!code || code == uni.getStorageSync('snsapiCode')){
|
||||
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'
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
if (!code) return this.toAuth();
|
||||
}
|
||||
|
||||
clearAuthStatus() {
|
||||
|
@ -213,7 +188,7 @@ class AuthWechat {
|
|||
Cache.clear(STATE_KEY);
|
||||
// Cache.clear('spread');
|
||||
loginType && Cache.clear(LOGINTYPE);
|
||||
resolve(data);
|
||||
resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
|
@ -223,15 +198,9 @@ class AuthWechat {
|
|||
* 获取跳转授权后的地址
|
||||
* @param {Object} appId
|
||||
*/
|
||||
getAuthUrl(appId,snsapiBase,backUrl) {
|
||||
let url = `${location.origin}${backUrl}`
|
||||
if(url.indexOf('?') == -1){
|
||||
url = url+'?'
|
||||
}else{
|
||||
url = url+'&'
|
||||
}
|
||||
getAuthUrl(appId) {
|
||||
const redirect_uri = encodeURIComponent(
|
||||
`${url}scope=${snsapiBase}&back_url=` +
|
||||
`${location.origin}/pages/auth/index?back_url=` +
|
||||
encodeURIComponent(
|
||||
encodeURIComponent(
|
||||
uni.getStorageSync(BACK_URL) ?
|
||||
|
@ -245,21 +214,16 @@ class AuthWechat {
|
|||
("" + 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`;
|
||||
// }
|
||||
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`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转自动登录
|
||||
*/
|
||||
toAuth(snsapiBase,backUrl) {
|
||||
toAuth() {
|
||||
let that = this;
|
||||
this.wechat().then(wx => {
|
||||
location.href = this.getAuthUrl(that.initConfig.appId,snsapiBase,backUrl);
|
||||
location.href = this.getAuthUrl(that.initConfig.appId);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue