def ding_msg_text(self, txt_body): try: logging.debug('Sending ding message ....') E_AppKey = 'dingl4ffi9i8c4zl2m41' E_AppSecret = 'VZ7L2ue_Fasulcv40CfrmBdLmKLDAgwLWQPDEr1Fd3PlB2TM5caVVjIGpwbYlaRr' AgentId = '300734750' CorpId = 'ding1876ffde971a32eb' client = AppKeyClient(CorpId, E_AppKey, E_AppSecret) # 新 access_token 获取方式 headers = {} data = {} url = 'https://oapi.dingtalk.com/media/upload?access_token=' + client.access_token + '&type=file' """ :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. """ t1 = message.TextBody(txt_body) # keep touch sel_chat_id = 'chat1fa6ffa170a762c040b5f0cc042ade7c' # keep touch sel_chat_id = 'chat596d30e5625ae08b5fd85ebe29b00091' # IT 周会 sel_chat_id = 'chat8b63a87cf13980d9ca1e294b946d2c4f' # 财务群 sel_chat_id = 'chat90c88f718769057f51ca51311cc1c9bf' # 陈 张 测试群 sel_chat_id = 'chat9e26746e4b1020e41bd231a270b43ee3' # 管理群 client.chat.send(sel_chat_id, t1) logging.debug('Ding message has been sent ....') except Exception as ex: logging.error(str(ex))
def ding_msg(self, file_name, txt_body): try: logging.debug('Sending ding message ....') E_AppKey = 'dingl4ffi9i8c4zl2m41' E_AppSecret = 'VZ7L2ue_Fasulcv40CfrmBdLmKLDAgwLWQPDEr1Fd3PlB2TM5caVVjIGpwbYlaRr' AgentId = '300734750' CorpId = 'ding1876ffde971a32eb' client = AppKeyClient(CorpId, E_AppKey, E_AppSecret) # 新 access_token 获取方式 headers = {} data = {} url = 'https://oapi.dingtalk.com/media/upload?access_token=' + client.access_token + '&type=file' """ :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. """ data['media'] = (file_name, open(r'%s' % file_name, 'rb').read()) encode_data = encode_multipart_formdata(data) data = encode_data[0] headers['Content-Type'] = encode_data[1] r = requests.post(url, headers=headers, data=data) k = json.loads(r.text) t1 = message.TextBody(txt_body) t2 = message.FileBody(k.get('media_id')) # keep touch sel_chat_id = 'chat1fa6ffa170a762c040b5f0cc042ade7c' # keep touch sel_chat_id = 'chat596d30e5625ae08b5fd85ebe29b00091' # IT 周会 sel_chat_id = 'chat8b63a87cf13980d9ca1e294b946d2c4f' # 财务群 sel_chat_id = 'chatcc42fa7d5b85ba68c6ff88467a3b6dd4' # 客服&生产 client.chat.send(sel_chat_id, t1) client.chat.send(sel_chat_id, t2) logging.debug('Ding message has been sent ....') except Exception as ex: logging.error(str(ex))
# encoding: utf-8 from __future__ import absolute_import, unicode_literals import redis from apiview import utility from django.conf import settings from dingtalk import SecretClient, AppKeyClient from dingtalk.storage.kvstorage import KvStorage from . import models redis_client = redis.Redis.from_url(settings.REDIS_DINGTALK_URL) client = AppKeyClient(settings.DINGTALK_CORP_ID, settings.DINGTALK_APP_KEY, settings.DINGTALK_APP_SECRET) def get_department_ids(proced=set(), parent_id=None): ret = set() if parent_id is None: scopes = client.user.auth_scopes() parent_id = scopes.get('auth_org_scopes', {}).get('authed_dept', []) if isinstance(parent_id, (list, tuple)): for pid in parent_id: ret.update(get_department_ids(proced, pid)) return ret if parent_id in proced:
#https://dingtalk-sdk.readthedocs.io/zh_CN/latest/client/index.html import dingtalk from dingtalk import AppKeyClient corp_id='dingf14485c1fcff68a3' app_key='dingnfwjn4hwrvhjatx5' app_secret='PrHR2J9mWioD8tC9E2-7SooZEMiECmZ_fMtCzsatvDuq6HGTg49Gu8J4tflfKvJT' #client = SecretClient('corp_id', 'secret') # 旧 access_token 获取方式 client = AppKeyClient(corp_id, app_key, app_secret) # 新 access_token 获取方式 user = client.user.get('100681') departments = client.department.list() b=dingtalk.client.api.User(client) bb=b.get_dept_member(54268940) ccc= print(bb) #print(user) a=dingtalk.client.api.Department(client).get(54286667) a=dingtalk.client.api.Department(client).list() # a= # # # # #
from __future__ import absolute_import, unicode_literals import redis from apiview import utility from django.conf import settings from dingtalk import SecretClient, AppKeyClient from dingtalk.storage.kvstorage import KvStorage from . import models redis_client = redis.Redis.from_url(settings.REDIS_DINGTALK_URL) if settings.DINGTALK_USE_APP_KEY: client = AppKeyClient(settings.DINGTALK_CORP_ID, settings.DINGTALK_APP_KEY, settings.DINGTALK_APP_SECRET, settings.DINGTALK_TOKEN, settings.DINGTALK_AES_KEY, KvStorage(redis_client)) else: client = SecretClient(settings.DINGTALK_CORP_ID, settings.DINGTALK_CORP_SECRET, settings.DINGTALK_TOKEN, settings.DINGTALK_AES_KEY, KvStorage(redis_client)) def get_department_ids(proced=set(), parent_id=None): ret = set() if parent_id is None: scopes = client.user.auth_scopes() parent_id = scopes.get('auth_org_scopes', {}).get('authed_dept', [])
from dingtalk import SecretClient, AppKeyClient # 旧 access_token 获取方式 #client = SecretClient('ding80f082a716941ab235c2f4657eb6378f', '1040330141093c05b09b12ca4712fea8') client = AppKeyClient('ding80f082a716941ab235c2f4657eb6378f', 'dingzxe9guswfsidedvv', 'myajd8byuS97KqK3Qy2wRn3c4WRqsAHMFWSpEdMl9svESO4JkrQtNN93g-2FsWJZ') # 新 access_token 获取方式 print(client.get_access_token().access_token) users = client.user.list(1) print(users) departments = client.department.list(fetch_child=True) print(departments)
import conf from dingtalk import AppKeyClient config = getattr(conf, 'DINGTALK', {}) client = AppKeyClient(config['corp_id'], config['app_key'], config['app_secret'])