瀏覽代碼

超分接口修改

private_deployment
lrh 1 年之前
父節點
當前提交
cfad5d89c4
共有 7 個檔案被更改,包括 46 行新增40 行删除
  1. +2
    -2
      suimangCApi/src/main/java/com/iformall/controller/PhotoSpeakVideoController.java
  2. +35
    -20
      suimangCApi/src/main/java/com/iformall/utils/BaiduImageCheckUtil.java
  3. +1
    -1
      suimangService/src/main/java/com/iformall/mapper/PhotoSpeakVideoMapper.java
  4. +1
    -1
      suimangService/src/main/java/com/iformall/service/sm/PhotoSpeakVideoService.java
  5. +2
    -6
      suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java
  6. +4
    -4
      suimangService/src/main/java/com/iformall/sm/AiVideoHelper.java
  7. +1
    -6
      suimangService/src/main/resources/mapper/PhotoSpeakVideoMapper.xml

+ 2
- 2
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<Long> list,@RequestParam("type") Integer type) {
return photoSpeakVideoService.checkVideoStatus(getMemberId(),list,type);
public ResultData checkVideoStatus(@RequestParam("list") List<Long> list) {
return photoSpeakVideoService.checkVideoStatus(getMemberId(),list);
}
}

+ 35
- 20
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<String, String> 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());
}
}

+ 1
- 1
suimangService/src/main/java/com/iformall/mapper/PhotoSpeakVideoMapper.java 查看文件

@@ -23,5 +23,5 @@ public interface PhotoSpeakVideoMapper extends CommonMapper<PhotoSpeakVideo, Lon

List<PhotoSpeakVideo> getSortList(PhotoSpeakVideo record);

Integer checkVideoStatus(@Param("userId") Long userId, @Param("list") List<Long> list,@Param("type") Integer type);
Integer checkVideoStatus(@Param("userId") Long userId, @Param("list") List<Long> list);
}

+ 1
- 1
suimangService/src/main/java/com/iformall/service/sm/PhotoSpeakVideoService.java 查看文件

@@ -65,5 +65,5 @@ public interface PhotoSpeakVideoService {

List<PhotoSpeakVideo> getNotHyUploadList();

ResultData checkVideoStatus(Long userId, List<Long> time, Integer type);
ResultData checkVideoStatus(Long userId, List<Long> time);
}

+ 2
- 6
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<Long> list, Integer type) {
public ResultData checkVideoStatus(Long userId, List<Long> 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("生成视频成功");
}


+ 4
- 4
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)) {


+ 1
- 6
suimangService/src/main/resources/mapper/PhotoSpeakVideoMapper.xml 查看文件

@@ -160,12 +160,7 @@
select count(1)
from photo_speak_video
where user_id = #{userId}
<if test="type == 1">
and video_status = 5
</if>
<if test="type == 2">
and video_hy_status = 5
</if>
and (video_status = 5 or video_status = 11)
<if test="list != null and list.size > 0">
and id in
<foreach collection="list" index="index" item="id" open="(" separator="," close=")">


Loading…
取消
儲存