You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
import config from '../../config.js';
|
|
import request from '../request.js';
|
|
import common from '../common.js';
|
|
let h5 = new Object()
|
|
|
|
|
|
/*
|
|
* 微信网页授权
|
|
* 2020-11-23
|
|
*/
|
|
h5.getToken = function() {
|
|
let user_id = uni.getStorageSync('user_id')
|
|
let access_token = uni.getStorageSync('access_token')
|
|
return new Promise((resolve, reject) => {
|
|
if (!access_token) {
|
|
request.getData('base/h5/api/Auth/getToken', {
|
|
user_id: user_id
|
|
}).then(res => {
|
|
if (res.code === 0) {
|
|
uni.setStorageSync('user_id', res.data.user_id)
|
|
uni.setStorageSync('access_token', res.data.access_token)
|
|
uni.setStorageSync('access_token_expire_time', res.data.access_token_expire_time)
|
|
|
|
resolve({
|
|
user_id: uni.getStorageSync('user_id'),
|
|
access_token: uni.getStorageSync('access_token'),
|
|
})
|
|
console.log('生产环境刚获得 缓存user_id = ' + uni.getStorageSync(
|
|
'user_id'))
|
|
} else {
|
|
console.log(res)
|
|
reject()
|
|
}
|
|
})
|
|
} else {
|
|
resolve({
|
|
user_id: uni.getStorageSync('user_id'),
|
|
})
|
|
console.log('生产环境 缓存user_id = ' + uni
|
|
.getStorageSync('user_id'))
|
|
}
|
|
|
|
})
|
|
}
|
|
|
|
export default h5
|