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

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);
    }
}
相关推荐
AresXue3 分钟前
2025最新Java性能优化建议 应用 数据库 机器 网络
java
跟着珅聪学java13 分钟前
spring boot 整合 activiti 教程
android·java·spring
Java水解35 分钟前
Spring JDBC与KingbaseES深度集成:构建高性能国产数据库应用实战
后端·spring
Giant10038 分钟前
小白也能懂的 Token 认证:从原理到实战,用 Express 手把手教你做
后端
学习的周周啊44 分钟前
一人AI自动化开发体系(Cursor 驱动):从需求到上线的全流程闭环与实战清单
运维·人工智能·自动化·ai编程·全栈·devops·cursor
间彧1 小时前
Spring IoC容器解决循环依赖的三级缓存机制详解
后端
间彧1 小时前
Spring IoC详解与应用实战
后端
junnhwan1 小时前
【苍穹外卖笔记】Day04--套餐管理模块
java·数据库·spring boot·后端·苍穹外卖·crud
间彧1 小时前
Java NPE异常详解
后端
无责任此方_修行中1 小时前
我的两次 Vibe Coding 经历,一次天堂,一次地狱
后端·node.js·vibecoding