1.基础方法
把url的参数部分转化成json对象
export const parseURLParam = (url = window.location.href) => {
if (url.indexOf('?') < 0) {
return {}
} else {
if (url.slice(url.indexOf('?') + 1) === '') {
return {}
}
}
try {
let hash
let myJson = {}
let hashes = url.slice(url.indexOf('?') + 1).split('&')
for (let i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=')
myJson[hash[0]] = hash[1]
}
return myJson
} catch (e) {
return {}
}
}
1.钉钉环境获取code 方式
dd.ready(() => {
dd.runtime.permission.requestAuthCode({
corpId: ’ ', // 企业id
onSuccess: (info) => {
this.code = info.code // 通过该免登授权码可以获取用户身份
this.goLogin()
},
onFail: function (err) { alert(err) }
})
})
2.微信企业微信获取方式
parseURLParam()[code]
3.获取state
parseURLParam()[state]
4.调用登录接口
5.已经授权登录到首页否则返回openId 绑定授权
// 401关闭页面
if (isDd !== ‘notInDingTalk’) {
dd.biz.navigation.close()
} else {
wx.closeWindow()
}