钉钉小程序免登录(企业内部应用,其他大同小异)

8 篇文章 2 订阅
4 篇文章 0 订阅
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"
}
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值