In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "Python how to send warning notice to WeCom". In daily operation, I believe many people have doubts about how to send warning notice to WeCom in Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "how to send warning notice to WeCom by Python". Next, please follow the editor to study!
Common alarm methods are: e-mail, phone, SMS, Wechat.
Text messages and phone calls are usually charged (if you have a free one, you can comment and share it), and the email is not so timely, so in the end, I chose Wechat notification.
Wechat here is WeCom, and I have registered a self-employed license before, so I can easily register my own WeCom.
1. New application
Log in to the web version of WeCom (https://work.weixin.qq.com/))
Click App Management-> App-> create App
Upload the logo of the application, enter the application name, and then select the visible range to successfully create an alarm application.
two。 Get Secret
In fact, only two interfaces are used to send alarm requests using Python
Get Token:
Https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={secret}
Send request:
Https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}
As you can see, the most important are corpid and secret:
Corpid: uniquely identify your business
Secret: an application-level key that the program knows which application you want to send to the enterprise.
Corpid can be obtained through my enterprise-> enterprise information.
However, it is relatively troublesome to get secret. Click the previous create application, and click to view secret.
Then click send and it will be sent to your WeCom
Finally, fill in the constants below with corpid and secret.
Import jsonimport datetimeimport requestsCORP_ID = "" SECRET = "" class WeChatPub: s = requests.session () def _ init__ (self): self.token = self.get_token () def get_token (self): url = f "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={SECRET}" rep = self.s.get (url) if rep .status _ code! = 200: print ("request failed.") Return return json.loads (rep.content) ['access_token'] def send_msg (self, content): url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + self.token header = {" Content-Type ":" application/json "} form_data = {" touser ":" @ all " "toparty": "PartyID1 | PartyID2", "totag": "TagID1 | TagID2", "msgtype": "textcard", "agentid": 1000002, "textcard": {"title": "Service exception alarm", "description": content, "url": "URL" "btntxt": "more"}, "safe": 0} rep = self.s.post (url, data=json.dumps (form_data) .encode ('utf-8'), headers=header) if rep.status_code! = 200: print ("request failed.") Return return json.loads (rep.content)
You can then send the message through the send_msg function.
Wechat = WeChatPub () now = datetime.datetime.now () timenow = now.strftime ('% Y% m / d% HV% MV% S') wechat.send_msg (f "{timenow} Aliyun cookie is invalid, please replace the new cookie as soon as possible")
As long as your WeCom does not have the permission to turn off the notification, your phone will pop up this alarm message immediately.
WeCom is docked in a few simple steps, and the real-time alarm function of the mobile phone is realized. WeCom's classmates are recommended to use it.
Of course, there must be more, easier to implement, I just chose one of them.
At this point, the study on "how to send warning notifications to WeCom by Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.