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

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);
    }
}
相关推荐
qq_172805594 分钟前
Go 自建库的使用教程与测试
开发语言·后端·golang
irving同学462388 分钟前
TypeORM 列装饰器完整总结
前端·后端·nestjs
一直_在路上8 分钟前
Go语言并发编程架构师指南:从基础到企业级实战
后端·架构
Reboot11 分钟前
Mongodb数据类型
后端
似水流年流不尽思念12 分钟前
Nacos Config 动态刷新的长轮询机制是如何实现的?
后端
一朵筋斗云16 分钟前
关于poll和epoll
后端
黑白世界464817 分钟前
开源分享: php-tools php gui的一次尝试
后端·php
金牌服务刘18 分钟前
主数据平台下游系统过多如何下发数据?
后端·微服务·连续集成
remaindertime26 分钟前
(八)Spring Cloud Alibaba 2023.x:网关统一鉴权与登录实现
后端·微服务
IT_陈寒26 分钟前
Java性能优化:10个让你的Spring Boot应用提速300%的隐藏技巧
前端·人工智能·后端