control_server.py
923 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from utils import system_info, netutil
SERVER = 'http://47.115.27.201:39001'
_host = None
def get_init_name():
r = requests.get(SERVER + '/get_only_int')
num = r.json().get('data', {}).get('only_int', 0)
assert num, '初始化接口,无法获取终端索引ID'
return "FBCHAT-{}".format(num)
def post_terminal_info(name, source_ws, num, version):
data = {
"name": name,
"ws": source_ws,
"num": num,
"version": version,
}
data.update(system_info.get())
global _host
if not _host:
_host = netutil.getip()
data['ip'] = _host
print(data)
try:
r = requests.post(SERVER + '/post_terminal_info', json=data, timeout=1)
new_ws = r.json().get('data', {}).get('ws', source_ws)
except:
new_ws = source_ws
return new_ws, not new_ws == source_ws