本例只只包含代码,具体步骤可稳步至另外一篇博客查看
/Huangfei10086/article/details/107713060
将上篇文章中的代码换成如下代码即可
脚本如下:
#!/usr/bin/python3.6#_*_coding:utf-8 _*_#auther:Fei Huangimport requests,sys,json,timeimport urllib3urllib3.disable_warnings()def SendMessageURL(User,Subject,Messages):#webhook换成你机器人的keyURL = "https://qyapi./cgi-bin/webhook/send?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxx"HEADERS = {"Content-Type": "application/json"}Data = {"msgtype": "markdown","markdown": {"content": "# 故障 \n <font color=\"warning\">%s</font> \n <font color=\"info\">%s</font> \n <@%s>"% (Subject,Messages,User)#"mentioned_list" : [User],#"content": \<font color="warning">Subject</font> \n Messages,#"mentioned_list" :[User],#"mentioned_list" :[User,"@all"],#"mentioned_mobile_list" : ["13800000000","@all"]}}r = requests.post(url=URL, headers=HEADERS, json=Data, verify=False)print(r.json())if __name__ == "__main__":SENDTO = str(sys.argv[1])SUBJECT = str(sys.argv[2])MESSAGE = str(sys.argv[3])Status = str(SendMessageURL(SENDTO,SUBJECT,MESSAGE))print (Status)