钉钉小程序免登录(企业内部应用)
1.前端获取登录临时凭证
dd.getAuthCode({
success: function(res) {
console.log(res)
let authCode = res.authCode
// 钉钉登录
},
fail: function(err) {}
});
返回值
{
"authCode": "登录临时凭证"
}
2.获取access_token
文档地址
uni.request({
url: 'https://oapi.dingtalk.com/gettoken?appkey=你的APPID&appsecret=你的APPKEY',
method: 'GET',
success: res => {
console.log(res)
let access_token = res.data.access_token
},
fail: res => {
console.log(res);
}
})
返回值
{
"errcode": 0,
"access_token": "96fc7a7axxx",
"errmsg": "ok",
"expires_in": 7200
}
3.通过免登码获取用户信息(userid)
文档地址
uni.request({
url: 'https://oapi.dingtalk.com/user/getuserinfo?access_token=' + access_token + '&code=' + authCode,
method: 'GET',
success: res => {
console.log(res)
let userid = res.data.userid
},
fail: res => {
console.log(res);
}
})
返回值
{
"errcode":0,
"sys_level":0,
"is_sys":false,
"name":"姓名",
"errmsg":"ok",
"deviceId":"0f31ccbfa5c8f15db009629fd2d89117",
"userid":"用户userID"
}
4.根据userID获取用户详情
文档地址
uni.request({
url: 'https://oapi.dingtalk.com/topapi/v2/user/get?access_token=' + access_token,
method: 'POST',
data: {
userid: userid,
language: 'zh_CN'
},
success: res => {
console.log(res)
},
fail: res => {
console.log(res);
}
})
返回值
{
"errcode":0,
"errmsg":"ok",
"result":{
"active":true,
"admin":false,
"avatar":"头像",
"boss":false,
"dept_id_list":[
91489253
],
"dept_order_list":[
{
"dept_id":91489253,
"order":176322471373645512
}
],
"exclusive_account":false,
"hide_mobile":false,
"leader_in_dept":[
{
"dept_id":91489253,
"leader":false
}
],
"mobile":"手机号",
"name":"姓名",
"real_authed":true,
"senior":false,
"state_code":"86",
"title":"",
"unionid":"用户unionid",
"userid":"用户userid"
},
"request_id":"10c0nefqhfsia"
}
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭