21 changed files with 996 additions and 65 deletions
@ -0,0 +1,25 @@ |
|||
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: chengkun |
|||
* @Date: 2022-06-12-16:24 |
|||
* @Description: |
|||
*/ |
|||
@Configuration |
|||
@RefreshScope |
|||
@Getter |
|||
@Setter |
|||
public class ImgConfig { |
|||
|
|||
@Value("${img.fileSize}") |
|||
private String fileSize; |
|||
|
|||
@Value("${img.accuracy}") |
|||
private String accuracy; |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
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; |
|||
|
|||
@Configuration |
|||
@RefreshScope |
|||
@Getter |
|||
@Setter |
|||
public class QiniuConfig { |
|||
|
|||
@Value("${qiniu.accessKey}") |
|||
private String accessKey; |
|||
|
|||
@Value("${qiniu.secretKey}") |
|||
private String secretKey; |
|||
|
|||
@Value("${qiniu.bucketName}") |
|||
private String bucketName; |
|||
|
|||
@Value("${qiniu.url}") |
|||
private String url; |
|||
|
|||
@Value("${qiniu.qiniuHostUrl}") |
|||
private String qiniuHostUrl; |
|||
|
|||
@Value("${qiniu.qiniuCheckImgUrl}") |
|||
private String qiniuCheckImgUrl; |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
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 grantType; |
|||
|
|||
@Value("${tiktok.tokenUrl}") |
|||
private String tokenUrl; |
|||
|
|||
@Value("${tiktok.checkImgUrl}") |
|||
private String checkImgUrl; |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
package com.bnyer.file.service; |
|||
|
|||
import com.bnyer.file.vo.ChekFileVo; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
/** |
|||
* @Author: qyh |
|||
* @Date: 2022-06-16-11:03 |
|||
* @Description: |
|||
*/ |
|||
public interface IFileService { |
|||
ArrayList<ChekFileVo> checkImg(ArrayList<MultipartFile> multipartFiles); |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
package com.bnyer.file.service; |
|||
|
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
public interface IQiniuService { |
|||
String userUpload(MultipartFile file); |
|||
|
|||
/** |
|||
* 检查图片内容是否符合规定 |
|||
* @param imageUrl 图片的url地址或者图片Base64编码(Base64编码请求时应在开头加上data:application/octet-stream;base64,) |
|||
* @return JSONObject |
|||
*/ |
|||
String checkImageContent(String imageUrl); |
|||
|
|||
/** |
|||
* 检查图片格式 |
|||
* @param multipartFiles |
|||
* @return |
|||
*/ |
|||
ArrayList<MultipartFile> checkImageFormat(ArrayList<MultipartFile> multipartFiles); |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
package com.bnyer.file.service; |
|||
|
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
/** |
|||
* @Author: qyh |
|||
* @Date: 2022-06-08-18:44 |
|||
* @Description: |
|||
*/ |
|||
public interface ITikTokImage { |
|||
//抖音图片审核
|
|||
Boolean checkImageContent(MultipartFile file); |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
package com.bnyer.file.service.impl; |
|||
|
|||
import com.bnyer.file.service.IFileService; |
|||
import com.bnyer.file.service.IQiniuService; |
|||
import com.bnyer.file.service.ITikTokImage; |
|||
import com.bnyer.file.utils.ImgUtil; |
|||
import com.bnyer.file.vo.ChekFileVo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
/** |
|||
* @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<ChekFileVo> checkImg(ArrayList<MultipartFile> multipartFiles) { |
|||
ArrayList<ChekFileVo> chekFileVos = new ArrayList<>(); |
|||
//返回通过校验的数组
|
|||
ArrayList<MultipartFile> multipartFileList = qiniuService.checkImageFormat(multipartFiles); |
|||
for (MultipartFile multipartFile : multipartFileList) { |
|||
ChekFileVo chekFileVo = new ChekFileVo(); |
|||
String filename = multipartFile.getResource().getFilename(); |
|||
chekFileVo.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)) { |
|||
//可以通过
|
|||
chekFileVo.setStatus("1"); |
|||
chekFileVos.add(chekFileVo); |
|||
}else { |
|||
//不可以通过
|
|||
chekFileVo.setStatus("2"); |
|||
chekFileVos.add(chekFileVo); |
|||
} |
|||
continue; |
|||
} |
|||
if (checkMsg.equals("review")){ |
|||
//人工审核
|
|||
chekFileVo.setStatus("0"); |
|||
chekFileVos.add(chekFileVo); |
|||
continue; |
|||
} |
|||
if (checkMsg.equals("block")){ |
|||
//不可通过
|
|||
chekFileVo.setStatus("2"); |
|||
chekFileVos.add(chekFileVo); |
|||
} |
|||
} |
|||
return chekFileVos; |
|||
} |
|||
} |
|||
@ -0,0 +1,193 @@ |
|||
package com.bnyer.file.service.impl; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.bnyer.file.config.QiniuConfig; |
|||
import com.bnyer.file.service.IQiniuService; |
|||
import com.bnyer.file.utils.StringUtil; |
|||
import com.google.gson.Gson; |
|||
import com.google.gson.JsonSyntaxException; |
|||
import com.qiniu.common.QiniuException; |
|||
import com.qiniu.common.Zone; |
|||
import com.qiniu.http.Client; |
|||
import com.qiniu.http.Response; |
|||
import com.qiniu.storage.Configuration; |
|||
import com.qiniu.storage.UploadManager; |
|||
import com.qiniu.storage.model.DefaultPutRet; |
|||
import com.qiniu.util.Auth; |
|||
import com.qiniu.util.StringMap; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.util.ArrayList; |
|||
|
|||
/** |
|||
* @Author: Yeman |
|||
* @Date: 2022-06-08-10:51 |
|||
* @Description: |
|||
*/ |
|||
@Service |
|||
public class QiniuServiceImpl implements IQiniuService { |
|||
|
|||
@Autowired |
|||
private QiniuConfig qiniuConfig; |
|||
private Zone zone = new Zone.Builder(Zone.autoZone()) |
|||
.upHttp("http://upload.qiniup.com") |
|||
.upHttps("http://upload.qiniup.com") |
|||
.upBackupHttp("http://upload.qiniup.com") |
|||
.upBackupHttps("http://upload.qiniup.com") |
|||
.rsHttp("http://rs.qiniu.com") |
|||
.rsfHttp("http://rsf.qiniu.com") |
|||
.apiHttp("http://api.qiniu.com") |
|||
.iovipHttp("http://iovip.qbox.me").build(); |
|||
@Override |
|||
public String userUpload(MultipartFile file) { |
|||
return this.updloadFile(file); |
|||
} |
|||
public String updloadFile(MultipartFile file){ |
|||
String url = null; |
|||
// 获取文件的名称
|
|||
String fileName = file.getOriginalFilename(); |
|||
//构造一个带指定 Region 对象的配置类
|
|||
Configuration cfg = new Configuration(zone); |
|||
cfg.useHttpsDomains=false; |
|||
UploadManager uploadManager = new UploadManager(cfg); |
|||
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey()); |
|||
String token = auth.uploadToken(qiniuConfig.getBucketName()); |
|||
// 使用工具类根据上传文件生成唯一图片名称
|
|||
String imgName = StringUtil.getRandomImgName(fileName); |
|||
if (!file.isEmpty()) { |
|||
InputStream inputStream =null; |
|||
try { |
|||
inputStream=(InputStream) file.getInputStream(); |
|||
Response response = uploadManager.put(inputStream, imgName, token,null,null); |
|||
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); |
|||
url=qiniuConfig.getUrl()+"/"+putRet.key; |
|||
//System.out.println(putRet.hash);
|
|||
inputStream.close(); |
|||
} catch (QiniuException ex) { |
|||
ex.printStackTrace(); |
|||
return "error"; |
|||
} catch (JsonSyntaxException e) { |
|||
e.printStackTrace(); |
|||
return "error"; |
|||
}catch (IOException ioe){ |
|||
ioe.printStackTrace(); |
|||
return "error"; |
|||
} |
|||
return url; |
|||
} |
|||
return "error"; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public String checkImageContent(String imageUrl) { |
|||
//基础参数拼接
|
|||
String url = qiniuConfig.getQiniuCheckImgUrl(); |
|||
String host = qiniuConfig.getQiniuHostUrl(); |
|||
String body = "{ \"data\": { \"uri\": \""+imageUrl+"\" }, \"params\": { \"scenes\": [ \"pulp\", \"terror\", \"politician\" ] } }"; |
|||
String contentType = "application/json"; |
|||
String method = "POST"; |
|||
String accessKey= qiniuConfig.getAccessKey(); |
|||
String secretKey= qiniuConfig.getSecretKey(); |
|||
Auth auth = Auth.create(accessKey, secretKey); |
|||
String qiniuToken = "Qiniu " + auth.signRequestV2(url, method, body.getBytes(), contentType); |
|||
//头部部分
|
|||
StringMap header = new StringMap(); |
|||
header.put("Host",host); |
|||
header.put("Authorization",qiniuToken); |
|||
header.put("Content-Type", contentType); |
|||
Configuration c = new Configuration(zone); |
|||
Client client = new Client(c); |
|||
try { |
|||
Response response = client.post(url, body.getBytes(), header, contentType); |
|||
JSONObject checkResult = JSON.parseObject(response.bodyString()); |
|||
return JSON.parseObject(checkResult.get("result").toString()).get("suggestion").toString(); |
|||
} catch (QiniuException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 检查图片的格式 |
|||
* @param multipartFiles |
|||
* @return 格式正确的文件 |
|||
*/ |
|||
@Override |
|||
public ArrayList<MultipartFile> checkImageFormat(ArrayList<MultipartFile> multipartFiles){ |
|||
ArrayList<MultipartFile> afterCheckFiles = new ArrayList<>(); |
|||
for (MultipartFile multipartFile : multipartFiles) { |
|||
ArrayList<String> imageSuffixList = new ArrayList<>(); |
|||
String suffix = getSuffix(multipartFile); |
|||
//图片后缀
|
|||
imageSuffixList.add("jpg"); |
|||
imageSuffixList.add("png"); |
|||
imageSuffixList.add("avi"); |
|||
imageSuffixList.add("flv"); |
|||
imageSuffixList.add("mpg"); |
|||
imageSuffixList.add("mpeg"); |
|||
imageSuffixList.add("mpe"); |
|||
imageSuffixList.add("m1v"); |
|||
imageSuffixList.add("m2v"); |
|||
imageSuffixList.add("mpv2"); |
|||
imageSuffixList.add("mp2v"); |
|||
imageSuffixList.add("dat"); |
|||
imageSuffixList.add("ts"); |
|||
imageSuffixList.add("tp"); |
|||
imageSuffixList.add("tpr"); |
|||
imageSuffixList.add("pva"); |
|||
imageSuffixList.add("pss"); |
|||
imageSuffixList.add("mp4"); |
|||
imageSuffixList.add("m4v"); |
|||
imageSuffixList.add("m4p"); |
|||
imageSuffixList.add("m4b"); |
|||
imageSuffixList.add("3gp"); |
|||
imageSuffixList.add("3gpp"); |
|||
imageSuffixList.add("3g2"); |
|||
imageSuffixList.add("3gp2"); |
|||
imageSuffixList.add("ogg"); |
|||
imageSuffixList.add("mov"); |
|||
imageSuffixList.add("qt"); |
|||
imageSuffixList.add("amr"); |
|||
imageSuffixList.add("rm"); |
|||
imageSuffixList.add("ram"); |
|||
imageSuffixList.add("rmvb"); |
|||
imageSuffixList.add("rpm"); |
|||
//判断视频的后缀 MP4、MOV、WMV
|
|||
ArrayList<String> videoSuffixList = new ArrayList<>(); |
|||
videoSuffixList.add("mp4"); |
|||
videoSuffixList.add("mov"); |
|||
videoSuffixList.add("wmv"); |
|||
if (suffix != null&&imageSuffixList.contains(suffix)&&multipartFile.getSize() / 1024 < 50000&&multipartFile.getSize() / 1024 > 0) { |
|||
afterCheckFiles.add(multipartFile); |
|||
} |
|||
} |
|||
return afterCheckFiles; |
|||
} |
|||
|
|||
public static String getSuffix(MultipartFile file) { |
|||
String originalFilename = file.getOriginalFilename(); |
|||
//System.out.println(originalFilename);
|
|||
int dot = originalFilename.lastIndexOf('.'); |
|||
int fileNameLength = originalFilename.length(); |
|||
if ((dot > -1) && (dot < (originalFilename.length()))) { |
|||
String suffix = originalFilename.substring(dot + 1, fileNameLength); |
|||
return suffix.toLowerCase(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
// public static void main(String[] args) {
|
|||
//
|
|||
// String imageString = ImgUtil.getImageString("C:\\Users\\ASUS\\Documents\\WeChat Files\\wxid_vzk0z5ghy6q922\\FileStorage\\File\\2020-09\\20220608134731.png");
|
|||
// JSONObject jsonObject = checkImageContent("data:application/octet-stream;base64," + imageString);
|
|||
// System.out.println(JSON.parseObject(jsonObject.get("result").toString()).get("suggestion").toString());
|
|||
// System.out.println(jsonObject);
|
|||
// }
|
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
package com.bnyer.file.service.impl; |
|||
|
|||
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.ITikTokImage; |
|||
import com.bnyer.file.utils.HttpUtils; |
|||
import com.bnyer.file.utils.ImgUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.HashMap; |
|||
|
|||
/** |
|||
* @Author: Yeman |
|||
* @Date: 2022-06-08-10:51 |
|||
* @Description: |
|||
*/ |
|||
@Service("tiktokImage") |
|||
public class TikTokImageServiceImpl implements ITikTokImage { |
|||
@Autowired |
|||
private TikTokConfig tikTokConfig; |
|||
|
|||
@Override |
|||
public Boolean checkImageContent(MultipartFile file) { |
|||
String token=""; |
|||
HashMap<String, Object> param = new HashMap<>(); |
|||
param.put("appId", tikTokConfig.getAppId()); |
|||
param.put("secret", tikTokConfig.getSecret()); |
|||
param.put("grant_type", tikTokConfig.getGrantType()); |
|||
String body = JSON.toJSONString(param); |
|||
String res = HttpUtils.sendPost(tikTokConfig.getTokenUrl(), body); |
|||
String err_tips = JSON.parseObject(res).get("err_tips").toString(); |
|||
if (err_tips.equals("success")){ |
|||
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(tikTokConfig.getCheckImgUrl(), 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 false; |
|||
} |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
package com.bnyer.file.utils; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import java.io.BufferedReader; |
|||
import java.io.IOException; |
|||
import java.io.InputStreamReader; |
|||
import java.io.PrintWriter; |
|||
import java.net.URL; |
|||
import java.net.URLConnection; |
|||
|
|||
/** |
|||
* @Author: qyh |
|||
* @Date: 2022-06-08-18:52 |
|||
* @Description: |
|||
*/ |
|||
@Slf4j |
|||
public class HttpUtils { |
|||
/** |
|||
* 向指定 URL 发送POST方法的请求 |
|||
* |
|||
* @param url 发送请求的 URL |
|||
* @param param 请求参数 |
|||
* @return 所代表远程资源的响应结果 |
|||
*/ |
|||
public static String sendPost(String url, String param) { |
|||
PrintWriter out = null; |
|||
BufferedReader in = null; |
|||
String result = ""; |
|||
try { |
|||
URL realUrl = new URL(url); |
|||
|
|||
log.info("post"+url+param); |
|||
// 打开和URL之间的连接
|
|||
URLConnection conn = realUrl.openConnection(); |
|||
// 设置通用的请求属性
|
|||
conn.setRequestProperty("content-type", "application/json"); |
|||
// 发送POST请求必须设置如下两行
|
|||
|
|||
conn.setDoOutput(true); |
|||
conn.setDoInput(true); |
|||
conn.setConnectTimeout(15000); |
|||
conn.setReadTimeout(15000); |
|||
// 获取URLConnection对象对应的输出流
|
|||
out = new PrintWriter(conn.getOutputStream()); |
|||
// 发送请求参数
|
|||
out.print(param); |
|||
// flush输出流的缓冲
|
|||
out.flush(); |
|||
// 定义BufferedReader输入流来读取URL的响应
|
|||
in = new BufferedReader( |
|||
new InputStreamReader(conn.getInputStream())); |
|||
String line; |
|||
while ((line = in.readLine()) != null) { |
|||
result += line; |
|||
} |
|||
} catch (Exception e) { |
|||
log.info("发送 POST 请求出现异常!" + e); |
|||
e.printStackTrace(); |
|||
} |
|||
//使用finally块来关闭输出流、输入流
|
|||
finally { |
|||
try { |
|||
if (out != null) { |
|||
out.close(); |
|||
} |
|||
if (in != null) { |
|||
in.close(); |
|||
} |
|||
} catch (IOException ex) { |
|||
ex.printStackTrace(); |
|||
} |
|||
} |
|||
log.info(result); |
|||
return result; |
|||
} |
|||
} |
|||
@ -0,0 +1,162 @@ |
|||
package com.bnyer.file.utils; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import java.util.Map; |
|||
import java.util.UUID; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* @Author: Yeman |
|||
* @Date: 2022-06-08-11:08 |
|||
* @Description: |
|||
*/ |
|||
@Slf4j |
|||
public class StringUtil { |
|||
/** |
|||
* 数值类型前面补零(共13位) |
|||
* @param num |
|||
* @return |
|||
*/ |
|||
public static String supplementZeroGenerateThirteen(int num){ |
|||
String str = String.format("%013d", num); |
|||
|
|||
return str; |
|||
} |
|||
|
|||
/** |
|||
* 数值类型前面补零(共16位) |
|||
* @param num |
|||
* @return |
|||
*/ |
|||
public static String supplementZeroGenerateSixteen(int num){ |
|||
String str = String.format("%016d", num); |
|||
|
|||
return str; |
|||
} |
|||
/** |
|||
* 数值类型前面补零(共3位) |
|||
* @param num |
|||
* @return |
|||
*/ |
|||
public static String supplementZeroGenerateThree(int num){ |
|||
String str = String.format("%03d", num); |
|||
|
|||
return str; |
|||
} |
|||
|
|||
/** |
|||
* 判断字符串是不是double型 |
|||
* @param str |
|||
* @return |
|||
*/ |
|||
public static boolean isNumeric(String str){ |
|||
Pattern pattern = Pattern.compile("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"); |
|||
Matcher isNum = pattern.matcher(str); |
|||
if( !isNum.matches() ){ |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
public static String trim(String str, boolean nullFlag){ |
|||
String tempStr = null; |
|||
|
|||
if (str != null) |
|||
{ |
|||
tempStr = str.trim(); |
|||
} |
|||
|
|||
if (nullFlag) |
|||
{ |
|||
if ("".equals(tempStr) || "null".equals(tempStr)) |
|||
{ |
|||
tempStr = null; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (tempStr == null) |
|||
{ |
|||
tempStr = ""; |
|||
} |
|||
} |
|||
|
|||
return tempStr; |
|||
} |
|||
public static String replace(String strSource, String strFrom, String strTo) { |
|||
if(strSource==null){ |
|||
return null; |
|||
} |
|||
int i = 0; |
|||
if ((i = strSource.indexOf(strFrom, i)) >= 0) { |
|||
char[] cSrc = strSource.toCharArray(); |
|||
char[] cTo = strTo.toCharArray(); |
|||
int len = strFrom.length(); |
|||
StringBuffer buf = new StringBuffer(cSrc.length); |
|||
buf.append(cSrc, 0, i).append(cTo); |
|||
i += len; |
|||
int j = i; |
|||
while ((i = strSource.indexOf(strFrom, i)) > 0) { |
|||
buf.append(cSrc, j, i - j).append(cTo); |
|||
i += len; |
|||
j = i; |
|||
} |
|||
buf.append(cSrc, j, cSrc.length - j); |
|||
return buf.toString(); |
|||
} |
|||
return strSource; |
|||
} |
|||
|
|||
|
|||
public static String deal(String str) { |
|||
str = replace(str, "\\", "\\\\"); |
|||
str = replace(str, "'", "\\'"); |
|||
str = replace(str, "\r", "\\r"); |
|||
str = replace(str, "\n", "\\n"); |
|||
str = replace(str, "\"", "\\\""); |
|||
return str; |
|||
} |
|||
|
|||
public static String GetMapToXML(Map<String,String> param){ |
|||
StringBuffer sb = new StringBuffer(); |
|||
sb.append("<xml>"); |
|||
for (Map.Entry<String,String> entry : param.entrySet()) { |
|||
sb.append("<"+ entry.getKey() +">"); |
|||
sb.append(entry.getValue()); |
|||
sb.append("</"+ entry.getKey() +">"); |
|||
} |
|||
sb.append("</xml>"); |
|||
return sb.toString(); |
|||
} |
|||
|
|||
public static void main(String[] args){ |
|||
//String a = StringUtil.supplementZeroGenerateThirteen(1000);
|
|||
double a = 32.; |
|||
System.out.println(StringUtil.isNumeric("32.")); |
|||
System.out.println(a); |
|||
} |
|||
|
|||
/** |
|||
* @Description: 生成唯一图片名称 |
|||
* @Param: fileName |
|||
* @return: 云服务器fileName |
|||
*/ |
|||
public static String getRandomImgName(String fileName) { |
|||
|
|||
int index = fileName.lastIndexOf("."); |
|||
|
|||
if ((fileName == null || fileName.isEmpty()) || index == -1){ |
|||
throw new IllegalArgumentException(); |
|||
} |
|||
// 获取文件后缀
|
|||
String suffix = fileName.substring(index); |
|||
// 生成UUID
|
|||
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); |
|||
// 生成上传至云服务器的路径
|
|||
String path = "code/duck/" + DateUtil.today() + "-" + uuid + suffix; |
|||
return path; |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.bnyer.file.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
/** |
|||
* @Author qyh |
|||
* @Date 2022/7/6 21:16 |
|||
* @Description |
|||
*/ |
|||
@Getter |
|||
@Setter |
|||
@ApiModel("图片检查响应类") |
|||
public class ChekFileVo { |
|||
@ApiModelProperty(value="状态(0->待审核;1->审核通过;2->审核拒绝)") |
|||
private String status; |
|||
@ApiModelProperty(value="文件名称") |
|||
private String fileName; |
|||
} |
|||
@ -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