...
|
...
|
@@ -2,13 +2,21 @@ package com.yohoufo.common.helper; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.tools.common.beans.Response;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.HashMap;
|
...
|
...
|
@@ -29,14 +37,17 @@ public class ReviewHelper { |
|
|
@Value("${yoho.reviewed.text.license}")
|
|
|
private String textLicense;
|
|
|
|
|
|
@Value("${yoho.reviewed.pic.license}")
|
|
|
private String picLicense;
|
|
|
|
|
|
@Resource(name = "core-config-reader")
|
|
|
private ConfigReader configReader;
|
|
|
|
|
|
@Value("${yoho.reviewed.controller.url}")
|
|
|
private String reviewedUrl;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
@Value("${web.context}")
|
|
|
private String contextPath;
|
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -50,7 +61,7 @@ public class ReviewHelper { |
|
|
//文本审核降级开关 todo shit zk 上定义下设置一下
|
|
|
boolean isDegrade = configReader.getBoolean("sns.baiduAudit.text.degrade",false);
|
|
|
if(isDegrade){
|
|
|
logger.info("baiduApi sns.baiduAudit.text.degrade is true ");
|
|
|
logger.info("baiduApi ufo-gateway.baiduAudit.text.degrade is true ");
|
|
|
return true;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -63,27 +74,27 @@ public class ReviewHelper { |
|
|
Map<String , String> req = new HashMap<>();
|
|
|
req.put("content",checkContent);
|
|
|
req.put("uid",String.valueOf(uid));
|
|
|
req.put("sceneName","COMMENT_CENSOR");
|
|
|
req.put("sceneName","COMMENT_CENSOR_UFO");
|
|
|
req.put("businessLine","ufo");
|
|
|
req.put("license",textLicense);
|
|
|
req.put("businessLine","sns");
|
|
|
req.put("context","sns");
|
|
|
// req.put("extraParams",extraParams.toJSONString());
|
|
|
req.put("context",contextPath);
|
|
|
logger.warn("begin call reviewText , checkContent is {}",checkContent);
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
JSONObject result = serviceCaller.call("reviewed.textAudit", req,JSONObject.class, 5);
|
|
|
Response<JSONObject> result = textAudit(req);
|
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
logger.warn("call reviewText success, use time is {}, rsp is{}",endTime-startTime, result);
|
|
|
|
|
|
//接口返回非200,直接审核失败
|
|
|
if(result.getInteger("code")!=200){
|
|
|
if(result.getCode() != 200){
|
|
|
return false;
|
|
|
}
|
|
|
if( result.getJSONObject("data")==null){
|
|
|
if(result.getData() == null){
|
|
|
logger.warn("call reviewText response data is null");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if(result.getJSONObject("data").getInteger("resultCode") != 1){
|
|
|
if(result.getData().getInteger("resultCode") != 1){
|
|
|
logger.warn("call reviewText response auto fail");
|
|
|
return false;
|
|
|
}
|
...
|
...
|
@@ -109,4 +120,23 @@ public class ReviewHelper { |
|
|
}
|
|
|
|
|
|
|
|
|
public Response<JSONObject> textAudit(Map<String , String> req) {
|
|
|
Response<JSONObject> respVo = null;
|
|
|
try{
|
|
|
String url = reviewedUrl + "/textAudit/textAudit";
|
|
|
logger.info("textAudit call textAudit sendMessage url is {}", url);
|
|
|
//respVo=restTemplate.postForObject(url, req, Response.class);
|
|
|
|
|
|
ParameterizedTypeReference<Response<JSONObject>> typeRef = new ParameterizedTypeReference<Response<JSONObject>>() {};
|
|
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap();
|
|
|
headers.set("Content-Type", "application/json; charset=UTF-8");
|
|
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
|
|
HttpEntity httpEntity = new HttpEntity(req, headers);
|
|
|
ResponseEntity<Response<JSONObject>> responseEntity = restTemplate.exchange(url, HttpMethod.POST,httpEntity, typeRef);
|
|
|
respVo = responseEntity.getBody();
|
|
|
}catch (Exception e){
|
|
|
logger.warn("textAudit call textAudit error ",e);
|
|
|
}
|
|
|
return respVo;
|
|
|
}
|
|
|
} |
...
|
...
|
|