|
- package com.iformall.sm;
-
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.iformall.common.ErrorCode;
- import com.iformall.douyin.pay.orderQuery.OrderQueryResult;
- import com.iformall.douyin.pay.orderQuery.QueryMerchantResult;
- import com.iformall.douyin.pay.orderQuery.QueryRefundResult;
- import com.iformall.douyin.pay.orderQuery.QuerySettleResult;
- import com.iformall.douyin.pay.preOrder.*;
- import com.iformall.enums.EnumMouldPatchType;
- import com.iformall.enums.EnumPayStatus;
- import com.iformall.enums.EnumVideoType;
- import com.iformall.exception.MallinkException;
- import com.iformall.utils.Base64Util;
- import com.iformall.utils.HttpUtil;
- import com.iformall.utils.sign.SignUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
-
- import java.nio.charset.StandardCharsets;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.*;
-
- @Slf4j
- public class AiVideoHelper {
-
- // public static String uri = "http://222.128.9.132:22266";
- // http://nas.pucao.cn:2001/gen_dh_video
- public static String uri = "http://nas.pucao.cn:2001";
-
- public static String url = "http://nas.pucao.cn:2002";
- public static String photo_speak_suffix = "/img_talking";
- public static String image_quality_suffix = "/image_qualit";
- public static String voice_preview = "/tts_wav";
-
- public static String doPost(String url, String params) {
- return HttpUtil.doAiVideoPost(url,params);
- }
-
-
- public static AiVideoResult createVideo(AiVideoParam videoParam) {
-
- log.info("生成视频start request:" + videoParam.neglectImgString());
- String response = doPost(uri+"/gen_dh_video", JSONObject.toJSONString(videoParam));
- log.info("生成视频end response:"+response);
-
- AiVideoResult result = new AiVideoResult();
-
- if(StringUtils.isBlank(response)){
- result.setSuccess(false);
- result.setMsg("请求生成视频异常,请稍后重试");
- 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("请求生成视频异常,请稍后重试");
- return result;
- }
-
- if(code.intValue() == 1000){
- JSONObject data = jsonObject.getJSONObject("data");
- JSONObject video = data.getJSONObject("video");
- result.setSuccess(true);
- result.setMsg("success");
- result.setDuration(video.getFloatValue("duration"));
- result.setUrl(video.getString("url"));
- }else{
- result.setSuccess(false);
- result.setMsg(status.getString("msg"));
- }
- return result;
-
- // Integer code = jsonObject.getInteger("err_no");
- // if (null != code && code.intValue() == 0 ) {
- // CreatePreOrderResult result = new CreatePreOrderResult();
- // result.setSuccess(true);
- // result.setOutOrderNo(preOrder.getOutOrderNo());
- // JSONObject data = jsonObject.getJSONObject("data");
- // if (null != data ) {
- // result.setOrderId(data.getString("order_id"));
- // result.setToken(data.getString("order_token"));
- // }else {
- // log.error("createPreOrder reponse empity. request: "+JSON.toJSONString(preOrder.toRequestMap())+" response:"+response);
- // result.setSuccess(false);
- // result.setMsg("createPreOrder reponse empity."+response);
- // }
- // return result;
- // }else {
- // log.error("createPreOrder reponse error. request: "+JSON.toJSONString(preOrder.toRequestMap())+" response:"+response);
- // CreatePreOrderResult result = new CreatePreOrderResult();
- // result.setSuccess(false);
- // result.setMsg("createPreOrder reponse error."+response);
- // return result;
- // }
- }
- public static AiPhotoSpeakResult createPhotoSpeakVideo(AiPhotoSpeakParam videoParam) {
- String response = doPost(url + photo_speak_suffix, JSONObject.toJSONString(videoParam));
- log.info("生成视频end response:" + response);
- AiPhotoSpeakResult result = new AiPhotoSpeakResult();
- if (StringUtils.isBlank(response)) {
- result.setSuccess(false);
- result.setMsg("请求生成视频异常,请稍后重试");
- 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("请求生成视频异常,请稍后重试");
- return result;
- }
-
- if (code.intValue() == 4000) {
- JSONObject data = jsonObject.getJSONObject("data");
- String videoUrl = data.getString("url");
- result.setSuccess(true);
- result.setMsg(msg);
- result.setUrl(videoUrl);
- } else {
- result.setSuccess(false);
- result.setMsg(msg);
- }
- return result;
- }
-
- public static AiCheckPhotoResult checkPhoto(AiCheckPhotoParam param) {
- String response = doPost(url + image_quality_suffix, JSONObject.toJSONString(param));
- log.info("图片质量审核 end response:" + response);
- AiCheckPhotoResult result = new AiCheckPhotoResult();
-
- if (StringUtils.isBlank(response)) {
- result.setSuccess(false);
- result.setMsg("图片质量审核失败,请稍后重试");
- 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("请求生成视频异常,请稍后重试");
- return result;
- }
- if (code.intValue() == 2000) {
- result.setCode(code);
- result.setSuccess(true);
- result.setMsg(msg);
- } else {
- result.setCode(code);
- result.setSuccess(false);
- result.setMsg(msg);
- }
- return result;
- }
-
- public static AiPreviewResult voicePreview(AiPreviewParam param) {
- String response = doPost(url + voice_preview, JSONObject.toJSONString(param));
- log.info("TTS音色预览 end response:" + response);
- AiPreviewResult result = new AiPreviewResult();
-
- if (StringUtils.isBlank(response)) {
- result.setSuccess(false);
- result.setMsg("TTS音色预览失败,请稍后重试");
- return result;
- }
- JSONObject jsonObject = JSON.parseObject(response);
- JSONObject status = jsonObject.getJSONObject("status");
- JSONObject data = jsonObject.getJSONObject("data");
- Integer code = status.getInteger("code");
- String msg = status.getString("msg");
- if (code == null) {
- result.setSuccess(false);
- result.setMsg("TTS音色预览异常,请稍后重试");
- return result;
- }
- if (code.intValue() == 3000) {
- result.setCode(200);
- result.setSuccess(true);
- result.setUrl(url + data.getString("url"));
- result.setMsg(msg);
- } else {
- result.setCode(code);
- result.setSuccess(false);
- result.setMsg(msg);
- }
- return result;
- }
-
- public static void main(String[] args) {
- // AiVideoParam videoParam = new AiVideoParam();
- // videoParam.setGen_txt("我写了一篇小说,你帮我看看。");
- // videoParam.setVideo_template_id("16776650495633934_PgNAW8Sm");
- // videoParam.setVoice_id("zh-CN-XiaohanNeural");
- // videoParam.setVoice_style("default");
- // AiVideoParam.VideoFiles videoFiles = new AiVideoParam.VideoFiles();
- // AiVideoParam.BackGround backGround = new AiVideoParam.BackGround();
- // backGround.setType("vertical");
- // backGround.setImage(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/background/grace/1080.jpg"));
- // videoFiles.setBack_ground(backGround);
- // AiVideoParam.Material digitalHuman = new AiVideoParam.Material();
- // int[] digitalHumanCoord = new int[]{0,0};
- // digitalHuman.setCoord(digitalHumanCoord);
- // digitalHuman.setLevel(0);
- // digitalHuman.setRatio(1.0f);
- // videoFiles.setDigital_human(digitalHuman);
- // videoParam.setVideo_files(videoFiles);
- //
- // AiVideoResult video = AiVideoHelper.createVideo(videoParam);
- //
-
- // AiPhotoSpeakParam param = new AiPhotoSpeakParam();
- // param.setGen_txt("人多泰达股份冲冠怒发代发");
- // param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/digitalperson/16760216806604820_cSHoijDX_matting.png"));
- // param.setGender("male");
- // param.setVoice_id("zh-CN-YunxiNeural");
- // param.setVoice_style("sad");
- // param.setUrl("None");
- // AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param);
-
- AiCheckPhotoParam param = new AiCheckPhotoParam();
- String img = Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/personmould/16760216806604820_cSHoijDX_grace_1080.jpg");
- param.setImg(img);
- AiVideoHelper.checkPhoto(param);
-
- }
-
-
- }
|