diff --git a/services/biz_service.py b/services/biz_service.py index 3172067..aca8d03 100644 --- a/services/biz_service.py +++ b/services/biz_service.py @@ -297,16 +297,20 @@ class BizService(): if not wx_sns_content_text: logger.warning(f'转发文本消息为空不处理 {wx_sns_content_text}') return + if not wxids: logger.warning(f'wxids 空列表不处理 {wxids}') return tasks = [] for wxid in wxids: - k,loginfo=await self.wxchat.get_login_info_by_wxid_async(wxid) - app_id=loginfo.get('appId','') - token_id=loginfo.get('tokenId','') - tasks.append(self.wxchat.send_text_sns_async(token_id, app_id, wx_sns_content_text)) + loginfo=await self.wx_auth_required_time_async(wxid) + if not loginfo: + continue + + app_id=loginfo.get('appId','') + token_id=loginfo.get('tokenId','') + tasks.append(self.wxchat.send_text_sns_async(token_id, app_id, wx_sns_content_text)) await asyncio.gather(*tasks) @@ -317,12 +321,16 @@ class BizService(): if not wx_sns_content_imgs: logger.warning(f'转发图片消息为空不处理 {wx_sns_content_imgs}') return + tasks = [] for wxid in wxids: - k,loginfo=await self.wxchat.get_login_info_by_wxid_async(wxid) - app_id=loginfo.get('appId','') - token_id=loginfo.get('tokenId','') - tasks.append(self.wxchat.upload_send_image_sns_async(token_id, app_id, wx_sns_content_text,wx_sns_content_imgs)) + loginfo=await self.wx_auth_required_time_async(wxid) + if not loginfo: + continue + + app_id=loginfo.get('appId','') + token_id=loginfo.get('tokenId','') + tasks.append(self.wxchat.upload_send_image_sns_async(token_id, app_id, wx_sns_content_text,wx_sns_content_imgs)) await asyncio.gather(*tasks) @@ -347,10 +355,12 @@ class BizService(): tasks = [] for wxid in wxids: - k,loginfo=await self.wxchat.get_login_info_by_wxid_async(wxid) - app_id=loginfo.get('appId','') - token_id=loginfo.get('tokenId','') - tasks.append(self.wxchat.upload_send_video_sns_async(token_id, app_id,wx_sns_content_text,wx_sns_content_video_url,wx_sns_content_thumb_url)) + loginfo=await self.wx_auth_required_time_async(wxid) + if not loginfo: + continue + app_id=loginfo.get('appId','') + token_id=loginfo.get('tokenId','') + tasks.append(self.wxchat.upload_send_video_sns_async(token_id, app_id,wx_sns_content_text,wx_sns_content_video_url,wx_sns_content_thumb_url)) await asyncio.gather(*tasks) @@ -360,11 +370,15 @@ class BizService(): if not wx_sns_content_text: logger.warning(f'转发文本消息为空不处理 {wx_sns_content_text}') return + if not wxid: logger.warning(f'wxid 空不处理 {wxid}') return - k,loginfo=await self.wxchat.get_login_info_by_wxid_async(wxid) + loginfo=await self.wx_auth_required_time_async(wxid) + if not loginfo: + return + app_id=loginfo.get('appId','') token_id=loginfo.get('tokenId','') await self.wxchat.send_text_sns_async(token_id, app_id, wx_sns_content_text) @@ -376,10 +390,14 @@ class BizService(): if not wx_sns_content_imgs: logger.warning(f'转发图片消息为空不处理 {wx_sns_content_imgs}') return + if not wxid: logger.warning(f'wxid 空不处理 {wxid}') return - k,loginfo=await self.wxchat.get_login_info_by_wxid_async(wxid) + + loginfo=await self.wx_auth_required_time_async(wxid) + if not loginfo: + return app_id=loginfo.get('appId','') token_id=loginfo.get('tokenId','') await self.wxchat.upload_send_image_sns_async(token_id, app_id, wx_sns_content_text,wx_sns_content_imgs) @@ -401,10 +419,41 @@ class BizService(): if not wx_sns_content_thumb_url: logger.warning(f'转发视频缩略图消息为空不处理 {wx_sns_content_thumb_url}') return + if not wxid: logger.warning(f'wxid 空不处理 {wxid}') return - k,loginfo=await self.wxchat.get_login_info_by_wxid_async(wxid) + + loginfo=await self.wx_auth_required_time_async(wxid) + if not loginfo: + return + app_id=loginfo.get('appId','') token_id=loginfo.get('tokenId','') await self.wxchat.upload_send_video_sns_async(token_id, app_id,wx_sns_content_text,wx_sns_content_video_url,wx_sns_content_thumb_url) + + async def wx_auth_required_time_async(self,wxid:str)->dict: + if not wxid: + logger.warning(f'wxid 不能为空') + return None + + # 模拟获取登录信息 + k, loginfo = await self.wxchat.get_login_info_by_wxid_async(wxid) + if not loginfo: + logger.warning(f'{wxid} 微信信息不存在') + return None + + login_status = loginfo.get('status', '0') + if login_status != '1': + logger.warning(f'{wxid} 已经离线') + return None + + creation_timestamp = int(loginfo.get('create_at', time.time())) + current_timestamp = time.time() + three_days_seconds = 3 * 24 * 60 * 60 # 三天的秒数 + diff_flag = (current_timestamp - creation_timestamp) >= three_days_seconds + if not diff_flag: + logger.warning(f'{wxid} 用户创建不够三天,不能使用该功能') + return None + return loginfo + \ No newline at end of file