From 39f25e273c865d9a00fe91e16b6af59200a41b87 Mon Sep 17 00:00:00 2001 From: an-anthony <30309164+an-anthony@users.noreply.github.com> Date: Sat, 22 Apr 2023 14:48:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E8=BE=93=E5=87=BA=E9=95=BF=E5=BA=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/wechat/wechat_com_channel.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/channel/wechat/wechat_com_channel.py b/channel/wechat/wechat_com_channel.py index 229c9cb..b46db4c 100644 --- a/channel/wechat/wechat_com_channel.py +++ b/channel/wechat/wechat_com_channel.py @@ -6,6 +6,8 @@ @file: wechat_com_channel.py """ +import time + from channel.channel import Channel from concurrent.futures import ThreadPoolExecutor from common.log import logger @@ -45,8 +47,21 @@ class WechatEnterpriseChannel(Channel): app.run(host='0.0.0.0', port=_conf.get('port')) def send(self, msg, receiver): - logger.info('[WXCOM] sendMsg={}, receiver={}'.format(msg, receiver)) - self.client.message.send_text(self.AppId, receiver, msg) + # 切片长度 + n = 450 + if len(msg) < n: + logger.info('[WXCOM] sendMsg={}, receiver={}'.format(msg, receiver)) + self.client.message.send_text(self.AppId, receiver, msg) + return + # 分割后的子字符串列表 + chunks = [msg[i:i+n] for i in range(0, len(msg), n)] + # 总消息数 + total = len(chunks) + # 循环发送每个子字符串 + for i, chunk in enumerate(chunks): + logger.info('[WXCOM] sendMsg={}, receiver={}, page_number={}, page_total={}'.format(msg, chunk, i+1, total)) + self.client.message.send_text(self.AppId, receiver, chunk) + time.sleep(1) # 用延迟的方式使微信插件的输出顺序正常 def _do_send(self, query, reply_user_id): try: