<Python heuristic automates WeChat push of >

Server sauce

The WeChat open documentation does not provide an easy to use API for things like message push or robot management, but instead uses the Server sauce service push notification.

Server sauce

You just need to register/log in the Server sauce platform, scan the code and bind to the WeChat official account. Yes, the essence of Server sauce is a public account, which can push notification information for you.

After a successful binding, an SCKEY is returned, which is equivalent to an authenticated KEY. In their words, the SCKEY is very important, so please keep it safe and don’t tell anyone. In addition, messages of the same content can only be sent once a minute, and the server only keeps a record of messages for a week.

The specific interface is as follows:

https://sc.ftqq.com/[SCKEY].send

It takes two arguments:

  • text: Message title, the maximum is256Will fill.
  • desp: message content, maximum64Kb, can be empty, supportMarkDown.

PS: Both interfaces are supported
GET
POSTThe request. I don’t think it makes sense, but it does

So you don’t even have to write code to send notifications by typing the API in the browser address bar and passing in the necessary parameters, such as https://sc.ftqq.com/[SCKEY].send? Text = greetings from PI

As expected, soon received a greeting from brother PI

Pythonimplementation

# -*- coding: utf-8 -* # @Time : Note_Enable = True # Construct key sckey = "Scu1218.... 1e9fac5f9b79369b576" # information subject desp = "" ** Hangzhou weather ** \n > 900 degrees, northwest wind force 1, air good 8009, Relative temperature 673%\n > [![hello](https://images.pexels.com/photos/3369569/pexels-photo-3369569.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=126 0)] (https://www.dingtalk.com) \ n > # # # # # # 10 p.m release [weather] (https://www.dingtalk.com) \ n "' message = {" subject" : Class sendMsg (object): def send(self, message): if not notice_enable: lessor of top 1, 2018 Print (" WeChat ") return url = f"https://sc.ftqq.com/{sckey}.send" r = requests. POST (url, data={"text": F '{message["subject"]}', "desp": message["content"]}) if R.tatus_code == requests. CODES.OK: print(" WeChat ") else: Print (" WeChat message failed ") S = sendMsg () s.end (message)

Instead of the browser address bar, we submit one
POSTRequest it, and use it
MarkdownSyntax, greatly enhanced readability.