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

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);
    }
}
相关推荐
superman超哥1 分钟前
Rust 编译优化选项配置:释放性能潜力的精细调控
开发语言·后端·rust·rust编译优化·精细调控·编译优化选项
yyy(十一月限定版)1 分钟前
C++基础
java·开发语言·c++
Coder_Boy_2 分钟前
分布式系统设计经验总结:金融vs电商的核心差异与决策思路
java·运维·微服务·金融·电商
UrbanJazzerati5 分钟前
深度解析Salesforce Apex的Governance Limit:SOQL 50,000条记录的事务级限制
后端·面试
To Be Clean Coder12 分钟前
【Spring源码】getBean源码实战(一)
java·后端·spring
巴塞罗那的风12 分钟前
golang协程泄漏排查实战
开发语言·后端·golang
派大鑫wink16 分钟前
【Day21】NIO入门:通道、缓冲区与非阻塞IO基础
java·开发语言
ziyue757516 分钟前
idea将配置移动到自定义位置
java·intellij-idea·idea·软件
quant_198617 分钟前
BTC 行情预警系统实战教程
开发语言·后端·python·websocket·程序人生·金融
南汐以墨19 分钟前
UI自动化测试指南(一):浅解概念
java·测试工具