@@ -0,0 +1,50 @@ | |||
package com.iformall.controller; | |||
import com.github.pagehelper.PageInfo; | |||
import com.iformall.annotation.AuthIgnore; | |||
import com.iformall.common.ErrorCode; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.domain.po.base.BaseEntity; | |||
import com.iformall.domain.po.sm.PersonPhoto; | |||
import com.iformall.enums.EnumMouldSendType; | |||
import com.iformall.enums.EnumaMouldPatchStatus; | |||
import com.iformall.service.sm.MouldPatchSignService; | |||
import com.iformall.service.sm.PersonPhotoService; | |||
import com.iformall.utils.BaiduImageCheckUtil; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.util.ObjectUtils; | |||
import org.springframework.web.bind.annotation.*; | |||
import org.springframework.web.multipart.MultipartFile; | |||
@RestController | |||
@RequestMapping("/api/baidu") | |||
@Api(description = "模板接口") | |||
public class BaiduController extends BaseController { | |||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
@ApiOperation("百度图片审核接口") | |||
@PostMapping(value = "baiduPhoto", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||
@ApiImplicitParam(name = "file", value = "file", dataType = "MultipartFile", paramType = "query", required = true) | |||
public ResultData baiduCheckPhoto(@RequestPart("file") MultipartFile file) { | |||
logger.debug("[" + getIpAddr() + "] PersonPhotoController::baiduCheckPhoto"); | |||
if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "素材为空"); | |||
} | |||
long size = file.getSize(); | |||
final long length = 4 * 1024 * 1024; | |||
if (size > length) { | |||
return new ResultData(ErrorCode.PICTURE_FOUR_SIZE_EXCEED); | |||
} | |||
return BaiduImageCheckUtil.photoCheck(file); | |||
} | |||
} |
@@ -12,6 +12,10 @@ import com.iformall.domain.po.sm.UserMouldVideo; | |||
import com.iformall.enums.EnumVideoStatus; | |||
import com.iformall.service.ProductService; | |||
import com.iformall.service.UserBasicImageService; | |||
import com.iformall.sm.AiCheckPhotoParam; | |||
import com.iformall.sm.AiCheckPhotoResult; | |||
import com.iformall.sm.AiVideoHelper; | |||
import com.iformall.utils.Base64Util; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
@@ -20,7 +24,11 @@ import org.apache.commons.lang3.StringUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.util.ObjectUtils; | |||
import org.springframework.web.bind.annotation.*; | |||
import org.springframework.web.multipart.MultipartFile; | |||
import java.io.IOException; | |||
@RestController | |||
@@ -50,5 +58,29 @@ public class UserBasicImageController extends BaseController { | |||
return new ResultData(); | |||
} | |||
@ApiOperation("图片人脸检测") | |||
@PostMapping(value = "checkPhoto", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||
@ApiImplicitParam(name = "file", value = "file", dataType = "MultipartFile", paramType = "query", required = true) | |||
public ResultData checkPhoto(@RequestPart("file") MultipartFile file) { | |||
logger.debug("[" + getIpAddr() + "] PersonPhotoController::checkPhoto"); | |||
if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "素材为空"); | |||
} | |||
try { | |||
byte[] fileBytes = file.getBytes(); | |||
String imgStr = Base64Util.encode(fileBytes); | |||
AiCheckPhotoParam param = new AiCheckPhotoParam(); | |||
param.setImg(imgStr); | |||
AiCheckPhotoResult result = AiVideoHelper.checkPhoto(param); | |||
if (result.isSuccess()) { | |||
return new ResultData(); | |||
} | |||
return new ResultData(result.getCode(), result.getMsg()); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(), "接口请求异常"); | |||
} | |||
} | |||
} |
@@ -12,7 +12,7 @@ public class UrlCheck { | |||
|| url.contains("getCarStopFee") | |||
|| url.contains("/video/upload") | |||
|| url.contains("/personPhoto/baiduPhoto") | |||
|| url.contains("/personPhoto/checkPhoto"); | |||
|| url.contains("checkPhoto"); | |||
} | |||
} |
@@ -253,7 +253,7 @@ public class UserDigitalAvatarOrderServiceImpl implements UserDigitalAvatarOrder | |||
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"上传图片参数异常"); | |||
} | |||
DigitalAvatarResult result = AiDigitalAvatarHelper.digitalAvatarPhoto(param); | |||
DigitalAvatarResult result = AiDigitalAvatarHelper.digitalAvatarPhoto(param,record.getId()); | |||
if(result.isSuccess()){ | |||
UserDigitalAvatarOrderServiceImpl proxy = (UserDigitalAvatarOrderServiceImpl) AopContext.currentProxy(); | |||
proxy.handlePhoto(record,result.getImgList()); | |||
@@ -21,9 +21,48 @@ public class AiDigitalAvatarHelper { | |||
this.digital_avatar = digital_avatar; | |||
} | |||
private static String callbackUrl; | |||
@Value("${photo.callbackUrl}") | |||
public void setCallbackUrl(String callbackUrl){ | |||
this.callbackUrl = callbackUrl; | |||
} | |||
public static DigitalAvatarResult digitalAvatarPhoto(DigitalAvatarParam param) { | |||
public static AiCheckPhotoResult checkPhoto(AiCheckPhotoParam param) { | |||
String response = HttpUtil.doAiVideoPost(digital_avatar + "/dec_face", JSONObject.toJSONString(param)); | |||
log.info("图片人脸检测 end response:" + response); | |||
AiCheckPhotoResult result = new AiCheckPhotoResult(); | |||
if (StringUtils.isBlank(response)) { | |||
result.setSuccess(false); | |||
result.setMsg("(MetaService)图片人脸检测失败,请稍后重试"); | |||
return result; | |||
} | |||
JSONObject jsonObject = JSON.parseObject(response); | |||
JSONObject status = jsonObject.getJSONObject("status"); | |||
Integer code = status.getInteger("code"); | |||
String msg = status.getString("msg"); | |||
if (code == null) { | |||
result.setSuccess(false); | |||
result.setMsg("(MetaService)图片人脸检测失败,请稍后重试"); | |||
return result; | |||
} | |||
if (code.intValue() == 1000) { | |||
result.setCode(code); | |||
result.setSuccess(true); | |||
result.setMsg(msg); | |||
} else { | |||
result.setCode(code); | |||
result.setSuccess(false); | |||
result.setMsg(msg); | |||
} | |||
return result; | |||
} | |||
public static DigitalAvatarResult digitalAvatarPhoto(DigitalAvatarParam param,Long taskId) { | |||
param.setTask_id(taskId); | |||
param.setCallback_url(callbackUrl + "/callback/photo/speak"); | |||
// log.info("生成照片start request:" + param.getBg_img()); | |||
String response = HttpUtil.doAiVideoPost(digital_avatar + "/make_face", JSONObject.toJSONString(param)); | |||
log.info("生成照片end response:"+response); | |||
@@ -45,7 +84,7 @@ public class AiDigitalAvatarHelper { | |||
return result; | |||
} | |||
if(code.intValue() == 1000){ | |||
if(code.intValue() == 2000){ | |||
result.setSuccess(true); | |||
result.setMsg("success"); | |||
JSONObject data = jsonObject.getJSONObject("data"); | |||
@@ -86,7 +125,43 @@ public class AiDigitalAvatarHelper { | |||
return result; | |||
} | |||
if(code.intValue() == 1000){ | |||
if(code.intValue() == 3000){ | |||
result.setSuccess(true); | |||
result.setMsg("success"); | |||
JSONObject data = jsonObject.getJSONObject("data"); | |||
result.setImg(data.getString("img")); | |||
}else{ | |||
result.setSuccess(false); | |||
result.setMsg("[metavatar]"+status.getString("msg")); | |||
} | |||
return result; | |||
} | |||
public static ShareImgResult createShareImg(ShareImgParam param) { | |||
// log.info("生成照片start request:" + param.getBg_img()); | |||
String response = HttpUtil.doAiVideoPost(digital_avatar + "/logo_img", JSONObject.toJSONString(param)); | |||
log.info("照片超分end response:"+response); | |||
ShareImgResult result = new ShareImgResult(); | |||
if(StringUtils.isBlank(response)){ | |||
result.setSuccess(false); | |||
result.setMsg("[metavatar]请求异常,请稍后重试"); | |||
return result; | |||
} | |||
JSONObject jsonObject = JSON.parseObject(response); | |||
JSONObject status = jsonObject.getJSONObject("status"); | |||
Integer code = status.getInteger("code"); | |||
if(code == null){ | |||
result.setSuccess(false); | |||
result.setMsg("[metavatar]请求异常,请稍后重试"); | |||
return result; | |||
} | |||
if(code.intValue() == 4000){ | |||
result.setSuccess(true); | |||
result.setMsg("success"); | |||
JSONObject data = jsonObject.getJSONObject("data"); | |||
@@ -15,4 +15,8 @@ public class DigitalAvatarParam { | |||
private String img_middle; | |||
private String img_right; | |||
private Long task_id; | |||
private String callback_url; | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.iformall.sm; | |||
import lombok.Data; | |||
@Data | |||
public class ShareImgParam { | |||
private String img; | |||
private String watermark_img; | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.iformall.sm; | |||
import lombok.Data; | |||
@Data | |||
public class ShareImgResult { | |||
private boolean success; | |||
private String msg; | |||
private String img; | |||
} |