Explorar el Código

实时好友列表和群列表

develop
H Vs hace 1 mes
padre
commit
f7d9c03afa
Se han modificado 2 ficheros con 24 adiciones y 5 borrados
  1. +1
    -1
      app.py
  2. +23
    -4
      resources/contacts_resources.py

+ 1
- 1
app.py Ver fichero

@@ -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


+ 23
- 4
resources/contacts_resources.py Ver fichero

@@ -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)

Cargando…
Cancelar
Guardar