H Vs 1 місяць тому
джерело
коміт
2f6fdac1d5
2 змінених файлів з 23 додано та 5 видалено
  1. +16
    -3
      common/utils.py
  2. +7
    -2
      resources/login_resources.py

+ 16
- 3
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)




+ 7
- 2
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}")


Завантаження…
Відмінити
Зберегти