Administrator
4 天以前 48fb7a00951f91bdc707e5dd2d196e5bccb752c3
outside_api_command_manager.py
@@ -11,7 +11,7 @@
# 心跳信息
from huaxin_client import socket_util
from huaxin_client.client_network import SendResponseSkManager
from log_module.log import logger_system
from log_module.log import logger_system, logger_request_api
from utils import middle_api_protocol, tool
MSG_TYPE_HEART = "heart"
@@ -42,6 +42,7 @@
CODE_LIST_WANT = "want"
CODE_LIST_PAUSE_BUY = "pause_buy"
CODE_LIST_MUST_BUY = "must_buy"
CODE_LIST_GREEN = "green"
# 类型
API_TYPE_TRADE = "trade"  # 交易
@@ -162,7 +163,8 @@
        # 发送心跳
        cls.__heartbeats_thread(type, key, sk)
        cls.__listen_command_thread(type, key, sk)
        print("create_and_run_client success", type, key)
        # print("create_and_run_client success", type, key)
        logger_request_api.info(f"创建本地socket请求客户端:{type}")
        return key, sk
    @classmethod
@@ -188,8 +190,9 @@
            try:
                result = socket_util.recv_data(sk)[0]
                if result:
                    start_time = time.time()
                    try:
                        print("接收数据", _type, result)
                        # print("接收数据", _type, result)
                        result_json = json.loads(result)
                        if result_json["type"] == MSG_TYPE_HEART:
                            # 返回内容
@@ -198,15 +201,14 @@
                        data = result_json["data"]
                        content_type = data["type"]
                        print("接收内容", data)
                        # print("接收内容", data)
                        request_id = result_json.get('request_id')
                        if not socket_util.is_client_params_sign_right(result_json):
                            print("签名错误")
                            # print("签名错误")
                            # 签名出错
                            SendResponseSkManager.send_error_response(_type, request_id, client_id,
                                                                      {"code": -1, "msg": "签名错误"})
                            continue
                        if content_type == API_TYPE_TRADE:
                            # 交易
                            cls.action_callback.OnTrade(client_id, request_id, data)
@@ -248,8 +250,11 @@
                            cls.action_callback.OnCommonRequest(client_id, request_id, data)
                    except Exception as e:
                        logging.exception(e)
                        pass
                    finally:
                        use_time = int(time.time() - start_time)
                        if use_time > 5:
                            result_json = json.loads(result)
                            logger_request_api.info(f"超时5s以上:{result_json['data']['type']}")
                        # 发送响应
                        sk.send(json.dumps({"type": "cmd_recieve"}).encode('utf-8'))
                else: