Commit e1f41cf0175c599bad7e9689edb5c0e828249c6d
1 parent
83f731b0
易盾音频检测结果回调
Showing
5 changed files
with
172 additions
and
15 deletions
src/main/java/com/cnlive/shenhe/api/AudioControllerApi.java
| 1 | 1 | package com.cnlive.shenhe.api; |
| 2 | 2 | |
| 3 | +import com.alibaba.fastjson.JSONArray; | |
| 3 | 4 | import com.alibaba.fastjson.JSONObject; |
| 4 | 5 | import com.cnlive.shenhe.bean.ErrorEnum; |
| 5 | 6 | import com.cnlive.shenhe.bean.ResponseBean; |
| 6 | 7 | import com.cnlive.shenhe.entity.ShyAudio; |
| 8 | +import com.cnlive.shenhe.entity.ShyContent; | |
| 9 | +import com.cnlive.shenhe.entity.ShyYidun; | |
| 10 | +import com.cnlive.shenhe.enums.TextLabels; | |
| 7 | 11 | import com.cnlive.shenhe.serviceImpl.AudioServiceImpl; |
| 12 | +import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl; | |
| 13 | +import com.cnlive.shenhe.utils.AuditPass; | |
| 14 | +import com.cnlive.shenhe.utils.CommonConst; | |
| 8 | 15 | import com.cnlive.shenhe.utils.YiDunAntiFraudUtil; |
| 9 | 16 | import com.google.common.collect.EvictingQueue; |
| 10 | 17 | import com.google.common.collect.Maps; |
| ... | ... | @@ -36,6 +43,10 @@ public class AudioControllerApi { |
| 36 | 43 | |
| 37 | 44 | @Autowired |
| 38 | 45 | AudioServiceImpl audioService; |
| 46 | + @Autowired | |
| 47 | + YiDunServiceImpl yiDunServiceImpl; | |
| 48 | + @Autowired | |
| 49 | + AuditPass Pass; | |
| 39 | 50 | |
| 40 | 51 | /** |
| 41 | 52 | * 音频入库 |
| ... | ... | @@ -74,7 +85,7 @@ public class AudioControllerApi { |
| 74 | 85 | queue.add(shyAudio.getAudioId()); |
| 75 | 86 | shyAudio.setCreateTime(new Date()); |
| 76 | 87 | shyAudio.setState(0); |
| 77 | - //目前直接设置为人工审 | |
| 88 | + //获取审核类型 | |
| 78 | 89 | audioService.getShenheType(shyAudio); |
| 79 | 90 | shyAudio.setReceive(0); |
| 80 | 91 | audioService.importAudioMsg(shyAudio); |
| ... | ... | @@ -101,14 +112,87 @@ public class AudioControllerApi { |
| 101 | 112 | */ |
| 102 | 113 | @PostMapping("/callbackAudio") |
| 103 | 114 | @ResponseBody |
| 104 | - public void callbackYiDunAudio(String secretId,String businessId,String signature,String callbackData) { | |
| 105 | - logger.info("易盾音频检测结果回调信息secretId:{},businessId:{},signature:{},callbackData:{}",secretId,businessId,signature,callbackData); | |
| 115 | + public void callbackYiDunAudio(String secretId, String businessId, String signature, String callbackData) { | |
| 116 | + logger.info("易盾音频检测结果回调信息secretId:{},businessId:{},signature:{},callbackData:{}", secretId, businessId, signature, callbackData); | |
| 106 | 117 | boolean flag = YiDunAntiFraudUtil.verifySignature(secretId, businessId, signature, callbackData); |
| 107 | - logger.info("result:{}",flag); | |
| 118 | + logger.info("易盾音频检测校验签名结果result:{}", flag); | |
| 119 | + if (flag) { | |
| 120 | + try { | |
| 121 | + JSONObject jsonObject = JSONObject.parseObject("callbackData"); | |
| 122 | + JSONArray antispamArray = jsonObject.getJSONArray("antispam"); | |
| 123 | + if (antispamArray != null && antispamArray.size() > 0) { | |
| 124 | + for (Object obj : antispamArray) { | |
| 125 | + ShyYidun newYiDunMsg = new ShyYidun(); | |
| 126 | + ShyAudio newshyAudio = new ShyAudio(); | |
| 127 | + try { | |
| 128 | + JSONObject objectAntispam = (JSONObject) obj; | |
| 129 | + //0:通过,1:嫌疑,2:不通过 | |
| 130 | + int action = objectAntispam.getIntValue("action"); | |
| 131 | + //2:检测中,3:检测完成,4:检测失败 | |
| 132 | + int asrStatus = objectAntispam.getIntValue("asrStatus"); | |
| 133 | + String taskId = objectAntispam.getString("taskId"); | |
| 134 | + ShyYidun yiDunMsg = yiDunServiceImpl.getYiDunMsg(taskId); | |
| 135 | + if(yiDunMsg==null){ | |
| 136 | + continue; | |
| 137 | + } | |
| 138 | + newYiDunMsg.setId(yiDunMsg.getId()); | |
| 139 | + newYiDunMsg.setDuration(-1); | |
| 140 | + newYiDunMsg.setUpdate_time(new Date()); | |
| 141 | + yiDunMsg.setResult_type(String.valueOf(action)); | |
| 142 | + ShyAudio shyAudio = audioService.selectByPrimaryKey(Integer.parseInt(yiDunMsg.getContent_id())); | |
| 143 | + newshyAudio.setId(shyAudio.getId()); | |
| 144 | + if(action==0&&asrStatus==3){ | |
| 145 | + yiDunMsg.setDesc_msg("易盾点播音频审核通过了"); | |
| 146 | + newshyAudio.setMsg("易盾点播音频审核通过了"); | |
| 147 | + newshyAudio.setUploader("机审通过"); | |
| 148 | + newshyAudio.setState(1); | |
| 149 | + newshyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE); | |
| 150 | + newshyAudio.setReceive(CommonConst.RECEIVE_AUDIT); | |
| 151 | + Pass.audioPass(shyAudio.getAuditor_id(), 3, shyAudio.getAttr_tags(), "易盾点播音频审核通过了", shyAudio.getCallback()); | |
| 152 | + }else{ | |
| 153 | + String labelMsg = ""; | |
| 154 | + if (action != 0&&asrStatus==3) { | |
| 155 | + JSONArray labels = objectAntispam.getJSONArray("labels"); | |
| 156 | + labelMsg = "("; | |
| 157 | + if (labels != null && labels.size() > 0) { | |
| 158 | + for (Object labelObj : labels) { | |
| 159 | + JSONObject jsonObjectone = (JSONObject) labelObj; | |
| 160 | + Integer label = jsonObjectone.getInteger("label"); | |
| 161 | + String name = TextLabels.getName(label); | |
| 162 | + labelMsg = labelMsg + name; | |
| 108 | 163 | |
| 164 | + } | |
| 165 | + } | |
| 166 | + } | |
| 167 | + if(action==1&&asrStatus==3){ | |
| 168 | + yiDunMsg.setDesc_msg("易盾文本审核文本嫌疑" + labelMsg + ")"); | |
| 169 | + newshyAudio.setMsg("易盾文本审核文本违规" + labelMsg + ")"); | |
| 170 | + } | |
| 171 | + if(action==2&&asrStatus==3){ | |
| 172 | + yiDunMsg.setDesc_msg("易盾文本审核文本违规" + labelMsg + ")"); | |
| 173 | + newshyAudio.setMsg("易盾文本审核文本违规" + labelMsg + ")"); | |
| 174 | + } | |
| 175 | + newshyAudio.setState(0); | |
| 176 | + newshyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_USER); | |
| 177 | + newshyAudio.setReceive(CommonConst.RECEIVE_BEFORE); | |
| 178 | + } | |
| 179 | + } catch (NumberFormatException e) { | |
| 180 | + e.printStackTrace(); | |
| 181 | + //审核类型改为人工审核 | |
| 182 | + newshyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_USER); | |
| 183 | + //拒绝原因 | |
| 184 | + newshyAudio.setMsg("易盾点播音频审核其它问题需排查"); | |
| 185 | + newYiDunMsg.setDesc_msg("易盾点播音频审核其它问题需排查"); | |
| 186 | + } | |
| 187 | + yiDunServiceImpl.updateYiDunMsg(newYiDunMsg); | |
| 188 | + audioService.updateAudioMsg(newshyAudio); | |
| 189 | + } | |
| 190 | + } | |
| 191 | + } catch (NumberFormatException e) { | |
| 192 | + e.printStackTrace(); | |
| 109 | 193 | |
| 194 | + } | |
| 195 | + } | |
| 110 | 196 | } |
| 111 | 197 | |
| 112 | - | |
| 113 | - | |
| 114 | 198 | } |
| 115 | 199 | \ No newline at end of file | ... | ... |
src/main/java/com/cnlive/shenhe/job/AudioJob.java
| ... | ... | @@ -2,7 +2,9 @@ package com.cnlive.shenhe.job; |
| 2 | 2 | |
| 3 | 3 | import com.cnlive.shenhe.entity.ShyAudio; |
| 4 | 4 | import com.cnlive.shenhe.entity.ShyVideos; |
| 5 | +import com.cnlive.shenhe.entity.ShyYidun; | |
| 5 | 6 | import com.cnlive.shenhe.serviceImpl.AudioServiceImpl; |
| 7 | +import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl; | |
| 6 | 8 | import com.cnlive.shenhe.utils.CommonConst; |
| 7 | 9 | import org.slf4j.Logger; |
| 8 | 10 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -23,12 +25,14 @@ public class AudioJob { |
| 23 | 25 | |
| 24 | 26 | @Autowired |
| 25 | 27 | AudioServiceImpl audioService; |
| 28 | + @Autowired | |
| 29 | + YiDunServiceImpl yiDunServiceImpl; | |
| 26 | 30 | |
| 27 | 31 | /** |
| 28 | 32 | * 白名单sp音频通过 |
| 29 | 33 | */ |
| 30 | 34 | @Scheduled(fixedRate = 60 * 1000) |
| 31 | - public void updateVideos() { | |
| 35 | + public void updateAudio() { | |
| 32 | 36 | ShyAudio shyAudio = new ShyAudio(); |
| 33 | 37 | // 审核类型为免审 |
| 34 | 38 | shyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_FREE); |
| ... | ... | @@ -44,4 +48,29 @@ public class AudioJob { |
| 44 | 48 | } |
| 45 | 49 | } |
| 46 | 50 | } |
| 51 | + | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * 定时向易盾发送点播音频进行检测 | |
| 55 | + */ | |
| 56 | + @Scheduled(cron = "0 0 0/1 * * ?")//每小时执行一次 | |
| 57 | + public void audioFilter() { | |
| 58 | + ShyAudio shyAudio = new ShyAudio(); | |
| 59 | + //审核类型为机审 | |
| 60 | + shyAudio.setShenhe_type(CommonConst.AUDIT_TYPE_MACHANE); | |
| 61 | + //待审核状态 | |
| 62 | + shyAudio.setState(CommonConst.AUDIT_INTT); | |
| 63 | + List<ShyAudio> shyAudioList = audioService.findshyAudio(shyAudio); | |
| 64 | + if (shyAudioList != null && shyAudioList.size() > 0) { | |
| 65 | + for (ShyAudio audio : shyAudioList) { | |
| 66 | + ShyYidun shyYidun = new ShyYidun(); | |
| 67 | + shyYidun.setContent_id(audio.getId().toString()); | |
| 68 | + ShyYidun shyYidun1 = yiDunServiceImpl.getidunMsgByContentId(shyYidun); | |
| 69 | + if (shyYidun1 == null) { | |
| 70 | + logger.info("定时向易盾发送点播音频检测视频的audioId:" + audio.getAudioId()); | |
| 71 | + audioService.audioFilter(shyAudio); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + } | |
| 75 | + } | |
| 47 | 76 | } | ... | ... |
src/main/java/com/cnlive/shenhe/serviceImpl/AudioServiceImpl.java
| ... | ... | @@ -3,22 +3,24 @@ package com.cnlive.shenhe.serviceImpl; |
| 3 | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | 4 | import com.cnlive.shenhe.bean.ErrorEnum; |
| 5 | 5 | import com.cnlive.shenhe.bean.ResponseBean; |
| 6 | -import com.cnlive.shenhe.entity.ShyAudio; | |
| 7 | -import com.cnlive.shenhe.entity.ShyUsers; | |
| 8 | -import com.cnlive.shenhe.entity.ShyVideos; | |
| 6 | +import com.cnlive.shenhe.entity.*; | |
| 9 | 7 | import com.cnlive.shenhe.mapper.ShyAudioMapper; |
| 10 | 8 | import com.cnlive.shenhe.mapper.ShyUsersMapper; |
| 11 | 9 | import com.cnlive.shenhe.utils.AuditPass; |
| 12 | 10 | import com.cnlive.shenhe.utils.CommonConst; |
| 13 | 11 | import com.cnlive.shenhe.utils.CommonUtils; |
| 12 | +import com.cnlive.shenhe.utils.YiDunAntiFraudUtil; | |
| 14 | 13 | import com.github.pagehelper.PageHelper; |
| 15 | 14 | import com.github.pagehelper.PageInfo; |
| 16 | 15 | import org.apache.ibatis.session.RowBounds; |
| 17 | 16 | import org.slf4j.Logger; |
| 18 | 17 | import org.slf4j.LoggerFactory; |
| 19 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 19 | +import org.springframework.beans.factory.annotation.Value; | |
| 20 | 20 | import org.springframework.stereotype.Service; |
| 21 | 21 | import tk.mybatis.mapper.entity.Example; |
| 22 | + | |
| 23 | +import java.util.Date; | |
| 22 | 24 | import java.util.List; |
| 23 | 25 | |
| 24 | 26 | /** |
| ... | ... | @@ -44,6 +46,10 @@ public class AudioServiceImpl { |
| 44 | 46 | |
| 45 | 47 | @Autowired |
| 46 | 48 | SitesServiceImpl sitesService; |
| 49 | + @Autowired | |
| 50 | + YiDunServiceImpl yiDunServiceImpl; | |
| 51 | + @Value("${yiDun_audio_callback}") | |
| 52 | + String yiDun_audio_callback; | |
| 47 | 53 | |
| 48 | 54 | public ShyAudio getAudioMsg(String audioId) { |
| 49 | 55 | return shyAudioMapper.getAudioMsg(audioId); |
| ... | ... | @@ -337,7 +343,7 @@ public class AudioServiceImpl { |
| 337 | 343 | logger.info("sites" + sites.toString()); |
| 338 | 344 | //初始化一个审核状态 |
| 339 | 345 | //审核类型 1-免审 2-机审 3-人工审 |
| 340 | - Integer shenheType = 3; | |
| 346 | + Integer shenheType = 2; | |
| 341 | 347 | //如果当前sp是免审sp |
| 342 | 348 | if (sites.contains(shyAudio.getSpId())) { |
| 343 | 349 | //免审 |
| ... | ... | @@ -345,4 +351,24 @@ public class AudioServiceImpl { |
| 345 | 351 | } |
| 346 | 352 | shyAudio.setShenhe_type(shenheType); |
| 347 | 353 | } |
| 354 | + /** | |
| 355 | + * 易盾点播音频过滤 | |
| 356 | + * | |
| 357 | + * @param shyAudio | |
| 358 | + * @return | |
| 359 | + */ | |
| 360 | + public void audioFilter(ShyAudio shyAudio) { | |
| 361 | + //调用易盾点播音频检测接口 | |
| 362 | + JSONObject jsonObject = YiDunAntiFraudUtil.submitAudioOnDemandUrl(shyAudio.getAudioUrl(),yiDun_audio_callback); | |
| 363 | + if (jsonObject != null) { | |
| 364 | + JSONObject result = jsonObject.getJSONObject("result"); | |
| 365 | + String taskId = result.getString("taskId"); | |
| 366 | + ShyYidun shyYidun = new ShyYidun(); | |
| 367 | + shyYidun.setId(taskId); | |
| 368 | + shyYidun.setUrl(shyAudio.getAudioUrl()); | |
| 369 | + shyYidun.setContent_id(shyAudio.getId().toString()); | |
| 370 | + shyYidun.setCreate_time(new Date()); | |
| 371 | + yiDunServiceImpl.addYiDunMsg(shyYidun); | |
| 372 | + } | |
| 373 | + } | |
| 348 | 374 | } | ... | ... |
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
| ... | ... | @@ -113,8 +113,25 @@ public class YiDunAntiFraudUtil { |
| 113 | 113 | //getURLFilter("http://3g.huabian.com/api/hz0227/show/440549.html"); |
| 114 | 114 | |
| 115 | 115 | //智能点播音频审核 |
| 116 | - submitAudioOnDemandUrl("http://vod2017.qn.cnlive.com/60/vod/2020/0519/60_e74190fc4365479eaa206c5de9dbbe2d/ff8080817105357401722b713464073c_128.mp4"); | |
| 116 | + //submitAudioOnDemandUrl("http://vod2017.qn.cnlive.com/60/vod/2020/0519/60_e74190fc4365479eaa206c5de9dbbe2d/ff8080817105357401722b713464073c_128.mp4","http://test.shen.cnlive.com/api/audio/callbackAudio"); | |
| 117 | + //submitAudioOnDemandUrl("http://tjzg.vods2.cnlive.com/995/vod/2020/0628/995_9e3355af962e46aaa555dc2041c892d4/ff808081710535740172f901bf891c7e_128.mp4","http://test.shen.cnlive.com/api/audio/callbackAudio"); | |
| 118 | + //submitAudioOnDemandUrl("http://tjzg.vods2.cnlive.com/995/vod/2020/0628/995_949677ad3e1640fbabfb014252c8e4bd/ff808081710535740172f904769c1c92_128.mp4","http://test.shen.cnlive.com/api/audio/callbackAudio"); | |
| 119 | + //submitAudioOnDemandUrl("http://tjzg.vods2.cnlive.com/995/vod/2020/0628/995_c5fb9f1474a44906836c4f5f02070fb7/ff808081710535740172f90820321cb2_128.mp4","http://test.shen.cnlive.com/api/audio/callbackAudio"); | |
| 120 | + //submitAudioOnDemandUrl("http://tjzg.vods2.cnlive.com/995/vod/2020/0628/995_2694acb0a2b644e3841c9c615b1bdeaf/ff808081710535740172f908280c1cbe_128.mp4","http://test.shen.cnlive.com/api/audio/callbackAudio"); | |
| 121 | + | |
| 122 | + /*for (int i = 0; i < 3; i++) { | |
| 123 | + ShyYidun shyYidun = new ShyYidun(); | |
| 124 | + if(i==1){ | |
| 125 | + shyYidun.setDesc_msg("aaa"); | |
| 126 | + System.out.println(shyYidun.getDesc_msg()); | |
| 127 | + } | |
| 128 | + if(i==2){ | |
| 129 | + System.out.println(shyYidun.getDesc_msg()); | |
| 130 | + } | |
| 131 | + | |
| 132 | + | |
| 117 | 133 | |
| 134 | + }*/ | |
| 118 | 135 | } |
| 119 | 136 | |
| 120 | 137 | |
| ... | ... | @@ -124,7 +141,7 @@ public class YiDunAntiFraudUtil { |
| 124 | 141 | * @param url |
| 125 | 142 | * @return |
| 126 | 143 | */ |
| 127 | - public static JSONObject submitAudioOnDemandUrl(String url) { | |
| 144 | + public static JSONObject submitAudioOnDemandUrl(String url,String callbackUrl) { | |
| 128 | 145 | try { |
| 129 | 146 | Map<String, String> params = new HashMap<>(); |
| 130 | 147 | // 1.设置公共参数 |
| ... | ... | @@ -136,7 +153,7 @@ public class YiDunAntiFraudUtil { |
| 136 | 153 | |
| 137 | 154 | // 2.设置私有参数 |
| 138 | 155 | params.put("url", url); |
| 139 | - params.put("callbackUrl", "http://test.shen.cnlive.com/api/audio/callbackAudio"); | |
| 156 | + params.put("callbackUrl", callbackUrl); | |
| 140 | 157 | |
| 141 | 158 | // 3.生成签名信息 |
| 142 | 159 | String signature = YiDunAntiFraudUtil.genSignature(TEXTANDIMAGESECRETKEY, params); | ... | ... |
src/main/resources/application.properties
| ... | ... | @@ -103,4 +103,5 @@ ks_domain=http://test.wideo.cnlive.com |
| 103 | 103 | #ks_domain=http://sxzg.ys1.cnliveimg.com |
| 104 | 104 | |
| 105 | 105 | #\u56fe\u7247\u5b58\u653e\u6839\u8def\u5f84 |
| 106 | -desdir=shen | |
| 107 | 106 | \ No newline at end of file |
| 107 | +desdir=shen | |
| 108 | +yiDun_audio_callback=http://test.shen.cnlive.com/api/audio/callbackAudio | |
| 108 | 109 | \ No newline at end of file | ... | ... |