|
@@ -764,26 +764,43 @@ class GeWeChatCom: |
|
|
hash_key = f"__AI_OPS_WX__:CONTACTS_BRIEF:{wxid}" |
|
|
hash_key = f"__AI_OPS_WX__:CONTACTS_BRIEF:{wxid}" |
|
|
|
|
|
|
|
|
# 获取缓存中的数据 |
|
|
# 获取缓存中的数据 |
|
|
# cache_str = redis_helper.redis_helper.get_hash_field(hash_key, "data") |
|
|
|
|
|
# cache = json.loads(cache_str) if cache_str else [] |
|
|
|
|
|
cache=[] |
|
|
|
|
|
|
|
|
|
|
|
# 缓存为空,分批处理 contacts_wxids |
|
|
|
|
|
batch_size = 100 |
|
|
|
|
|
for i in range(0, len(contacts_wxids), batch_size): |
|
|
|
|
|
batch = contacts_wxids[i:i + batch_size] |
|
|
|
|
|
friends_brief = self.get_brief_info(token_id, app_id, batch) |
|
|
|
|
|
|
|
|
cache_str = redis_helper.redis_helper.get_hash_field(hash_key, "data") |
|
|
|
|
|
cache = json.loads(cache_str) if cache_str else [] |
|
|
|
|
|
# 回调处理 |
|
|
|
|
|
if len(contacts_wxids) == 1: |
|
|
|
|
|
cache_wxids = [f['userName'] for f in cache] |
|
|
|
|
|
friends_brief = self.get_brief_info(token_id, app_id, contacts_wxids) |
|
|
|
|
|
if contacts_wxids[0] in cache_wxids: |
|
|
|
|
|
# 替换已经存在的数据 |
|
|
|
|
|
for i in range(len(cache)): |
|
|
|
|
|
if cache[i]['userName'] == contacts_wxids[0]: |
|
|
|
|
|
cache[i] = friends_brief[0] |
|
|
|
|
|
else: |
|
|
|
|
|
cache.extend(f for f in friends_brief if f["nickName"]) |
|
|
|
|
|
friends_no_brief_wxid = [f['userName'] for f in friends_brief if not f["nickName"]] |
|
|
|
|
|
if friends_no_brief_wxid: |
|
|
|
|
|
detailed_info = self.get_detail_info(token_id, app_id, friends_no_brief_wxid) |
|
|
|
|
|
cache.extend(detailed_info) |
|
|
|
|
|
|
|
|
friends_no_brief_wxid = [f['userName'] for f in friends_brief if not f["nickName"]] |
|
|
|
|
|
cache.extend(f for f in friends_brief if f["nickName"]) |
|
|
|
|
|
|
|
|
# 分批处理 |
|
|
|
|
|
else: |
|
|
|
|
|
cache=[] |
|
|
|
|
|
# 缓存为空,分批处理 contacts_wxids |
|
|
|
|
|
batch_size = 100 |
|
|
|
|
|
for i in range(0, len(contacts_wxids), batch_size): |
|
|
|
|
|
batch = contacts_wxids[i:i + batch_size] |
|
|
|
|
|
friends_brief = self.get_brief_info(token_id, app_id, batch) |
|
|
|
|
|
|
|
|
|
|
|
cache.extend(f for f in friends_brief if f["nickName"]) |
|
|
|
|
|
|
|
|
|
|
|
friends_no_brief_wxid = [f['userName'] for f in friends_brief if not f["nickName"]] |
|
|
|
|
|
if friends_no_brief_wxid: |
|
|
|
|
|
detailed_info = self.get_detail_info(token_id, app_id, friends_no_brief_wxid) |
|
|
|
|
|
cache.extend(detailed_info) |
|
|
|
|
|
|
|
|
if friends_no_brief_wxid: |
|
|
|
|
|
detailed_info = self.get_detail_info(token_id, app_id, friends_no_brief_wxid) |
|
|
|
|
|
cache.extend(detailed_info) |
|
|
|
|
|
|
|
|
# 更新缓存 |
|
|
|
|
|
|
|
|
# 更新缓存 |
|
|
|
|
|
redis_helper.redis_helper.update_hash_field(hash_key, "data", json.dumps(cache, ensure_ascii=False)) |
|
|
redis_helper.redis_helper.update_hash_field(hash_key, "data", json.dumps(cache, ensure_ascii=False)) |
|
|
|
|
|
|
|
|
return cache |
|
|
return cache |
|
|
|
|
|
|
|
|
def delete_contacts_brief_from_cache(self, wxid, contacts_wxids: list): |
|
|
def delete_contacts_brief_from_cache(self, wxid, contacts_wxids: list): |
|
|