AudioControllerApi.java
9.07 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.cnlive.shenhe.api;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.entity.ShyAudio;
import com.cnlive.shenhe.entity.ShyYidun;
import com.cnlive.shenhe.enums.TextLabels;
import com.cnlive.shenhe.service.AudioService;
import com.cnlive.shenhe.service.YiDunService;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.YiDunAntiFraudUtil;
import com.google.common.collect.EvictingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
/**
* @Author: xujincheng
* @Date: 2020/6/5 13:33
* @Description: 音频送审接口
*/
@Controller
@RequestMapping("/api/audio")
public class AudioControllerApi {
private static Logger logger = LoggerFactory.getLogger(AudioControllerApi.class);
private static EvictingQueue<String> queue = EvictingQueue.create(50);
@Autowired
AudioService audioService;
@Autowired
YiDunService yiDunService;
@Autowired
AuditPass pass;
/**
* 音频入库
*
* @param
* @multiplecategory 获取栏目分类//
* @audioClipsName 获取音频上传人的id
* @soure 音频来源
* @audioId 音频id
* @audioTitle 音频标题
* @audioUrl 音频url
* @audioCoverUrl 封面图
* @audioIntro 音频简介
* @audioTag 音频标签
* @audioKeyword 音频关键字
* @uploadTime 音频上传时间
* @priority 优先级(1-热点 0-非热点)
* @callback 回调函数
* @spId spId
* @bucketName 存储空间名
* @bucketType 金山或七牛
* @duration 时长
* @contactInfo 音频上传人联系方式
* @extendField 扩展字段
*/
@PostMapping("/import")
@ResponseBody
public ResponseBean importAudio(String param) {
logger.info("音频入库,param=====" + param);
try {
ShyAudio shyAudio = JSONObject.parseObject(param, ShyAudio.class);
ShyAudio audioMsg = audioService.getAudioMsg(shyAudio.getAudioId());
if (audioMsg == null) {
synchronized (AudioControllerApi.class) {
if (!queue.contains(shyAudio.getAudioId())) {
queue.add(shyAudio.getAudioId());
shyAudio.setCreateTime(new Date());
shyAudio.setState(0);
//获取审核类型
audioService.getShenheType(shyAudio);
shyAudio.setReceive(0);
audioService.importAudioMsg(shyAudio);
}
}
} else {
shyAudio.setId(audioMsg.getId());
shyAudio.setUpdateTime(new Date());
audioService.updateAudioMsg(shyAudio);
return new ResponseBean(ErrorEnum.SUCCESS);
}
} catch (Exception e) {
e.printStackTrace();
return new ResponseBean(ErrorEnum.ERROR);
}
return new ResponseBean(ErrorEnum.SUCCESS);
}
/**
* 易盾音频检测结果回调
*
* @param
*/
@PostMapping("/callbackAudio")
@ResponseBody
public void callbackYiDunAudio(String secretId, String businessId, String signature, String callbackData) {
logger.info("易盾音频检测结果回调信息secretId:{},businessId:{},signature:{},callbackData:{}", secretId, businessId, signature, callbackData);
boolean flag = YiDunAntiFraudUtil.verifySignature(secretId, businessId, signature, callbackData);
logger.info("易盾音频检测校验签名结果result:{}", flag);
if (flag) {
try {
JSONObject jsonObject = JSONObject.parseObject(callbackData);
JSONArray antispamArray = jsonObject.getJSONArray("antispam");
if (antispamArray != null && antispamArray.size() > 0) {
for (Object obj : antispamArray) {
ShyYidun newYiDunMsg = new ShyYidun();
ShyAudio newshyAudio = new ShyAudio();
try {
JSONObject objectAntispam = (JSONObject) obj;
//0:通过,1:嫌疑,2:不通过
int action = objectAntispam.getIntValue("action");
//2:检测中,3:检测完成,4:检测失败
int asrStatus = objectAntispam.getIntValue("asrStatus");
String taskId = objectAntispam.getString("taskId");
ShyYidun yiDunMsg = yiDunService.getYiDunMsg(taskId);
if (yiDunMsg == null) {
continue;
}
newYiDunMsg.setId(yiDunMsg.getId());
newYiDunMsg.setDuration(-1);
newYiDunMsg.setUpdate_time(new Date());
ShyAudio shyAudio = audioService.selectByPrimaryKey(Integer.parseInt(yiDunMsg.getContent_id()));
newshyAudio.setId(shyAudio.getId());
if (action == 0 && asrStatus == 3) {
newYiDunMsg.setDesc_msg("易盾点播音频审核通过了");
newYiDunMsg.setCheck_status(0);
newshyAudio.setMsg("易盾点播音频审核通过了");
newshyAudio.setUploader("机审通过");
newshyAudio.setState(1);
newshyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE);
newshyAudio.setReceive(CommonConst.RECEIVE_AUDIT);
pass.audioPass(shyAudio.getAudioId(), 3, shyAudio.getAttr_tags(), "易盾点播音频审核通过了", shyAudio.getCallback());
} else {
StringBuilder labelMsg = new StringBuilder();
if (action != 0 && asrStatus == 3) {
JSONArray labels = objectAntispam.getJSONArray("labels");
labelMsg = new StringBuilder("(");
if (labels != null && labels.size() > 0) {
for (Object labelObj : labels) {
JSONObject jsonObjectone = (JSONObject) labelObj;
Integer label = jsonObjectone.getInteger("label");
String name = TextLabels.getName(label);
labelMsg.append(name);
}
}
}
if (action == 1 && asrStatus == 3) {
newYiDunMsg.setDesc_msg("易盾点播音频审核音频嫌疑" + labelMsg + ")");
newshyAudio.setMsg("易盾点播音频审核音频嫌疑" + labelMsg + ")");
}
if (action == 2 && asrStatus == 3) {
newYiDunMsg.setDesc_msg("易盾点播音频审核音频违规" + labelMsg + ")");
newshyAudio.setMsg("易盾点播音频审核音频违规" + labelMsg + ")");
}
newshyAudio.setState(0);
newshyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
newshyAudio.setReceive(CommonConst.RECEIVE_BEFORE);
//审核失败
newYiDunMsg.setCheck_status(2);
}
newYiDunMsg.setResult_type(String.valueOf(action));
} catch (NumberFormatException e) {
e.printStackTrace();
//审核类型改为人工审核
newshyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
//拒绝原因
newshyAudio.setMsg("易盾点播音频审核其它问题需排查");
newYiDunMsg.setDesc_msg("易盾点播音频审核其它问题需排查");
}
yiDunService.updateYiDunMsg(newYiDunMsg);
audioService.updateAudioMsg(newshyAudio);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
}