# update: 2021-10-15 """ 配置流程 1、禁用vbox虚拟机的网卡。 2、pc端安装客户端程序,打开“智能广播扫描工具”,扫描设备,并修改设备ip。(服务ip不能和设备ip一样,随意就可以) { "sn": "iHciceH9A5", "type": "req", "name": "songs_queue_append", "params": { "tid": "134", "vol": 100, "urls": [ { "name": "1", # 只支持mp3格式 不支持wav格式 "uri": "http://websitecdn.gangganghao.com.cn/ls20/mp3/ei.mp3" }, { "name": "2", "uri": "http://websitecdn.gangganghao.com.cn/ls20/mp3/jxy.mp3" } ] } } """ import requests import time class Api(object): def __init__(self, service_url='http://192.168.30.89:8888'): """ port: 端口号 8888 安装目录下 ls20_mgrserver/ls20_mgrserver.ini 文件中进行配置 192.168.1.241 ls20://02029F15B65A 192.168.1.242 ls20://0203B0F822FC 192.168.1.243 ls20://02015790B99B 192.168.1.244 ls20://02006723C3BA 192.168.1.245 ls20://020099728112 """ # self.api_service_url = service_url # --- 八局项目 第3现场设备 --- # self.api_service_url = 'http://192.168.15.193:8888' # self.file_service_url = 'http://192.168.15.195:9900' # --- 八局项目 第4现场设备 --- self.api_service_url = 'http://192.168.1.43:8888' self.file_service_url = 'http://192.168.1.242:9900' self.headers = dict() self.headers['content-type'] = 'application/json' def call_audio_make_sound_v2(self, file_name, url, sn): """ url: http://sc.geemi.cn/smartSiteService/api/uploadLog/uploadLogCapture """ data = { # "sn": sn, "sn": 'iHciceH9A5', "type": "req", "name": 'songs_queue_append', "params": { "tid": '1', "vol": 50, "urls": [ { "name": "1", # "uri": f"http://127.0.0.1:5042/api?module=TEST&method=test011&mp3_name={file_name}", # "uri": "http://192.168.20.231:8802/api?mp3_name=2021-10-16-11-05-29-717030.mp3", # "uri": f"http://fra-component-trigger:5042/api?mp3_name={file_name}", # "uri": f"http://192.168.20.231:9900/{file_name}", # "uri": f"http://192.168.0.15:9900/{file_name}", # "uri": f"http://192.168.51.242:9900/{file_name}", # "uri": "http://192.168.51.242:9900/find-unknown-person.mp3", # "uri": "http://192.168.15.195:9900/find-unknown-person.mp3", "uri": f"{self.file_service_url}/find-unknown-person.mp3", } ] } } times = 0 while times < 10: try: print('Api:call_audio_make_sound_v2:url:', self.api_service_url) print('Api:call_audio_make_sound_v2:uri:', data.get('params').get('urls')[0].get('uri')) response = requests.post(self.api_service_url, json=data, headers=self.headers) print('Api:call_audio_make_sound_v2:result:', response.status_code) return True except Exception as e: print(e) times += 1 time.sleep(1) return False def call_audio_make_sound_v3(self, result_type): """ url: http://sc.geemi.cn/smartSiteService/api/uploadLog/uploadLogCapture result_type: 结果类型 0 匹配到人员 1 人脸检测失败 2 提取特征失败 3 未匹配到人员 """ if result_type in [3]: # uri = "http://192.168.15.195:9900/a1.mp3" # 请登记 3 uri = f"{self.file_service_url}/a1.mp3" # 请登记 3 elif result_type in [1, 2]: # uri = "http://192.168.15.195:9900/a2.mp3" # 请重试 1 2 uri = f"{self.file_service_url}/a2.mp3" # 请重试 1 2 elif result_type in [0]: # uri = "http://192.168.15.195:9900/a3.mp3" # 欢迎 0 uri = f"{self.file_service_url}/a3.mp3" # 欢迎 0 else: return False data = { # "sn": sn, "sn": 'iHciceH9A5', "type": "req", "name": 'songs_queue_append', "params": { "tid": '1', # "vol": 50, "vol": 100, "urls": [ { "name": "1", # "uri": f"http://127.0.0.1:5042/api?module=TEST&method=test011&mp3_name={file_name}", # "uri": "http://192.168.20.231:8802/api?mp3_name=2021-10-16-11-05-29-717030.mp3", # "uri": f"http://fra-component-trigger:5042/api?mp3_name={file_name}", # "uri": f"http://192.168.20.231:9900/{file_name}", # "uri": f"http://192.168.0.15:9900/{file_name}", # "uri": f"http://192.168.51.242:9900/{file_name}", # "uri": "http://192.168.51.242:9900/find-unknown-person.mp3", # "uri": "http://192.168.15.195:9900/a1.mp3", "uri": uri, } ] } } times = 0 while times < 10: try: # print('Api:call_audio_make_sound_v3:url:', url) # print('Api:call_audio_make_sound_v3:uri:', data.get('params').get('urls')[0].get('uri')) response = requests.post(self.api_service_url, json=data, headers=self.headers) # print('Api:call_audio_make_sound_v3:result:', response.status_code) return True except Exception as e: print(e) times += 1 time.sleep(1) return False def file_download(self): """ doc: https://documenter.getpostman.com/view/691989/TzRVdR6Q#70870504-1cb6-439b-9cf4-f1f786d9d3a1 """ data = { # "sn": ["ls20://0201518F79D4"], "sn": ["iHciceH9A5"], "type": "req", "name": "file_download", "params": { "urls": [ { "uri": "http://192.168.20.231:9900/2021-10-16-11-05-29-717030.mp3", "target": "/root/2021-10-16-11-05-29-717030.mp3" } ] } } print('Api:file_download:url:', self.api_service_url) response = requests.post(self.api_service_url, json=data, headers=self.headers) print('Api:file_download:result:', response.status_code) return response.status_code def songs_queue_append(self): """ url: http://sc.geemi.cn/smartSiteService/api/uploadLog/uploadLogCapture """ from requests.exceptions import ConnectionError, ReadTimeout import time time.sleep(0.01) # url = "http://192.168.20.189:8888" # url = "http://192.168.51.193:8888" # url = "http://192.168.15.193:8888" data = { # "sn": "iHciceH9A5", # 第3现场设备 "sn": "ls20://02009EDCD48C", # 第4现场设备 "type": "req", "name": "songs_queue_append", "params": { "tid": "134", "vol": 80, # "vol": 10, # 基本听不见 "urls": [ { "name": "1", "uri": f"{self.file_service_url}/a2.mp3", # --- test --- # "uri": "http://websitecdn.gangganghao.com.cn/ls20/mp3/ei.mp3", # "uri": "http://192.168.20.231:8802/api?mp3_name=2021-10-16-11-05-29-717030.mp3", # "uri": "http://192.168.20.231:9900/2021-10-16-11-05-29-717030.mp3", # "uri": "/root/2021-10-16-11-05-29-717030.mp3", # "uri": "http://192.168.0.15:9900/2021-10-16-11-05-29-717030.mp3", # "uri": "http://192.168.51.242:9900/find-unknown-person.mp3", # "uri": "http://192.168.15.195:9900/find-unknown-person.mp3", # "uri": "http://192.168.15.195:9900/a1.mp3", }, # { # "name": "2", # "uri": "http://websitecdn.gangganghao.com.cn/ls20/mp3/jxy.mp3" # } ] } } run_at = time.time() times = 0 while times < 10: try: print('Api:songs_queue_append:url:', self.api_service_url) # response = requests.post(url, json=data, headers=self.headers, timeout=1) response = requests.post(self.api_service_url, json=data, headers=self.headers) print('Api:songs_queue_append:result:', response.status_code) return f"{round(time.time() - run_at, 2)}s" # except ConnectionError as e: except Exception as e: print(e) times += 1 time.sleep(1) return f"{round(time.time() - run_at, 2)}s" if __name__ == '__main__': # --- init --- api = Api() # --- test --- cd /home/server/projects/taiwuict/cscec-8bur-vms/supplement-python/apis/audio && python3 api.py # out = api.file_download() out = api.songs_queue_append() print('use time:', out)