diff --git a/app.py b/app.py index 1e37259..fb34887 100644 --- a/app.py +++ b/app.py @@ -275,7 +275,7 @@ class WechatThreadManager: self.add_group_member_as_friend_task_threads = {} # 自动加好友线程 - self.add_contacts_threads = {} + self.add_contacts_worker_threads = {} self.wxchat=gewe_chat.wxchat diff --git a/resources/contacts_resources.py b/resources/contacts_resources.py index 55f9b60..6445636 100644 --- a/resources/contacts_resources.py +++ b/resources/contacts_resources.py @@ -59,7 +59,26 @@ class GetFriendsInfoResource(Resource): def post(self): req = request.get_json() wxid = req.get("wxid") - cache=self.wxchat.get_contacts_brief_from_cache(wxid) - # cache_str=redis_helper.redis_helper.get_hash_field(f'__AI_OPS_WX__:CONTACTS_BRIEF:{wxid}','data') - # cache = json.loads(cache_str) if cache_str else [] - return jsonify(cache) + cache = req.get("cache",True) + _,loginfo=utils.get_login_info_by_wxid(wxid) + token_id=loginfo.get('tokenId') + app_id=loginfo.get('appId') + + if cache: + cache=self.wxchat.get_contacts_brief_from_cache(wxid) + # cache_str=redis_helper.redis_helper.get_hash_field(f'__AI_OPS_WX__:CONTACTS_BRIEF:{wxid}','data') + # cache = json.loads(cache_str) if cache_str else [] + return jsonify(cache) + else: + ret,msg,contacts_list=self.wxchat.fetch_contacts_list(token_id,app_id) + if ret!=200: + response=jsonify({ + 'code':ret, + 'message':msg + }) + response.status_code=ret + return response + friend_wxids = [c for c in contacts_list['friends'] if c not in ['fmessage', 'medianote','weixin','weixingongzhong']] # 可以调整截取范围 + data=self.wxchat.save_contacts_brief_to_cache(token_id, app_id, wxid, friend_wxids) + print(f'{wxid}获取实时好友信息') + return jsonify(data)