Commit 64966efe authored by xianyang's avatar xianyang

优化tcp清算

parent 1eb193e6
......@@ -64,6 +64,8 @@ class TestingEnv(Env):
PASSWORD: str = "fj123456"
oss_url = 'http://oss.3yakj.com/application_static_data'
CLEARING_CENTER_URL: str = 'http://106.55.103.148:6464/'
CLEARING_CENTER_HOST: str = '106.55.103.148'
CLEARING_CENTER_PORT: int = 6464
class ProdEnv(Env):
......@@ -84,6 +86,8 @@ class ProdEnv(Env):
ALGORITHM: str = "HS256"
PASSWORD: str = "fj123456"
CLEARING_CENTER_URL: str = 'http://47.103.144.36:5454/'
CLEARING_CENTER_HOST: str = '106.55.103.148'
CLEARING_CENTER_PORT: int = 6464
# env = TestingEnv() # 开发环境
......
......@@ -98,7 +98,7 @@ def wrapper_out():
def search(params, method):
"""
调用清算接口
调用清算接口http
:param params: 传入参数
:param method: 传入方法
"""
......@@ -116,6 +116,39 @@ def search(params, method):
return text
def send_json_rpc_request(params, method):
"""
调用清算接口tcp
:param params: 传入参数
:param method: 传入方法
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((env.CLEARING_CENTER_HOST, env.CLEARING_CENTER_PORT))
request = {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": '125'
}
# 将请求对象编码为 JSON 字符串
request_str = json.dumps(request) + "\n" # test协议一定要加\n
# 发送 JSON-RPC 请求
s.sendall(request_str.encode())
# 接收服务器响应
response_str = s.recv(1024).decode()
# 将响应字符串解码为 JSON 对象
response = json.loads(response_str)
if "error" in response:
return {}
return response["result"]
def get_ip():
res = socket.gethostbyname(socket.gethostname())
return res
......@@ -133,6 +166,7 @@ def get_month_last_month(month_type,start_time,end_time):
print(last_month,now_month)
return last_month,now_month
def time_format(utc_timestamp: int):
days = (utc_timestamp + 3600 * 8) % 86400
hours = int(days / 3600)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment