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 send_message(self, message): data = { "msgtype": "text", "text": { "content": message } } headers = { 'Content-Type': 'application/json' } response = requests.post(self.url, json=data, headers=headers) return response.status_code