获取阿里云视频播放凭证接口

1、 在service_vod模块创建接口

在service_vod的com/ atguigu/vodservice/controller/VideoController里添加根据视频id获取视频播放凭证。

java 复制代码
package com.atguigu.vodservice.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.atguigu.commonutils.R;
import com.atguigu.vodservice.utils.AliyunVodSDKUtils;
import com.atguigu.vodservice.utils.ConstantPropertiesUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

@Api(description="阿里云视频点播微服务")
@CrossOrigin //跨域
@RestController
@RequestMapping("/eduvod/video")
public class VideoController {

    @GetMapping("getplayauth/{videoId}")
    public R getVideoPlayAuth(@PathVariable("videoId") String videoId) throws Exception {

        //获取阿里云存储相关常量
        String accessKeyId = ConstantPropertiesUtil.ACCESS_KEY_ID;
        String accessKeySecret = ConstantPropertiesUtil.ACCESS_KEY_SECRET;

        //初始化
        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);

        //请求
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId(videoId);

        //响应
        GetVideoPlayAuthResponse response = client.getAcsResponse(request);

        //得到播放凭证
        String playAuth = response.getPlayAuth();

        //返回结果
        return R.ok().message("获取凭证成功").data("playAuth", playAuth);
    }
}
相关推荐
QC班长1 天前
Maven公司私库配置踩坑点
java·服务器·maven·intellij-idea
Makoto_Kimur1 天前
java开发面试-AI Coding速成
java·开发语言
wuqingshun3141591 天前
说说mybatis的缓存机制
java·缓存·mybatis
空中海1 天前
Kubernetes 生产实践、可观测性与扩展入门
java·贪心算法·kubernetes
Devin~Y1 天前
大厂Java面试实录:Spring Boot/Cloud、Kafka、Redis、K8s 与 Spring AI(RAG/Agent)三轮连环问
java·spring boot·redis·mysql·spring cloud·kafka·kubernetes
bLEd RING1 天前
SpringBoot3.3.0集成Knife4j4.5.0实战
java
小松加哲1 天前
Spring MVC 核心原理全解析
java·spring·mvc
GetcharZp1 天前
比 Zap 还要快?Go 社区高性能日志神器 Zerolog 落地实践指南
后端
Ulyanov1 天前
《PySide6 GUI开发指南:QML核心与实践》 第二篇:QML语法精要——构建声明式UI的基础
java·开发语言·javascript·python·ui·gui·雷达电子对抗系统仿真
码界筑梦坊1 天前
357-基于Java的大型商场应急预案管理系统
java·开发语言·毕业设计·知识分享