企业微信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无用
悬赏问题
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改