com.dahuatech.icc.multiinone.admin.StartTalkSDK Maven / Gradle / Ivy
The newest version!
package com.dahuatech.icc.multiinone.admin;
import com.dahuatech.hutool.json.JSONObject;
import com.dahuatech.hutool.log.Log;
import com.dahuatech.hutool.log.LogFactory;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.multiinone.admin.constant.AdminConstant;
import com.dahuatech.icc.multiinone.admin.vo.StartTalkRequest;
import com.dahuatech.icc.multiinone.admin.vo.StartTalkResponse;
import com.dahuatech.icc.oauth.exception.BusinessException;
import com.dahuatech.icc.oauth.http.IccClient;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigBaseInfo;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
import com.dahuatech.icc.oauth.model.v202010.oSDK.OauthParamConstant;
/**
* program:java-sdk
*
* Author: 355079
* Date:2022-08-11 10:30
* Description: 开始语音对讲
*/
public class StartTalkSDK {
private static final Log logger = LogFactory.get();
/**
* 开始语音对讲
**/
public static StartTalkResponse startTalk(StartTalkRequest request) {
logger.info("StartTalkSDK,startTalk,param:{}",new JSONObject(request).toJSONString(0));
StartTalkResponse response = null;
try {
//基本校验
request.valid();
//业务校验
request.businessValid();
request.setUrl(new StartTalkRequest(request.getOauthConfigBaseInfo().getHttpConfigInfo(), AdminConstant.START_TALK, request.getMethod()).getUrl());
//业务逻辑处理
response = new IccClient(request.getOauthConfigBaseInfo()).doAction(request, request.getResponseClass());
//由于返回的url可能存在多个,需要对每一个都拼接token
if(response.getData() == null){
return response;
}
if (response.getData().getToken() != null && response.getData().getUrl() != null) {
String url = response.getData().getUrl();
String token = response.getData().getToken();
String[] urls = url.split("\\|");
String newUrl = new String();
for (int i = 0; i < urls.length; i++) {
urls[i] += "?token=";
urls[i] += token;
if (i != urls.length - 1) {
urls[i] += "|";
}
newUrl += urls[i];
}
response.getData().setUrl(newUrl);
}
} catch (BusinessException businessException) {
logger.error("StartTalkSDK,StartTalk,errorMessage:{},errorArgs:{},errorCode:{}", businessException.getErrorMsg(), businessException.getArgs(), businessException.getCode());
response = new StartTalkResponse();
response.setCode(businessException.getCode());
response.setErrMsg(businessException.getErrorMsg());
response.setArgs(businessException.getArgs());
response.setSuccess(false);
return response;
}
catch (Exception e) {
response = new StartTalkResponse();
logger.error("Stark talk occured a Exception, errorMsg:{}.", e, e.getMessage());
response.setErrMsg(OauthParamConstant.SYSTEME_RROR.getErrMsg());
response.setCode(OauthParamConstant.SYSTEME_RROR.getCode());
response.setSuccess(false);
return response;
}
return response;
}
public static void main(String[] args) throws ClientException {
StartTalkRequest startTalkRequest = new StartTalkRequest();
StartTalkRequest.StartTalkData startTalkData = startTalkRequest.new StartTalkData();
startTalkData.setSource("");
startTalkData.setDeviceCode("1003209");
startTalkData.setTalkType("1");
startTalkData.setTarget("");
startTalkData.setAudioBit("16");
startTalkData.setAudioType("1");
startTalkData.setBroadcastChannels("");
startTalkData.setSampleRate("8000");
startTalkData.setTalkmode("");
startTalkData.setChannelSeq("0");
startTalkRequest.setData(startTalkData);
OauthConfigBaseInfo oauthConfigBaseInfo = new OauthConfigUserPwdInfo("10.55.36.202", "xqh", "d8d66345-87a3-476d-8344-1aeb5fb6eca0", "system", "dahua2021");
startTalkRequest.setOauthConfigBaseInfo(oauthConfigBaseInfo);
StartTalkResponse response = startTalk(startTalkRequest);
System.out.println("url:" + response.getData().getUrl());
}
}