import requests
import json

def dingmessage():
    webhook = "https://oapi.dingtalk.com/robot/send?access_token=efe407f2a73..."
    header = {
        "Content-Type": "application/json",
        "Charset": "UTF-8"
    }
    # text文本格式
    # message = {
    #     "msgtype": "text",
    #     "at": {
    #         "atMobiles": ["187xxx"],
    #         "isAtAll": False
    #     },
    #     "text": {
    #         "content": "test" #发送的内容
    #     }
    # }
    # markdown文本格式
    message = {
        "msgtype": "markdown",
        "markdown": {
            "title": "短信请求",
            "text": "test @187xxxx"
        },
        "at": {
            # @指定报警人
            "atMobiles": ["187xxxx"],
            "isAtAll": False
        }
    }
    message_json = json.dumps(message)
    print(message_json)
    info = requests.post(url=webhook,data=message_json,headers=header)
    print(info.text)

if __name__=="__main__":
    dingmessage()