123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- """
- 配置流程
- 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 = '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": 'iHciceH9A5',
- "type": "req",
- "name": 'songs_queue_append',
- "params": {
- "tid": '1',
- "vol": 50,
- "urls": [
- {
- "name": "1",
-
-
-
-
-
-
-
-
- "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 = f"{self.file_service_url}/a1.mp3"
- elif result_type in [1, 2]:
-
- uri = f"{self.file_service_url}/a2.mp3"
- elif result_type in [0]:
-
- uri = f"{self.file_service_url}/a3.mp3"
- else:
- return False
- data = {
-
- "sn": 'iHciceH9A5',
- "type": "req",
- "name": 'songs_queue_append',
- "params": {
- "tid": '1',
-
- "vol": 100,
- "urls": [
- {
- "name": "1",
-
-
-
-
-
-
-
-
- "uri": uri,
- }
- ]
- }
- }
- times = 0
- while times < 10:
- try:
-
-
- response = requests.post(self.api_service_url, json=data, headers=self.headers)
-
- 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": ["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)
-
-
-
- data = {
-
- "sn": "ls20://02009EDCD48C",
- "type": "req",
- "name": "songs_queue_append",
- "params": {
- "tid": "134",
- "vol": 80,
-
- "urls": [
- {
- "name": "1",
- "uri": f"{self.file_service_url}/a2.mp3",
-
-
-
-
-
-
-
-
-
- },
-
-
-
-
- ]
- }
- }
- run_at = time.time()
- times = 0
- while times < 10:
- try:
- print('Api:songs_queue_append:url:', self.api_service_url)
-
- 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 Exception as e:
- print(e)
- times += 1
- time.sleep(1)
- return f"{round(time.time() - run_at, 2)}s"
- if __name__ == '__main__':
-
- api = Api()
-
-
- out = api.songs_queue_append()
- print('use time:', out)
|