diff --git a/resources/login_resources.py b/resources/login_resources.py index c2b8eef..c87246d 100644 --- a/resources/login_resources.py +++ b/resources/login_resources.py @@ -118,30 +118,36 @@ def waitting_login_result(wxchat:gewe_chat.GeWeChatCom, token_id, app_id,region_ head_img_url=res.get('headImgUrl','') login_info = res.get('loginInfo', {}) + wxid=login_info.get('wxid',agent_tel) + login_info.update({'appId': app_id, 'uuid': uuid, 'tokenId': token_id,'status': 1,'headImgUrl':head_img_url,'regionId':region_id}) cache_login_info=redis_helper.redis_helper.get_hash(hash_key) + if 'appId' not in cache_login_info: login_info.update({"create_at":int(time.time()),"modify_at":int(time.time())}) - else: - login_info.update({"modify_at":int(time.time())}) - - cleaned_login_info = {k: (v if v is not None else '') for k, v in login_info.items()} - - redis_helper.redis_helper.set_hash(hash_key, cleaned_login_info) - wxchat.release_login_lock(token_id) - - # 默认配置 - config=Models.AgentConfig.model_validate({ + # 默认配置 + config=Models.AgentConfig.model_validate({ "chatroomIdWhiteList": [], "agentTokenId": agent_token_id, "agentEnabled": False, "addContactsFromChatroomIdWhiteList": [], "chatWaitingMsgEnabled": True - }) - + }) + else: + login_info.update({"modify_at":int(time.time())}) + # 已有配置 + config_cache=wxchat.get_wxchat_config_from_cache(wxid) + config=Models.AgentConfig.model_validate(config_cache) + + cleaned_login_info = {k: (v if v is not None else '') for k, v in login_info.items()} + #wxid=cleaned_login_info.get('wxid',agent_tel) + # 保存配置信息 config_dict=config.model_dump() - wxid=cleaned_login_info.get('wxid',agent_tel) wxchat.save_wxchat_config(wxid,config_dict) + + # 保存登录信息 + redis_helper.redis_helper.set_hash(hash_key, cleaned_login_info) + wxchat.release_login_lock(token_id) break else: logger.info(f"登录检查中: {ret}-{msg}-{res}") diff --git a/wechat/biz.py b/wechat/biz.py index 8409513..df5462b 100644 --- a/wechat/biz.py +++ b/wechat/biz.py @@ -331,33 +331,38 @@ def login_or_reconnect(wxchat:gewe_chat.GeWeChatCom, token_id, app_id, region_id head_img_url=res.get('headImgUrl','') login_info = res.get('loginInfo', {}) + + wxid=login_info.get('wxid',agent_tel) + login_info.update({'appId': app_id, 'uuid': uuid, 'tokenId': token_id,'status': 1,'headImgUrl':head_img_url,'regionId':region_id}) cache_login_info=redis_helper.redis_helper.get_hash(hash_key) if 'appId' not in cache_login_info: login_info.update({"create_at":int(time.time()),"modify_at":int(time.time())}) + # 默认配置 + config=Models.AgentConfig.model_validate({ + "chatroomIdWhiteList": [], + "agentTokenId": agent_token_id, + "agentEnabled": False, + "addContactsFromChatroomIdWhiteList": [], + "chatWaitingMsgEnabled": True + }) + + else: login_info.update({"modify_at":int(time.time())}) - # if 'appId' in cache_login_info: - # login_info.update({"reg_time":datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3],"login_time":datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]}) - # else: - # login_info.update({"login_time":datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]}) + # 已有配置 + config_cache=wxchat.get_wxchat_config_from_cache(wxid) + config=Models.AgentConfig.model_validate(config_cache) + cleaned_login_info = {k: (v if v is not None else '') for k, v in login_info.items()} - redis_helper.redis_helper.set_hash(hash_key, cleaned_login_info) - wxchat.release_login_lock(token_id) - # 默认配置 - - config=Models.AgentConfig.model_validate({ - "chatroomIdWhiteList": [], - "agentTokenId": agent_token_id, - "agentEnabled": False, - "addContactsFromChatroomIdWhiteList": [], - "chatWaitingMsgEnabled": True - }) - + # 保存配置信息 config_dict=config.model_dump() - wxid=cleaned_login_info.get('wxid',agent_tel) wxchat.save_wxchat_config(wxid,config_dict) + + # 保存登录信息 + redis_helper.redis_helper.set_hash(hash_key, cleaned_login_info) + wxchat.release_login_lock(token_id) return login_info else: logger.info(f"登录检查中: {ret}-{msg}-{res}")