通过 企业微信 APP 推送消息。
(title: str, content: str)
| 476 | |
| 477 | |
| 478 | def wecom_app(title: str, content: str) -> None: |
| 479 | """ |
| 480 | 通过 企业微信 APP 推送消息。 |
| 481 | """ |
| 482 | if not push_config.get("QYWX_AM"): |
| 483 | return |
| 484 | QYWX_AM_AY = re.split(",", push_config.get("QYWX_AM")) |
| 485 | if 4 < len(QYWX_AM_AY) > 5: |
| 486 | print("QYWX_AM 设置错误!!") |
| 487 | return |
| 488 | print("企业微信 APP 服务启动") |
| 489 | |
| 490 | corpid = QYWX_AM_AY[0] |
| 491 | corpsecret = QYWX_AM_AY[1] |
| 492 | touser = QYWX_AM_AY[2] |
| 493 | agentid = QYWX_AM_AY[3] |
| 494 | try: |
| 495 | media_id = QYWX_AM_AY[4] |
| 496 | except IndexError: |
| 497 | media_id = "" |
| 498 | wx = WeCom(corpid, corpsecret, agentid) |
| 499 | # 如果没有配置 media_id 默认就以 text 方式发送 |
| 500 | if not media_id: |
| 501 | message = title + "\n\n" + content |
| 502 | response = wx.send_text(message, touser) |
| 503 | else: |
| 504 | response = wx.send_mpnews(title, content, media_id, touser) |
| 505 | |
| 506 | if response == "ok": |
| 507 | print("企业微信推送成功!") |
| 508 | else: |
| 509 | print("企业微信推送失败!错误信息如下:\n", response) |
| 510 | |
| 511 | |
| 512 | class WeCom: |
nothing calls this directly
no test coverage detected