由于做这一方面的人少,所以提供的SDK也很少。下面我提供两个比较不错的:
1. github:https://github.com/007gzs/dingtalk-sdk
例子:https://github.com/007gzs/dingtalk-django-example
文档:https://dingtalk-sdk.readthedocs.io/zh_CN/latest/client/index.html
2. github:https://github.com/blackmatrix7/dingtalk-python
3. 钉钉群机器人
github地址:https://github.com/zhuifengshen/DingtalkChatbot
下载:pip install DingtalkChatbot
首先,第一个,可以通过 pip install dingtalk-sdk进行下载安装,然后就可以使用了。在install dingtalk-sdk之前需要pip install cryptography>=0.8.2或者pip install pycrypto>=2.6.1
第二个可以看到下面的简介,需要将项目的dingtalk模块复制到需要使用的项目根目录下,再使用,所以不建议大家在项目中使用。
使用:
1. 开发企业内部应用
from dingtalk import SecretClient, AppKeyClient
E_AppKey = AppKey
E_AppSecret = AppSecret
client = SecretClient(E_AppKey, E_AppSecret) #旧 access_token 获取方式
client = AppKeyClient(E_AppKey, E_AppSecret) #新 access_token 获取方式
# 根据钉钉的userid获取钉钉用户的信息
profile = client.user.get('userid')
# 获取部门列表
dep_list = client.department.list()
# 获取部门详情
dep = client.department.get(dep_id)
然后就是按照文档上面的各个接口来拿到你想要的数据。
2. 第三方企业应用
from dingtalk import ISVClient
suiteKey = 'suiteKey'
suiteSecret = 'suiteSecret'
client = ISVClient(suiteKey, suiteSecret)
corp = client.get_auth_info(corpid) # 根据corpId获取企业授权信息
code = client.get_permanent_code('') # 根据临时授权码获取企业永久授权码
corp_client = client.get_dingtalk_client(corpid) # 根据corpId获取企业的access_token
根据corp_client,按照文档上的接口获取数据。
钉钉群机器人:
github地址:https://github.com/zhuifengshen/DingtalkChatbot
下载:pip install DingtalkChatbot
具体使用方法见GitHub下面的介绍