From cfad5d89c4ae4fe6dce50e9c80dad312e27cc6e0 Mon Sep 17 00:00:00 2001 From: lrh <1585126058@qq.com> Date: Fri, 7 Jul 2023 13:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E5=88=86=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PhotoSpeakVideoController.java | 4 +- .../iformall/utils/BaiduImageCheckUtil.java | 55 ++++++++++++------- .../mapper/PhotoSpeakVideoMapper.java | 2 +- .../service/sm/PhotoSpeakVideoService.java | 2 +- .../sm/impl/PhotoSpeakVideoServiceImpl.java | 8 +-- .../java/com/iformall/sm/AiVideoHelper.java | 8 +-- .../mapper/PhotoSpeakVideoMapper.xml | 7 +-- 7 files changed, 46 insertions(+), 40 deletions(-) diff --git a/suimangCApi/src/main/java/com/iformall/controller/PhotoSpeakVideoController.java b/suimangCApi/src/main/java/com/iformall/controller/PhotoSpeakVideoController.java index 0e335ea..3991ec1 100644 --- a/suimangCApi/src/main/java/com/iformall/controller/PhotoSpeakVideoController.java +++ b/suimangCApi/src/main/java/com/iformall/controller/PhotoSpeakVideoController.java @@ -468,7 +468,7 @@ public class PhotoSpeakVideoController extends BaseController { @ApiOperation("获取视频是否生成成功") @GetMapping("/checkVideoStatus") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) - public ResultData checkVideoStatus(@RequestParam("list") List list,@RequestParam("type") Integer type) { - return photoSpeakVideoService.checkVideoStatus(getMemberId(),list,type); + public ResultData checkVideoStatus(@RequestParam("list") List list) { + return photoSpeakVideoService.checkVideoStatus(getMemberId(),list); } } diff --git a/suimangCApi/src/main/java/com/iformall/utils/BaiduImageCheckUtil.java b/suimangCApi/src/main/java/com/iformall/utils/BaiduImageCheckUtil.java index 2b4842f..392d676 100644 --- a/suimangCApi/src/main/java/com/iformall/utils/BaiduImageCheckUtil.java +++ b/suimangCApi/src/main/java/com/iformall/utils/BaiduImageCheckUtil.java @@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; -import com.iformall.sm.AiBaiduCheckResult; -import okhttp3.*; import org.springframework.web.multipart.MultipartFile; import java.io.*; @@ -14,6 +12,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; +import java.util.Date; +import java.util.HashMap; /** * 图片质量检查方法 @@ -29,9 +29,7 @@ public class BaiduImageCheckUtil { // 百度Secret Key private final static String secretKey = "RY5YCqGejrc32xT5kIxDj0mqP9QRiKfD"; //写死的 access_token - private final static String access_token = "24.c1c7992795301773c60c8cf01abfe759.2592000.1689236723.282335-33618414"; - - public static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build(); + private final static String access_token = "24.ba201483ba860779dcb402cc044a3bd4.2592000.1691298224.282335-35825024"; //7.7 public static ResultData photoCheck(MultipartFile file) { try { @@ -41,9 +39,10 @@ public class BaiduImageCheckUtil { String param = "image=" + imageUrl; // 注意这里access_token有过期时间, 客户端可自行缓存,过期后重新获取。 // Access Token的有效期(秒为单位,有效期30天) -// String accessToken = getAuth(); + String accessToken = getAuth(); + //这里暂时写死 - String result = BaiDuHttpUtil.post(photo_check_url, access_token, param); + String result = BaiDuHttpUtil.post(photo_check_url, accessToken, param); System.out.println(result); JSONObject jsonObject = JSON.parseObject(result); //1:合规,2:不合规,3:疑似,4:审核失败 @@ -99,21 +98,37 @@ public class BaiduImageCheckUtil { * 获取API访问权限token,该token有一定的有效期,需要自行管理,当失效时需重新获取。 * Access Token的有效期(秒为单位,有效期30天) */ - public static String getAuth() throws IOException { - MediaType mediaType = MediaType.parse("application/json"); - RequestBody body = RequestBody.create(mediaType, ""); - Request request = new Request.Builder() - .url(auth_url + "client_id=" + apiKey + "&client_secret= " + secretKey + "&grant_type=client_credentials") - .method("POST", body) - .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - Response response = HTTP_CLIENT.newCall(request).execute(); - System.out.println(response.body().string()); - return response.body().string(); + public static String getAuth() { + HashMap map = new HashMap<>(); + map.put("client_id", apiKey); + map.put("client_secret", secretKey); + map.put("grant_type", "client_credentials"); + String doPost = HttpUtil.doPost(auth_url, map); + JSONObject json = JSONObject.parseObject(doPost); + String access_token = (String) json.get("access_token"); + Integer expires_in = (Integer) json.get("expires_in"); + String checkExpires = checkExpires(expires_in); + if (checkExpires == null){ + return access_token; + } + return doPost; + } + + private static String checkExpires(Integer expiresIn) { + int days = expiresIn / 60 / 60 / 24; + Date timeAfterDays = DateUtils.getTimeAfterDays(days, new Date()); + if (timeAfterDays.before(new Date())){ + String doPost = getAuth(); + JSONObject json = JSONObject.parseObject(doPost); + String access_token = (String) json.get("access_token"); + Integer expires_in = (Integer) json.get("expires_in"); + return access_token; + } + return null; } - public static void main(String[] args) throws IOException { + + public static void main(String[] args) { System.out.println(getAuth()); } } \ No newline at end of file diff --git a/suimangService/src/main/java/com/iformall/mapper/PhotoSpeakVideoMapper.java b/suimangService/src/main/java/com/iformall/mapper/PhotoSpeakVideoMapper.java index ccae9a7..f48066e 100644 --- a/suimangService/src/main/java/com/iformall/mapper/PhotoSpeakVideoMapper.java +++ b/suimangService/src/main/java/com/iformall/mapper/PhotoSpeakVideoMapper.java @@ -23,5 +23,5 @@ public interface PhotoSpeakVideoMapper extends CommonMapper getSortList(PhotoSpeakVideo record); - Integer checkVideoStatus(@Param("userId") Long userId, @Param("list") List list,@Param("type") Integer type); + Integer checkVideoStatus(@Param("userId") Long userId, @Param("list") List list); } diff --git a/suimangService/src/main/java/com/iformall/service/sm/PhotoSpeakVideoService.java b/suimangService/src/main/java/com/iformall/service/sm/PhotoSpeakVideoService.java index 742b04a..53913b2 100644 --- a/suimangService/src/main/java/com/iformall/service/sm/PhotoSpeakVideoService.java +++ b/suimangService/src/main/java/com/iformall/service/sm/PhotoSpeakVideoService.java @@ -65,5 +65,5 @@ public interface PhotoSpeakVideoService { List getNotHyUploadList(); - ResultData checkVideoStatus(Long userId, List time, Integer type); + ResultData checkVideoStatus(Long userId, List time); } diff --git a/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java b/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java index a489607..1947c0e 100644 --- a/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java @@ -458,15 +458,11 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { } @Override - public ResultData checkVideoStatus(Long userId, List list, Integer type) { + public ResultData checkVideoStatus(Long userId, List list) { if (CollectionUtils.isEmpty(list)){ return new ResultData(ErrorCode.VIDEO_CREATING.getCode(),""); } - - if (type == null){ - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"类型不能为空"); - } - Integer integer = photoSpeakVideoMapper.checkVideoStatus(userId,list,type); + Integer integer = photoSpeakVideoMapper.checkVideoStatus(userId,list); if (integer > 0){ return new ResultData("生成视频成功"); } diff --git a/suimangService/src/main/java/com/iformall/sm/AiVideoHelper.java b/suimangService/src/main/java/com/iformall/sm/AiVideoHelper.java index d9e25b9..9f452ab 100644 --- a/suimangService/src/main/java/com/iformall/sm/AiVideoHelper.java +++ b/suimangService/src/main/java/com/iformall/sm/AiVideoHelper.java @@ -247,11 +247,11 @@ public class AiVideoHelper { } public static AiVideoHqResult videoHq(AiVideoHqParam param) { -// String response = doPost(hy_url + video_hq, JSONObject.toJSONString(param)); - String response = doPost("http://111.198.0.15:22288" + video_hq, JSONObject.toJSONString(param)); + String response = doPost(hy_url + video_hq, JSONObject.toJSONString(param)); +// String response = doPost("http://111.198.0.15:22288" + video_hq, JSONObject.toJSONString(param)); log.info("视频超分 end response:" + response); -// log.info("视频超分 IP:" + hy_url + video_hq); - log.info("视频超分 IP:" + "http://111.198.0.15:22288" + video_hq); + log.info("视频超分 IP:" + hy_url + video_hq); +// log.info("视频超分 IP:" + "http://111.198.0.15:22288" + video_hq); AiVideoHqResult result = new AiVideoHqResult(); if (StringUtils.isBlank(response)) { diff --git a/suimangService/src/main/resources/mapper/PhotoSpeakVideoMapper.xml b/suimangService/src/main/resources/mapper/PhotoSpeakVideoMapper.xml index a553528..3161d49 100644 --- a/suimangService/src/main/resources/mapper/PhotoSpeakVideoMapper.xml +++ b/suimangService/src/main/resources/mapper/PhotoSpeakVideoMapper.xml @@ -160,12 +160,7 @@ select count(1) from photo_speak_video where user_id = #{userId} - - and video_status = 5 - - - and video_hy_status = 5 - + and (video_status = 5 or video_status = 11) and id in