53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
import requests
|
|
from typing import Optional
|
|
|
|
|
|
class DingAPI():
|
|
def __init__(self):
|
|
self.token = None
|
|
self.url = ''
|
|
|
|
def get_token(self) -> Optional:
|
|
"""
|
|
获取Access Token
|
|
return: token(str)
|
|
"""
|
|
|
|
url = 'https://api.dingtalk.com/v1.0/oauth2/dinga88e3d35525b86ca/token'
|
|
|
|
payload = {
|
|
"client_id": "dingn3de1pyuwkymohhe",
|
|
"client_secret": "qv__egWJnLVXh14_R1rfD_vBi7M8Gzhnk94EJN6puMzsqqpBCP8U7Ow-zA7SV8Rx",
|
|
"grant_type": "client_credentials"
|
|
}
|
|
|
|
response = requests.post(url, json=payload)
|
|
token = response.json().get('access_token')
|
|
|
|
return token
|
|
|
|
|
|
def card_create(self, data):
|
|
"""
|
|
创建并投放卡片
|
|
return: response(dict)
|
|
"""
|
|
url = 'https://api.dingtalk.com/v1.0/card/instances/createAndDeliver'
|
|
|
|
headers = {
|
|
'x-acs-dingtalk-access-token': data["token"],
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
data = {
|
|
"cardTemplateId": "cee2715f-001d-41cb-8fcd-3be18be9fbf5.schema",
|
|
"outTrackId": "",
|
|
"cardData":"",
|
|
"openSpaceId":"dtv1.card//IM_GROUP.4210192048793363",# 场域id
|
|
}
|
|
response = requests.post(url, json=data, headers=headers)
|
|
return response.json()
|
|
|
|
def get_
|
|
|