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

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);
    }
}
相关推荐
张np几秒前
java基础-ArrayList
java·开发语言
Swizard1 分钟前
别让 AI 假装在工作:Android "Vibe Coding" 的生存指南
android·java·vibe coding
Lear5 分钟前
【SpringBoot】 文件下载功能完整实现指南
后端
用户2345267009825 分钟前
Python中如何实现数据库连接池深度好文
后端
BBB努力学习程序设计9 分钟前
Java集合框架:管理数据的"超级工具箱"
java
用户23452670098210 分钟前
Python实现音频文件的分布式处理深度好文
后端
京东零售技术11 分钟前
NeurIPS 2025 | TANDEM:基于双层优化的数据配比学习方法
后端·算法
沸腾_罗强12 分钟前
Envoy方案实现分析报告
后端
Moment18 分钟前
半年时间使用 Tiptap 开发一个和飞书差不多效果的协同文档 😍😍😍
前端·javascript·后端
百度Geek说20 分钟前
基于AI的质量风险管控
后端