python--向釘釘群傳送訊息(親測可用)
阿新 • • 發佈:2020-08-28
向釘釘群傳送文字訊息
def sendDingDing(self,text): print(text) headers = {'Content-Type': 'application/json'} webhook = "https://oapi.dingtalk.com/robot/send?access_token="+self.apps.access_token data = { "msgtype": "text", "text": { "content": text+'\n' },"at": { "atMobiles": [ ], "isAtAll": False } } x = requests.post(url=webhook, data=json.dumps(data), headers=headers)
向釘釘群傳送連結訊息
mport json import requests def send_msg(url): headers = {'Content-Type': 'application/json;charset=utf-8'} data= { "msgtype": "link", "link": { "text": '點我跳轉百度', "title": "點我", "picUrl": "圖片連結", # 可以加,可以不加 "messageUrl": "https://www.baidu.com" }, } r = requests.post(url,data = json.dumps(data),headers=headers) return r.textif __name__ == '__main__': url = 'https://oapi.dingtalk.com/robot/send?access_token={}'.format() print(send_msg(url))