MCPcopy
hub / github.com/smallfawn/QLScriptPublic / dingding_bot

Function dingding_bot

daily/notify.py:198–224  ·  view source on GitHub ↗

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

(title: str, content: str)

Source from the content-addressed store, hash-verified

196
197
198def dingding_bot(title: str, content: str) -> None:
199 """
200 使用 钉钉机器人 推送消息。
201 """
202 if not push_config.get("DD_BOT_SECRET") or not push_config.get("DD_BOT_TOKEN"):
203 return
204 print("钉钉机器人 服务启动")
205
206 timestamp = str(round(time.time() * 1000))
207 secret_enc = push_config.get("DD_BOT_SECRET").encode("utf-8")
208 string_to_sign = "{}\n{}".format(timestamp, push_config.get("DD_BOT_SECRET"))
209 string_to_sign_enc = string_to_sign.encode("utf-8")
210 hmac_code = hmac.new(
211 secret_enc, string_to_sign_enc, digestmod=hashlib.sha256
212 ).digest()
213 sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
214 url = f'https://oapi.dingtalk.com/robot/send?access_token={push_config.get("DD_BOT_TOKEN")}&timestamp={timestamp}&sign={sign}'
215 headers = {"Content-Type": "application/json;charset=utf-8"}
216 data = {"msgtype": "text", "text": {"content": f"{title}\n\n{content}"}}
217 response = requests.post(
218 url=url, data=json.dumps(data), headers=headers, timeout=15
219 ).json()
220
221 if not response["errcode"]:
222 print("钉钉机器人 推送成功!")
223 else:
224 print("钉钉机器人 推送失败!")
225
226
227def feishu_bot(title: str, content: str) -> None:

Callers

nothing calls this directly

Calls 4

printFunction · 0.70
getMethod · 0.45
timeMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected