企业微信消息实时推送
🤔功能概述
腾讯提供了一个企业微信,主要是给企业来使用,可以进行办公以及可以扩展企业的一些其他服务。企业微信不是只有企业可以注册,个人也可以注册,只不过个人注册后无法认证,可能会有一些企业服务无法使用,我们这里只是使用其发送消息服务,所以基本上够用。
这边我们是基于微信企业号编写一套Python的代码接口,用于来给自己微信发送消息,可以应用于监控等场景,利用微信的服务免费满足自己应用。
😼企业微信应用消息配置说明
优点:
- 一次配置,持续使用
- 配置好以后,只需要微信就能收消息,不再需要安装企业微信客户端
PS:消息接口无需认证即可使用,个人用微信就可以注册
👋🏻开通流程
具体操作流程见文末文档链接
🤗Python代码例子
import json,requests
def send_to_wecom(text,wecom_cid,wecom_aid,wecom_secret,wecom_touid='@all'):
get_token_url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={wecom_cid}&corpsecret={wecom_secret}"
response = requests.get(get_token_url).content
access_token = json.loads(response).get('access_token')
print(access_token)
if access_token and len(access_token) > 0:
send_msg_url = f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}'
data = {
"touser":wecom_touid,
"agentid":wecom_aid,
"msgtype":"text",
"text":{
"content":text
},
"duplicate_check_interval":600
}
response = requests.post(send_msg_url,data=json.dumps(data)).content
return response
else:
return False
send_to_wecom("推送测试\r\n测试换行", "xxx", "1000002", "xxxx");
⭐相关链接
官方开发文档:
https://work.weixin.qq.com/api/doc/90000/90135/90236
详细教程文档:
本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可。