MCPcopy Create free account
hub / github.com/MoMingRose/QLAutomateTasks / dingding_bot

Function dingding_bot

notify.py:181–208  ·  view source on GitHub ↗

使用 钉钉机器人 推送消息。

(title: str, content: str)

Source from the content-addressed store, hash-verified

179
180
181def dingding_bot(title: str, content: str) -> None:
182 """
183 使用 钉钉机器人 推送消息。
184 """
185 if not push_config.get("DD_BOT_SECRET") or not push_config.get("DD_BOT_TOKEN"):
186 print("钉钉机器人 服务的 DD_BOT_SECRET 或者 DD_BOT_TOKEN 未设置!!\n取消推送")
187 return
188 print("钉钉机器人 服务启动")
189
190 timestamp = str(round(time.time() * 1000))
191 secret_enc = push_config.get("DD_BOT_SECRET").encode("utf-8")
192 string_to_sign = "{}\n{}".format(timestamp, push_config.get("DD_BOT_SECRET"))
193 string_to_sign_enc = string_to_sign.encode("utf-8")
194 hmac_code = hmac.new(
195 secret_enc, string_to_sign_enc, digestmod=hashlib.sha256
196 ).digest()
197 sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
198 url = f'https://oapi.dingtalk.com/robot/send?access_token={push_config.get("DD_BOT_TOKEN")}&timestamp={timestamp}&sign={sign}'
199 headers = {"Content-Type": "application/json;charset=utf-8"}
200 data = {"msgtype": "text", "text": {"content": f"{title}\n\n{content}"}}
201 response = requests.post(
202 url=url, data=json.dumps(data), headers=headers, timeout=15
203 ).json()
204
205 if not response["errcode"]:
206 print("钉钉机器人 推送成功!")
207 else:
208 print("钉钉机器人 推送失败!")
209
210
211def feishu_bot(title: str, content: str) -> None:

Callers

nothing calls this directly

Calls 1

printFunction · 0.85

Tested by

no test coverage detected