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

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);
    }
}
相关推荐
刘晓飞4 分钟前
import type 和 import 区别
后端
吴声子夜歌6 分钟前
小程序——界面API(一)
java·javascript·小程序
予枫的编程笔记9 分钟前
【面试专栏|Java并发编程】从Runnable到Callable,Java4种线程创建方式
java·多线程·thread·java面试·runnable·callable·java线程
野犬寒鸦12 分钟前
SAP后端实习开发面试:操作系统与网络核心考点及Linux与Redis
java·服务器·网络·后端·面试
ServBay14 分钟前
代码减半,10分钟彻底告别 Java 开发旧习
java·后端
Soofjan16 分钟前
Go Map SwissTable Rehash 扩容与再哈希(源码笔记 6)
后端
future021017 分钟前
Spring 核心原理学习路线(完结汇总):7 篇文章串起 IOC、AOP、事务与 Boot
后端·学习·spring
阿杆22 分钟前
五分钟配好向日葵 MCP,让 AI 替你远程安装 OpenClaw!
后端·aigc·mcp
MegaDataFlowers25 分钟前
CRUD操作及配置解析
java·mybatis
毕设源码-邱学长30 分钟前
【开题答辩全过程】以 胡小楼行政村农用灌溉机井预约管理系统的设计与实现为例,包含答辩的问题和答案
java·eclipse