web123456

Dark Horse Headlines Articles and Picture Review

  • package ;
  • import ;
  • import ;
  • import ;
  • import .slf4j.Slf4j;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import .*;
  • @Getter
  • @Setter
  • @Slf4j
  • @Component
  • @ConfigurationProperties(prefix = "baiduyun")
  • public class ContentCensor {
  • private String baiduyunId;
  • private String baiduyunSecret;
  • /**
  • * Text review
  • *
  • * @paramtext text to be reviewed
  • * @returnReview results { log_id, conclusion, conclusionType }
  • * @throwsException Audit exception
  • */
  • public Map<String, Object> textCensor(String text) throws Exception {
  • String accessToken = (baiduyunId, baiduyunSecret);
  • FormBody formBody = new FormBody.Builder().add("text", text).build();
  • Request request = new Request.Builder()
  • .url(("/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=%s", accessToken))
  • .method("POST", formBody)
  • .addHeader("Content-Type", "application/x-www-form-urlencoded")
  • .addHeader("Accept", "application/json")
  • .build();
  • Response response = AuthUtil.HTTP_CLIENT.newCall(request).execute();
  • String strBody = ().string();
  • if (() != ()) {
  • JSONObject errObj = (strBody);
  • ("Baidu text audit interface call failed: error_code: {}, error_msg: {}", ("error_code"), ("error_msg"));
  • throw new RuntimeException("Baidu text audit interface call failed");
  • }
  • JSONObject resultObj = (strBody);
  • (resultObj);
  • Map<String, Object> result = new HashMap<>();
  • ("log_id", ("log_id"));
  • ("conclusion", ("conclusion"));
  • ("conclusionType", ("conclusionType"));
  • return result;
  • }
  • /**
  • * Image review
  • *
  • * @paramimgParams List of images to be reviewed Base64 string list
  • * @returnReview results { log_id, conclusion, conclusionType }
  • * @throwsException Audit exception
  • */
  • public Map imgCensor(ArrayList<byte[]> imgParams) throws Exception {
  • String accessToken = (baiduyunId, baiduyunSecret);
  • Request.Builder builder = new Request.Builder()
  • .url(("/rest/2.0/solution/v1/img_censor/v2/user_defined?access_token=%s", accessToken))
  • .addHeader("Content-Type", "application/x-www-form-urlencoded")
  • .addHeader("Accept", "application/json");
  • Map<String, Object> result = new HashMap<>();
  • for (Object imgParam : imgParams) {
  • FormBody formBody = new FormBody.Builder().add("image", (imgParam)).build();
  • Request request = ("POST", formBody).build();
  • Response response = AuthUtil.HTTP_CLIENT.newCall(request).execute();
  • String strBody = ().string();
  • if (() != ()) {
  • JSONObject errObj = (strBody);
  • ("Baidu Image Audit Interface Call failed: error_code: {}, error_msg: {}", ("error_code"), ("error_msg"));
  • throw new RuntimeException("Baidu text audit interface call failed");
  • }
  • JSONObject resultObj = (strBody);
  • (resultObj);
  • Short conclusionType = ("conclusionType");
  • // The review is not passed
  • if (!(conclusionType, ())) {
  • ("log_id", ("log_id"));
  • ("conclusion", ("conclusion"));
  • ("conclusionType", ("conclusionType"));
  • return result;
  • }
  • }
  • ("conclusionType", ());
  • return result;
  • }
  • }