|
|
@ -1,11 +1,14 @@ |
|
|
package com.bnyer.file.service.impl; |
|
|
package com.bnyer.file.service.impl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.nacos.common.codec.Base64; |
|
|
import com.alibaba.nacos.common.codec.Base64; |
|
|
|
|
|
import com.bnyer.file.config.TikTokConfig; |
|
|
import com.bnyer.file.service.IQiniuService; |
|
|
import com.bnyer.file.service.IQiniuService; |
|
|
import com.bnyer.file.service.ITikTokImage; |
|
|
import com.bnyer.file.service.ITikTokImage; |
|
|
import com.bnyer.file.utils.HttpUtils; |
|
|
import com.bnyer.file.utils.HttpUtils; |
|
|
|
|
|
import com.bnyer.file.utils.ImgUtil; |
|
|
import com.bnyer.file.utils.StringUtil; |
|
|
import com.bnyer.file.utils.StringUtil; |
|
|
import com.google.gson.Gson; |
|
|
import com.google.gson.Gson; |
|
|
import com.google.gson.JsonSyntaxException; |
|
|
import com.google.gson.JsonSyntaxException; |
|
|
@ -18,6 +21,7 @@ import com.qiniu.storage.UploadManager; |
|
|
import com.qiniu.storage.model.DefaultPutRet; |
|
|
import com.qiniu.storage.model.DefaultPutRet; |
|
|
import com.qiniu.util.Auth; |
|
|
import com.qiniu.util.Auth; |
|
|
import com.qiniu.util.StringMap; |
|
|
import com.qiniu.util.StringMap; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
@ -36,17 +40,12 @@ import java.util.HashMap; |
|
|
*/ |
|
|
*/ |
|
|
@Service("tiktokImage") |
|
|
@Service("tiktokImage") |
|
|
public class TikTokImageServiceImpl implements ITikTokImage { |
|
|
public class TikTokImageServiceImpl implements ITikTokImage { |
|
|
@Value("${tiktok.appId}") |
|
|
@Autowired |
|
|
private static String appId; |
|
|
private TikTokConfig tikTokConfig; |
|
|
|
|
|
|
|
|
@Value("${tiktok.secret}") |
|
|
|
|
|
private static String secret; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${tiktok.grant_type}") |
|
|
|
|
|
private static String grant_type; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${qiniu.url}") |
|
|
|
|
|
private String getTokenUrl="https://developer.toutiao.com/api/apps/v2/token"; |
|
|
private String getTokenUrl="https://developer.toutiao.com/api/apps/v2/token"; |
|
|
|
|
|
|
|
|
|
|
|
private String checkImgUrl="https://developer.toutiao.com/api/apps/censor/image"; |
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -54,15 +53,35 @@ public class TikTokImageServiceImpl implements ITikTokImage { |
|
|
public Boolean checkImageContent(MultipartFile file) { |
|
|
public Boolean checkImageContent(MultipartFile file) { |
|
|
String token=""; |
|
|
String token=""; |
|
|
HashMap<String, Object> param = new HashMap<>(); |
|
|
HashMap<String, Object> param = new HashMap<>(); |
|
|
param.put("appId", appId); |
|
|
param.put("appId", tikTokConfig.getAppId()); |
|
|
param.put("secret", secret); |
|
|
param.put("secret", tikTokConfig.getSecret()); |
|
|
param.put("grant_type", grant_type); |
|
|
param.put("grant_type", tikTokConfig.getGrant_type()); |
|
|
String body = JSON.toJSONString(param); |
|
|
String body = JSON.toJSONString(param); |
|
|
String res = HttpUtils.sendPost(getTokenUrl, body); |
|
|
String res = HttpUtils.sendPost(getTokenUrl, body); |
|
|
String err_tips = JSON.parseObject(res).get("err_tips").toString(); |
|
|
String err_tips = JSON.parseObject(res).get("err_tips").toString(); |
|
|
if (err_tips.equals("success")){ |
|
|
if (err_tips.equals("success")){ |
|
|
token=JSON.parseObject(err_tips).get("access_token").toString(); |
|
|
res=JSON.parseObject(res).get("data").toString(); |
|
|
|
|
|
token=JSON.parseObject(res).get("access_token").toString(); |
|
|
|
|
|
} |
|
|
|
|
|
if (token!=""){ |
|
|
|
|
|
HashMap<String, Object> checkParam = new HashMap<>(); |
|
|
|
|
|
checkParam.put("app_id", tikTokConfig.getAppId()); |
|
|
|
|
|
checkParam.put("access_token", token); |
|
|
|
|
|
checkParam.put("image_data", ImgUtil.getImageString(file)); |
|
|
|
|
|
String checkBody = JSON.toJSONString(checkParam); |
|
|
|
|
|
String checkRes = HttpUtils.sendPost(checkImgUrl, checkBody); |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(checkRes); |
|
|
|
|
|
JSONArray predicts = JSON.parseArray(jsonObject.get("predicts").toString()); |
|
|
|
|
|
for (Object predict : predicts) { |
|
|
|
|
|
String hit = JSON.parseObject(predict.toString()).get("hit").toString(); |
|
|
|
|
|
if (hit.equals("true")) { |
|
|
|
|
|
//System.out.println("不通过==========================");
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
//System.out.println(predict+"===================");
|
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
return null; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|