<Python heuristics to automate the push of >

If you wish to receive notifications via a pin (note that it is not a pin mail, all mail operations were covered in the previous section)

Set up a swarm of robots on the spike, resulting from the spike individual permissions.

If it is enterprise authority, please refer to it in detail
https://developers.dingtalk.com/document

  • Add aThe customRobot and specifiedgroup
  • To get aWebhookaddress
  • For security reasons, addThe signature, i.e.,secret

According to the
https://developers.dingtalk.com/document/app/custom-robot-access?spm=ding_open_doc.document.0.0.6d9d28e1ji2ImR#topic-202 6027use
PythonRealize a robot push function

The textpush

# -*- coding: utf-8 -*- import requests import json import time import hmac import hashlib import base64 import urllib.parse def dingMessage(): timestamp = str(round(time.time() * 1000)) secret = 'SEC21022... cf06a65a761c86eb4027b' secret_enc = secret.encode('utf-8') string_to_sign = '{}\n{}'.format(timestamp, secret) string_to_sign_enc = string_to_sign.encode('utf-8') hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) print(timestamp) Print (sign) # requested URL, WebHook address WebHook = f "https://oapi.dingtalk.com/robot/send?access_token=33576dfcb4... 7BC0EC08354CC181A &timestamp={timestamp}&sign={sign}" # build request header ={" content-type ": "application/json", "Charset": "MsgType ": "text", "text": {"content": f" @137.... 97091 {Tex}} ", whether # todo @ all "at" : {" atMobiles: "[]" 137... 7091 ", "isAtAll" : Message_json = json.dumps(message) # info = point.post (url=webhook, request) Print (info.text) if __name__ == "__main__": DingMessage ()

What did

  • secretRobot signature
  • webhookThe robotAPIAddress, parameter composition:timestamp(timestamp)sign(sha256encryptedbase64Signature generated by encoding)
  • texText information
  • messageSubject object, select@The person concerned (based on cell phone number here)

markdownpush

# -*- coding: utf-8 -*- import json import requests def dingmessage(): import time import hmac import hashlib import base64 import urllib.parse timestamp = str(round(time.time() * 1000)) secret = 'SEC21022b79.... 9cf06a65a761c86eb4027b' secret_enc = secret.encode('utf-8') string_to_sign = '{}\n{}'.format(timestamp, secret) string_to_sign_enc = string_to_sign.encode('utf-8') hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) print(timestamp) Print (sign) # requested URL, WebHook address WebHook = f "https://oapi.dingtalk.com/robot/send?access_token=33576dfc... 4800D577BC0EC08354CC181A &timestamp={timestamp}&sign={sign}" # Build request header ={"Content-Type": "application/json", "Charset": "UTF-8" } message = { "msgtype": "markdown", # "text": { # "content": f" @137... 97091 {Tex} "#}," markdown ": {" title" : "hangzhou weather", "text" : "# # # # @ 155 hangzhou weather... 773 \n> 900 degrees, NW force 1, air good 8009, Relative temperature 673%\n> [![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)](https://developers.dingtalk.com/do Cument /app/send-normal-messages)\n> ###### 10:20 post [weather](s)\n "}, # todo @ all "at": { "atMobiles": [ "15....773" ], "isAtAll": Message_json = json.dumps(message) # info = point.post (url=webhook, request) Print (info.text) if __name__ == "__main__": DingMessage ()

Web pagelink

# -*- coding: utf-8 -*- import json import requests def dingmessage(): import time import hmac import hashlib import base64 import urllib.parse timestamp = str(round(time.time() * 1000)) secret = 'SEC21022b792577.... 8639cf06a65a761c86eb4027b' secret_enc = secret.encode('utf-8') string_to_sign = '{}\n{}'.format(timestamp, secret) string_to_sign_enc = string_to_sign.encode('utf-8') hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) print(timestamp) Print (sign) # requested URL, WebHook address WebHook = f "https://oapi.dingtalk.com/robot/send?access_token=33576dfcb4... 800d577bc0ec08354cc181a&timestamp={timestamp}&sign={sign}" header = { "Content-Type": "application/json", "Charset": "Utf-8"} message = {" msgType ": "link", "link": {"text": "This new version of the upcoming release, the founder xx calls it mangrove. Before that, whenever faced with a major upgrade, product managers would take a code name appropriate to the occasion, this time, why mangrove ", "title": "the era of the moving forward ", "picUrl": "", "" messageUrl": "https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srci d=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nett Ype = WIFI "}, whether # todo @ all "at" : {" atMobiles ": [15..." 8773 "], "isAtAll" : False } } message_json = json.dumps(message) info = requests.post(url=webhook, data=message_json, headers=header) print(info.text) if __name__ == "__main__": dingmessage()

cardpush

The overall jumpActionCardtype

# -*- coding: utf-8 -*- import json import requests def dingmessage(): import time import hmac import hashlib import base64 import urllib.parse timestamp = str(round(time.time() * 1000)) secret = 'SEC21022b7925.... 064668639cf06a65a761c86eb4027b' secret_enc = secret.encode('utf-8') string_to_sign = '{}\n{}'.format(timestamp, secret) string_to_sign_enc = string_to_sign.encode('utf-8') hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) print(timestamp) Print (sign) # requested URL, WebHook address WebHook = f "https://oapi.dingtalk.com/robot/send?access_token=33576dfcb... 4800d577bc0ec08354cc181a&timestamp={timestamp}&sign={sign}" header = { "Content-Type": "application/json", "Charset": "UTF-8" } message = { "msgtype": "actionCard", "actionCard": { "text": "! [screenshot] (https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \ n \ n # # # # 20 years ago to create jobs apple cafe \ n \ n The design of Apple Store is changing from the original feeling of full technology to life, which can be traced back to Apple's plan of building a coffee shop 20 years ago. "0" and "singleTitle", "read the full text", "singleURL" : "https://www.dingtalk.com/"}, whether # todo @ all "at" : {" atMobiles ": [ "155....8773" ], "isAtAll": False } } message_json = json.dumps(message) info = requests.post(url=webhook, data=message_json, headers=header) print(info.text) if __name__ == "__main__": dingmessage()

Independent jumpActionCardtype

# -*- coding: utf-8 -*- import json import requests def dingmessage(): import time import hmac import hashlib import base64 import urllib.parse timestamp = str(round(time.time() * 1000)) secret = 'SEC21022b792..... 39cf06a65a761c86eb4027b' secret_enc = secret.encode('utf-8') string_to_sign = '{}\n{}'.format(timestamp, secret) string_to_sign_enc = string_to_sign.encode('utf-8') hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) print(timestamp) Print (sign) # requested URL, WebHook address WebHook = f "https://oapi.dingtalk.com/robot/send?access_token=33576dfcb4... 0ec08354cc181a&timestamp={timestamp}&sign={sign}" header = { "Content-Type": "application/json", "Charset": "UTF-8" } message = { "msgtype": "actionCard", "actionCard": { "text": "! [screenshot] (https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \ n \ n # # # # 20 years ago to create jobs apple cafe \ n \ n The design of Apple Store is changing from the original full of science and technology to the lifestyle, and the trend of the lifestyle can be traced back to Apple's plan of building a cafe 20 years ago. "0" and "btnOrientation" : "1", "BTNS" : [{" title ":" content is good ", "an actionURL that was" : "https://www.dingtalk.com/"}, {" title ": "Not interested", "an actionURL that was" : "https://www.dingtalk.com/"}}], whether # todo @ all "at" : {" atMobiles ": [ "155....8773" ], "isAtAll": False } } message_json = json.dumps(message) info = requests.post(url=webhook, data=message_json, headers=header) print(info.text) if __name__ == "__main__": dingmessage()

These are the types of Swarm Robot Notifications.

In a word, nail robot push is a very good choice, enough to deal with all kinds of scenarios in daily work (regular reminder, threshold alarm, event notification, etc.)