(title, content)
| 246 | |
| 247 | # 企业微信 APP 推送 |
| 248 | def wecom_app(title, content): |
| 249 | try: |
| 250 | if not QYWX_AM: |
| 251 | print("QYWX_AM 并未设置!!\n取消推送") |
| 252 | return |
| 253 | QYWX_AM_AY = re.split(',', QYWX_AM) |
| 254 | if 4 < len(QYWX_AM_AY) > 5: |
| 255 | print("QYWX_AM 设置错误!!\n取消推送") |
| 256 | return |
| 257 | corpid = QYWX_AM_AY[0] |
| 258 | corpsecret = QYWX_AM_AY[1] |
| 259 | touser = QYWX_AM_AY[2] |
| 260 | agentid = QYWX_AM_AY[3] |
| 261 | try: |
| 262 | media_id = QYWX_AM_AY[4] |
| 263 | except: |
| 264 | media_id = '' |
| 265 | wx = WeCom(corpid, corpsecret, agentid) |
| 266 | # 如果没有配置 media_id 默认就以 text 方式发送 |
| 267 | if not media_id: |
| 268 | message = title + '\n\n' + content |
| 269 | response = wx.send_text(message, touser) |
| 270 | else: |
| 271 | print('企业微信服务启动') |
| 272 | response = wx.send_mpnews(title, content, media_id, touser) |
| 273 | if response == 'ok': |
| 274 | print('推送成功!') |
| 275 | else: |
| 276 | print('推送失败!错误信息如下:\n', response) |
| 277 | except Exception as e: |
| 278 | print(e) |
| 279 | |
| 280 | class WeCom: |
| 281 | def __init__(self, corpid, corpsecret, agentid): |
no test coverage detected