企业微信pc版的栏目中不定时会推送信息,这个信息为文本,如何接收信息就保存文本。
3条回答 默认 最新
- 歇歇 2022-05-23 22:02关注
接受信息
@app.route('/blackcat/v1/receive_task', methods=['POST', 'GET']) def receive(): try: auth_verify = AuthVerify() if request.method == "POST": msg_signature = request.args.get('msg_signature') timestamp = request.args.get('timestamp') nonce = request.args.get('nonce') request_data = request.data param = auth_verify.verifi_content(msg_signature, timestamp, nonce, request_data) submit_task_receive.delay(param) if request.method == "GET":
建立一个对应消息处理机制,即收到什么信息,做什么处理
如发送消息
可用下面代码
发送信息#! /usr/bin/env python # -*- coding: UTF-8 -*- import requests, sys class SendWeiXinWork(): def __init__(self): self.CORP_ID = "xxx" # 企业号的标识 self.SECRET = "xxx" # 管理组凭证密钥 self.AGENT_ID = xxx # 应用ID self.token = self.get_token() def get_token(self): url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" data = { "corpid": self.CORP_ID, "corpsecret": self.SECRET } req = requests.get(url=url, params=data) res = req.json() if res['errmsg'] == 'ok': return res["access_token"] else: return res def send_message(self, to_user, content): url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s" % self.token data = { # "touser": to_user, # 发送个人就填用户账号 "toparty": to_user, # 发送组内成员就填部门ID "msgtype": "text", "agentid": self.AGENT_ID, "text": {"content": content}, "safe": "0" } req = requests.post(url=url, json=data) res = req.json() if res['errmsg'] == 'ok': print("send message sucessed") return "send message sucessed" else: return res if __name__ == '__main__': SendWeiXinWork = SendWeiXinWork() SendWeiXinWork.send_message("2", "测试a")
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 保护模式-系统加载-段寄存器