#coding:utf-8import requestsimport jsondef dingmessage():# 请求的URL,WebHook地址 webhook = "https://oapi.dingtalk.com/robot/send?access_token=????"#构建请求头部 header = { "Content-Type": "application/json", "Charset": "UTF-8"}#构建请求数据 # tex = "#上班注意安全,不要迟到" message = { # Text 格式 ... # "msgtype": "markdown", # "markdown": { # "content": tex # }, # "at": { # "isAtAll": True # } # { # markdown 格式 ... "msgtype": "markdown", "markdown": { "title":"杭州天气", "text": "#### 杭州天气 @156xxxx8827\n" + "> 9度,西北风1级,空气良89,相对温度73%\n\n" + "> \n" + "> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n" }, "at": { "atMobiles": [ "156xxxx8827", "189xxxx8325" ], "isAtAll": True } }#对请求的数据进行json封装 message_json = json.dumps(message)#发送请求 info = requests.post(url=webhook,data=message_json,headers=header)#打印返回的结果 print(info.text)if __name__=="__main__": dingmessage()