钉钉对接通讯录--自己笔记用

对接钉钉通讯录

打开钉钉开发的网址

https://open-dev.dingtalk.com/
在里面要创建好自己的新小程序 然后点击到
在这里插入图片描述

用AppKey 和AppSecret 去获取token

打开下面的链接跳转到能把帮你生成代码api的网址

https://open-dev.dingtalk.com/apiExplorer#/?devType=org&api=dingtalk.oapi.v2.user.create

在这里插入图片描述

代码里面的操作

DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        OapiGettokenRequest req = new OapiGettokenRequest();
        req.setAppkey("Appkey");
        req.setAppsecret("Appsecret");
        req.setHttpMethod("GET");
        OapiGettokenResponse rsp = client.execute(req);
        String token = rsp.getAccessToken();

想要本地代码能获取到下面通讯录的信息需要做一个内网穿透

可以用下面的gitclone工具;

git clone https://github.com/open-dingtalk/pierced.git

必须下载后用 cmd 打开;
在这里插入图片描述

ding.exe -config=./ding.cfg -subdomain=127.0.0.1 9090

-subdomain= 后面加的是你的域名 + 端口号

在这里插入图片描述
到这里就成功一半啦 然后再去这个页面配置一下你的本地ip,把页面的服务器出口ip写成你的电脑ip。下面两个暂时还没弄懂干嘛的。。。以后在修改
在这里插入图片描述

要在程序里面添加权限才能对通讯录进行操作

在这里插入图片描述

然后就能用获取到的token去做想做的一系列自己系统对钉钉的操作了

在这里插入图片描述
1:每次调用钉钉接口时,必须要传入access_token用来验证,7200毫秒会更新一次access_token

2:先查询所有部门的id,通过部门id才可以查询到部门里面的userid和name。

3: 通过userid,就能对自己系统人员进行一系列的操作啦!


版权声明:本文为sutimber原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。