2025-09-08 17:04:43 +08:00
|
|
|
package com.zhgd.xmgl.call;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2025-09-09 11:19:08 +08:00
|
|
|
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
|
|
|
|
import com.zhgd.jeecg.common.util.pass.HttpUtils;
|
|
|
|
|
import com.zhgd.redis.lock.RedisRepository;
|
2025-09-08 17:04:43 +08:00
|
|
|
import com.zhgd.xmgl.call.api.BroadcastManufacturer;
|
|
|
|
|
import com.zhgd.xmgl.modules.broadcast.entity.SmartBroadcastConfig;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-09-09 11:19:08 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2025-09-08 17:04:43 +08:00
|
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
2025-09-09 11:19:08 +08:00
|
|
|
import org.springframework.context.annotation.Lazy;
|
2025-09-08 17:04:43 +08:00
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2025-09-09 11:19:08 +08:00
|
|
|
import java.util.Objects;
|
2025-09-08 17:04:43 +08:00
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Component
|
|
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
|
public class ShiZiWangBroadcastCall implements BroadcastManufacturer {
|
|
|
|
|
private SmartBroadcastConfig config;
|
2025-09-09 11:19:08 +08:00
|
|
|
@Lazy
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisRepository redisRepository;
|
2025-09-08 17:04:43 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SmartBroadcastConfig getConfig() {
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setConfig(SmartBroadcastConfig config) {
|
|
|
|
|
this.config = config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void playVoiceFile(List<String> devSns, String fileName, String filePath) {
|
2025-09-09 11:19:08 +08:00
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
|
body.put("SerialNums", devSns);
|
|
|
|
|
body.put("PlayText", fileName);
|
|
|
|
|
body.put("PlayFileContent", Base64.encode(FileUtil.readBytes(filePath)));
|
|
|
|
|
JSONObject header = new JSONObject();
|
|
|
|
|
header.put("Token", getToken());
|
|
|
|
|
HttpUtils.sendPostBodyRtJo("狮子王播放语音文件", "https://norsos.lionking110.com/sos/v1/mntn/adap/business/external/group/play", body, 20000, header);
|
2025-09-08 17:04:43 +08:00
|
|
|
}
|
2025-09-09 11:19:08 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取token
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String getToken() {
|
|
|
|
|
return redisRepository.getOrSet("SHIZIWANG:TOKEN:" + config.getAppId(), () -> {
|
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
|
body.put("AppId", config.getAppId());
|
|
|
|
|
body.put("AppCode", config.getAppCode());
|
|
|
|
|
JSONObject jsonObject = HttpUtils.sendPostBodyRtJo("狮子王通过appId信息获取token", "https://norsos.lionking110.com/sos/v1/mntn/account/appId/token", body, 20000, null);
|
|
|
|
|
if (!Objects.equals(jsonObject.getInteger("Status"), 0)) {
|
|
|
|
|
throw new OpenAlertException("狮子王通过appId信息获取token异常,错误信息:" + jsonObject.getString("StatusMsg"));
|
|
|
|
|
}
|
|
|
|
|
return jsonObject.getString("Token");
|
|
|
|
|
}, 7200L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-09-08 17:04:43 +08:00
|
|
|
}
|