From 2f6fdac1d532576314b20d9a9d705d76e34917ec Mon Sep 17 00:00:00 2001 From: H Vs Date: Wed, 5 Mar 2025 16:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/utils.py | 19 ++++++++++++++++--- resources/login_resources.py | 9 +++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/common/utils.py b/common/utils.py index f099daf..aed6213 100644 --- a/common/utils.py +++ b/common/utils.py @@ -250,7 +250,7 @@ def dialogue_message(wxid_from:str,wxid_to:str,wx_content:list,is_ai:bool=False) return json.dumps(data, separators=(',', ':'), ensure_ascii=False) -def kafka_base_message(content: dict)->dict: +def kafka_base_message(msg_type,content: dict)->dict: # 获取当前时间戳,精确到毫秒 current_timestamp = int(time.time() * 1000) @@ -263,7 +263,8 @@ def kafka_base_message(content: dict)->dict: "topic": "topic.ai.ops.wx", "time": current_time, "data": { - "msg_type": "login-qrcode", + #"msg_type": "login-qrcode", + "msg_type": msg_type, "content": content } } @@ -288,7 +289,19 @@ def login_qrcode_message(token_id: str,agent_tel:str,qr_code_img_base64:str,qr_c "qr_code_urls":qr_code_url, "qr_code_img_base64":qr_code_img_base64 } - data=kafka_base_message(content) + data=kafka_base_message("login-qrcode",content) + return json.dumps(data, separators=(',', ':'), ensure_ascii=False) + +def login_result_message(token_id: str,agent_tel:str,region_id:str,agent_token_id:str,wxid:str)->str: + + content = { + "tel":agent_tel, + "token_id":token_id, + "region_id":region_id, + "agent_token_id":agent_token_id, + "wxid":wxid + } + data=kafka_base_message("login-result",content) return json.dumps(data, separators=(',', ':'), ensure_ascii=False) diff --git a/resources/login_resources.py b/resources/login_resources.py index 27aede3..035d26c 100644 --- a/resources/login_resources.py +++ b/resources/login_resources.py @@ -8,6 +8,8 @@ import threading from model import Models +from common import kafka_helper + class GetLoginInfoResource(Resource): @@ -67,8 +69,8 @@ class GetLoginWxQRCodeResource(Resource): app_id=loginfo.get('appId','') qr_code = gewe_chat.wxchat.get_login_qr_code(token_id, app_id,region_id) - base64_string = qr_code.get('qrImgBase64') - uuid = qr_code.get('uuid') + base64_string = qr_code.get('qrImgBase64',None) + uuid = qr_code.get('uuid',None) if not uuid: msg=f"uuid获取二维码失败,uuid: {uuid}" gewe_chat.wxchat.release_login_lock(token_id) @@ -149,6 +151,9 @@ def waitting_login_result(wxchat:gewe_chat.GeWeChatCom, token_id, app_id,region_ # 保存登录信息 redis_helper.redis_helper.set_hash(hash_key, cleaned_login_info) wxchat.release_login_lock(token_id) + # 登录结果推送到kafka + k_message=utils.login_result_message(token_id,agent_tel,region_id,agent_token_id,wxid) + kafka_helper.kafka_client.produce_message(k_message) break else: logger.info(f"登录检查中: {ret}-{msg}-{res}")