首先确定是否已设置回调地址
编写后台代码接收回调传来的不同清晰度的视频地址,下面以 720和1080清晰度为例:
package com.wkk.test.wkk_test.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wkk.test.wkk_test.domain.TencentVideoOnDemandJsonData;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@RestController
@RequestMapping("notify")
public class NotifyController {
Integer height720 = 720;
Integer height1080 = 1080;
@PostMapping(value = "/tencentVideoOnDemand")
public void payNotify(HttpServletRequest request, HttpServletResponse response,@RequestBody String jsonObject) throws Exception{
TencentVideoOnDemandJsonData jsonData = null;
String height720VideoUrl = "";
String height1080VideoUrl = "";
try {
ObjectMapper objectMapper = new ObjectMapper();
jsonData = objectMapper.readValue(jsonObject, TencentVideoOnDemandJsonData.class);
if (jsonData.getEventType().equals("ProcedureStateChanged")){
TencentVideoOnDemandJsonData.ProcedureStateChangeEvent event = jsonData.getProcedureStateChangeEvent();
String fileId = event.getFileId();
TencentVideoOnDemandJsonData.MediaProcessResultSet[] mediaProcessResultSet = event.getMediaProcessResultSet();
for (TencentVideoOnDemandJsonData.MediaProcessResultSet processResultSet : mediaProcessResultSet) {
TencentVideoOnDemandJsonData.TranscodeTask transcodeTask = processResultSet.getTranscodeTask();
TencentVideoOnDemandJsonData.Output output = transcodeTask.getOutput();
int height = output.getHeight();
if (height==height720){
height720VideoUrl = output.getUrl();
}else if (height==height1080){
height1080VideoUrl = output.getUrl();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("腾讯云回调");
System.out.println("height720VideoUrl: "+height720VideoUrl); // 720 清晰度视频地址
System.out.println("height1080VideoUrl: "+height1080VideoUrl); // 1080 清晰度视频地址
}
}
对应的解析json的实体类代码:
package com.wkk.test.wkk_test.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class TencentVideoOnDemandJsonData {
@JsonProperty("EventType")
private String eventType;
@JsonProperty("FileUploadEvent")
private Object fileUploadEvent;
@JsonProperty("ProcedureStateChangeEvent")
private ProcedureStateChangeEvent procedureStateChangeEvent;
@JsonProperty("FileDeleteEvent")
private Object fileDeleteEvent;
@JsonProperty("PullCompleteEvent")
private Object pullCompleteEvent;
@JsonProperty("EditMediaCompleteEvent")
private Object editMediaCompleteEvent;
@JsonProperty("ComposeMediaCompleteEvent")
private Object composeMediaCompleteEvent;
@JsonProperty("WechatPublishCompleteEvent")
private Object wechatPublishCompleteEvent;
@JsonProperty("TranscodeCompleteEvent")
private Object transcodeCompleteEvent;
@JsonProperty("ConcatCompleteEvent")
private Object concatCompleteEvent;
@JsonProperty("ClipCompleteEvent")
private Object clipCompleteEvent;
@JsonProperty("CreateImageSpriteCompleteEvent")
private Object createImageSpriteCompleteEvent;
@JsonProperty("SnapshotByTimeOffsetCompleteEvent")
private Object snapshotByTimeOffsetCompleteEvent;
@JsonProperty("WechatMiniProgramPublishEvent")
private Object wechatMiniProgramPublishEvent;
@JsonProperty("WechatMiniProgramPublishCompleteEvent")
private Object wechatMiniProgramPublishCompleteEvent;
@JsonProperty("RemoveWatermarkCompleteEvent")
private Object removeWatermarkCompleteEvent;
@JsonProperty("RestoreMediaCompleteEvent")
private Object restoreMediaCompleteEvent;
@JsonProperty("ForbidMediaCompleteEvent")
private Object forbidMediaCompleteEvent;
@JsonProperty("SplitMediaCompleteEvent")
private Object splitMediaCompleteEvent;
@JsonProperty("RebuildMediaCompleteEvent")
private Object rebuildMediaCompleteEvent;
@JsonProperty("FastClipMediaCompleteEvent")
private Object fastClipMediaCompleteEvent;
@JsonProperty("BackUpMediaCompleteEvent")
private Object backUpMediaCompleteEvent;
@JsonProperty("ReviewAudioVideoCompleteEvent")
private Object reviewAudioVideoCompleteEvent;
@JsonProperty("DescribeFileAttributesCompleteEvent")
private Object describeFileAttributesCompleteEvent;
@JsonProperty("ExtractTraceWatermarkCompleteEvent")
private Object extractTraceWatermarkCompleteEvent;
@JsonProperty("ExtractCopyRightWatermarkCompleteEvent")
private Object extractCopyRightWatermarkCompleteEvent;
@JsonProperty("QualityInspectCompleteEvent")
private Object qualityInspectCompleteEvent;
@JsonProperty("QualityEnhanceCompleteEvent")
private Object qualityEnhanceCompleteEvent;
@JsonProperty("ReduceMediaBitrateCompleteEvent")
private Object reduceMediaBitrateCompleteEvent;
@Data
public static class ProcedureStateChangeEvent {
@JsonProperty("TaskId")
private String taskId;
@JsonProperty("Status")
private String status;
@JsonProperty("ErrCode")
private int errCode;
@JsonProperty("Message")
private String message;
@JsonProperty("FileId")
private String fileId;
@JsonProperty("FileName")
private String fileName;
@JsonProperty("FileUrl")
private String fileUrl;
@JsonProperty("MetaData")
private MetaData metaData;
@JsonProperty("AiAnalysisResultSet")
private Object[] aiAnalysisResultSet;
@JsonProperty("AiRecognitionResultSet")
private Object[] aiRecognitionResultSet;
@JsonProperty("AiContentReviewResultSet")
private Object[] aiContentReviewResultSet;
@JsonProperty("MediaProcessResultSet")
private MediaProcessResultSet[] mediaProcessResultSet;
@JsonProperty("SessionContext")
private String sessionContext;
@JsonProperty("SessionId")
private String sessionId;
@JsonProperty("TasksPriority")
private int tasksPriority;
@JsonProperty("TasksNotifyMode")
private String tasksNotifyMode;
@JsonProperty("Operator")
private String operator;
@JsonProperty("OperationType")
private String operationType;
}
@Data
public static class MetaData {
@JsonProperty("AudioDuration")
private double audioDuration;
@JsonProperty("AudioStreamSet")
private AudioStream[] audioStreamSet;
@JsonProperty("Bitrate")
private int bitrate;
@JsonProperty("Container")
private String container;
@JsonProperty("Duration")
private double duration;
@JsonProperty("Height")
private int height;
@JsonProperty("Md5")
private String md5;
@JsonProperty("Rotate")
private int rotate;
@JsonProperty("Size")
private long size;
@JsonProperty("VideoDuration")
private double videoDuration;
@JsonProperty("VideoStreamSet")
private VideoStream[] videoStreamSet;
@JsonProperty("Width")
private int width;
}
@Data
public static class MediaProcessResultSet {
@JsonProperty("Type")
private String type;
@JsonProperty("TranscodeTask")
private TranscodeTask transcodeTask;
@JsonProperty("AnimatedGraphicTask")
private Object animatedGraphicTask;
@JsonProperty("SnapshotByTimeOffsetTask")
private Object snapshotByTimeOffsetTask;
@JsonProperty("SampleSnapshotTask")
private Object sampleSnapshotTask;
@JsonProperty("ImageSpriteTask")
private Object imageSpriteTask;
@JsonProperty("CoverBySnapshotTask")
private Object coverBySnapshotTask;
@JsonProperty("AdaptiveDynamicStreamingTask")
private Object adaptiveDynamicStreamingTask;
}
@Data
public static class AudioStream {
@JsonProperty("Bitrate")
private int bitrate;
@JsonProperty("Codec")
private String codec;
@JsonProperty("Codecs")
private String codecs;
@JsonProperty("Loudness")
private int loudness;
@JsonProperty("SamplingRate")
private int samplingRate;
}
@Data
public static class VideoStream {
@JsonProperty("Bitrate")
private int bitrate;
@JsonProperty("Codec")
private String codec;
@JsonProperty("CodecTag")
private String codecTag;
@JsonProperty("Codecs")
private String codecs;
@JsonProperty("DynamicRangeInfo")
private DynamicRangeInfo dynamicRangeInfo;
@JsonProperty("Fps")
private int fps;
@JsonProperty("Height")
private int height;
@JsonProperty("Width")
private int width;
}
@Data
public static class DynamicRangeInfo {
@JsonProperty("HDRType")
private String hdrType;
@JsonProperty("Type")
private String type;
}
@Data
public static class TranscodeTask {
@JsonProperty("Status")
private String status;
@JsonProperty("ErrCode")
private int errCode;
@JsonProperty("ErrCodeExt")
private String errCodeExt;
@JsonProperty("Message")
private String message;
@JsonProperty("Progress")
private int progress;
@JsonProperty("BeginProcessTime")
private String beginProcessTime;
@JsonProperty("FinishTime")
private String finishTime;
@JsonProperty("Input")
private Input input;
@JsonProperty("Output")
private Output output;
}
@Data
public static class Input {
@JsonProperty("Definition")
private int definition;
@JsonProperty("TraceWatermark")
private TraceWatermark traceWatermark;
@JsonProperty("CopyRightWatermark")
private CopyRightWatermark copyRightWatermark;
@JsonProperty("WatermarkSet")
private Object[] watermarkSet;
@JsonProperty("HeadTailSet")
private Object[] headTailSet;
@JsonProperty("MosaicSet")
private Object[] mosaicSet;
@JsonProperty("StartTimeOffset")
private int startTimeOffset;
@JsonProperty("EndTimeOffset")
private int endTimeOffset;
}
@Data
public static class Output {
@JsonProperty("Url")
private String url;
@JsonProperty("Size")
private int size;
@JsonProperty("Container")
private String container;
@JsonProperty("Height")
private int height;
@JsonProperty("Width")
private int width;
@JsonProperty("Bitrate")
private int bitrate;
@JsonProperty("Md5")
private String md5;
@JsonProperty("Duration")
private double duration;
@JsonProperty("VideoStreamSet")
private VideoStream[] videoStreamSet;
@JsonProperty("AudioStreamSet")
private AudioStream[] audioStreamSet;
@JsonProperty("Definition")
private int definition;
@JsonProperty("DigitalWatermarkType")
private String digitalWatermarkType;
@JsonProperty("CopyRightWatermarkText")
private String copyRightWatermarkText;
@JsonProperty("VMAF")
private int vmaf;
}
@Data
public static class TraceWatermark {
@JsonProperty("Definition")
private int definition;
@JsonProperty("DefinitionForBStream")
private int definitionForBStream;
@JsonProperty("Switch")
private String switchStr;
}
@Data
public static class CopyRightWatermark {
@JsonProperty("Text")
private String text;
@JsonProperty("StartTimeOffset")
private int startTimeOffset;
@JsonProperty("EndTimeOffset")
private int endTimeOffset;
}
}