用python實現的釘釘後臺開發

由於做這一方面的人少,所以提供的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下面的介紹

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章