关于uniapp授权以及参数截取
const _this = this
const {
code
} = _this.getCode(window.location.href)
this.showCode = code
if (code) {
uni.post('/juhuimp/wxPublicAuth', {
code: code
}).then((res) => {
if (res.status == '200') {
if (res.data.token) {
const _customerOpenId = res.data.userOpenId
app.globalData.userOpenId = _customerOpenId
app.globalData.token = res.data.token
uni.getStorage({
key: 'activityId',
success: function(resGetStorage) {
const _activityId = resGetStorage.data.split('?')[1].split(
'=')[1].split('#')[0]
_this.placeActiveList(_customerOpenId, _activityId)
}
});
}
}
}).catch(err => {
console.log(err, 'ooooo')
uni.showToast({
title: '获取OpenId失败',
icon: 'none'
})
})
} else {
uni.setStorage({
key: 'activityId',
data:window.location.href
});
let userInfoCodeUrl =
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${host}&response_type=code&scope=snsapi_base&state=STATE#connect_redirect=1#wechat_redirect`
window.location.href = userInfoCodeUrl
}
getCode(appletUrl) {
const code = appletUrl.split('?')[1]
if (!code) return {}
const obj = {}
code.split('&').forEach(item => {
const arr = item.split('=')
obj[arr[0]] = arr[1]
})
return obj
},