13 changed files with 421 additions and 63 deletions
@ -0,0 +1,27 @@ |
|||
package com.bnyer.file.config; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* @Author: qyh |
|||
* @Date: 2022-06-12-16:24 |
|||
* @Description: |
|||
*/ |
|||
@Configuration |
|||
@RefreshScope |
|||
@Getter |
|||
@Setter |
|||
public class TikTokConfig { |
|||
@Value("${tiktok.appId}") |
|||
private String appId; |
|||
|
|||
@Value("${tiktok.secret}") |
|||
private String secret; |
|||
|
|||
@Value("${tiktok.grant_type}") |
|||
private String grant_type; |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
package com.bnyer.file.service; |
|||
|
|||
import com.bnyer.file.vo.TiktokImgVo; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
/** |
|||
* @Author: qyh |
|||
* @Date: 2022-06-16-11:03 |
|||
* @Description: |
|||
*/ |
|||
public interface IFileService { |
|||
ArrayList<TiktokImgVo> checkImg(ArrayList<MultipartFile> multipartFiles); |
|||
} |
|||
@ -1,9 +1,20 @@ |
|||
package com.bnyer.file.service; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.io.File; |
|||
import java.util.ArrayList; |
|||
|
|||
public interface IQiniuService { |
|||
String userUpload(MultipartFile file); |
|||
|
|||
String checkImageContent(String imageUrl); |
|||
|
|||
/** |
|||
* 检查图片格式 |
|||
* @param multipartFiles |
|||
* @return |
|||
*/ |
|||
ArrayList<MultipartFile> checkImageFormat(ArrayList<MultipartFile> multipartFiles); |
|||
} |
|||
|
|||
@ -0,0 +1,71 @@ |
|||
package com.bnyer.file.service.impl; |
|||
|
|||
import cn.hutool.core.img.Img; |
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.bnyer.file.config.TikTokConfig; |
|||
import com.bnyer.file.service.IFileService; |
|||
import com.bnyer.file.service.IQiniuService; |
|||
import com.bnyer.file.service.ITikTokImage; |
|||
import com.bnyer.file.utils.HttpUtils; |
|||
import com.bnyer.file.utils.ImgUtil; |
|||
import com.bnyer.file.vo.TiktokImgVo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
|
|||
/** |
|||
* @Author: Yeman |
|||
* @Date: 2022-06-08-10:51 |
|||
* @Description: |
|||
*/ |
|||
@Service("file") |
|||
public class FileServiceImpl implements IFileService { |
|||
@Autowired |
|||
private IQiniuService qiniuService; |
|||
@Autowired |
|||
private ITikTokImage tikTokImage; |
|||
@Override |
|||
public ArrayList<TiktokImgVo> checkImg(ArrayList<MultipartFile> multipartFiles) { |
|||
ArrayList<TiktokImgVo> tiktokImgVos = new ArrayList<>(); |
|||
//返回通过校验的数组
|
|||
ArrayList<MultipartFile> multipartFileList = qiniuService.checkImageFormat(multipartFiles); |
|||
for (MultipartFile multipartFile : multipartFileList) { |
|||
TiktokImgVo tiktokImgVo = new TiktokImgVo(); |
|||
String filename = multipartFile.getResource().getFilename(); |
|||
tiktokImgVo.setFileName(filename); |
|||
String imageString = ImgUtil.getImageString(multipartFile); |
|||
String checkMsg = qiniuService.checkImageContent("data:application/octet-stream;base64," +imageString); |
|||
if (checkMsg.equals("pass")){ |
|||
//抖音图片检测二次检测
|
|||
if (tikTokImage.checkImageContent(multipartFile)) { |
|||
//可以通过
|
|||
tiktokImgVo.setStatus("1"); |
|||
tiktokImgVos.add(tiktokImgVo); |
|||
}else { |
|||
//不可以通过
|
|||
tiktokImgVo.setStatus("2"); |
|||
tiktokImgVos.add(tiktokImgVo); |
|||
} |
|||
continue; |
|||
} |
|||
if (checkMsg.equals("review")){ |
|||
//人工审核
|
|||
tiktokImgVo.setStatus("0"); |
|||
tiktokImgVos.add(tiktokImgVo); |
|||
continue; |
|||
} |
|||
if (checkMsg.equals("block")){ |
|||
//不可通过
|
|||
tiktokImgVo.setStatus("2"); |
|||
tiktokImgVos.add(tiktokImgVo); |
|||
continue; |
|||
} |
|||
} |
|||
return tiktokImgVos; |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
package com.bnyer.file.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("抖音图片响应类") |
|||
public class TiktokImgVo implements Serializable { |
|||
|
|||
@ApiModelProperty(value="id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="图片地址") |
|||
private String imgUrl; |
|||
|
|||
@ApiModelProperty(value="用户id") |
|||
private Long creatorId; |
|||
|
|||
@ApiModelProperty(value="分类id") |
|||
private Long typeId; |
|||
|
|||
@ApiModelProperty(value="下载量") |
|||
private Integer downloadNum; |
|||
|
|||
@ApiModelProperty(value="点赞量") |
|||
private Integer greatNum; |
|||
|
|||
@ApiModelProperty(value="收藏量") |
|||
private Integer collectionNum; |
|||
|
|||
@ApiModelProperty(value="状态(0->待审核;1->审核通过;2->审核拒绝)") |
|||
private String status; |
|||
|
|||
@ApiModelProperty(value="是否热门(0->冷门;1->热门)") |
|||
private String isHot; |
|||
|
|||
private String fileName; |
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
Loading…
Reference in new issue