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

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);
    }
}
相关推荐
IT研究室29 分钟前
最新计算机毕业设计选题推荐-基于spring boot的家庭医生管理系统-网站-文档指导-Java-springboot
java·spring boot·课程设计
DataMover智迁1 小时前
免费数据库同步工具怎么选?DataMover 的定时全量、增量与 CDC
java·数据库·oracle
Rain的Java大神之路1 小时前
钱扣了,消息却没了:RocketMQ 5.x 事务回查状态到底该放哪?
java·后端·rocketmq
濮水大叔1 小时前
无需额外做本体建模,用 MCP 打通 WorkBuddy 与业务系统
node.js·全栈·mcp
二宝哥1 小时前
08.Spring AI 结合 Ollama:本地大模型应用开发实战
java·人工智能·spring
bossqugadw1 小时前
13 | Java | 集合框架(重点)List /Set / Map
java·单例模式·facebook·新浪微博·segmentfault
七夜zippoe2 小时前
国产库性能调优:索引/执行计划实战(四步处理顺序与四类慢的归因)
java·ai·信创
Rain的Java大神之路2 小时前
LeetCode 46 全排列:从「及格答案」到让面试官眼前一亮的三种写法
后端·leetcode·面试