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

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);
    }
}
相关推荐
Java_2017_csdn15 分钟前
在 Java 中,MessageFormat.format() 和 String.format() 函数对比?
java·开发语言·前端·数据库
卷无止境25 分钟前
C# 与 .NET 中的委托:把方法装进变量里
后端
绛洞花主敏明26 分钟前
Go操作xorm中间表多对多关联实战
开发语言·后端·golang
长栎26 分钟前
手写一个表达式计算器,你就理解解释器模式了
后端
噢,我明白了26 分钟前
MyBatis-Plus 中IPage的分页查询
java·mybatis
长栎27 分钟前
foreach 语法糖背后,迭代器模式做了多少脏活
后端
剑挑星河月30 分钟前
98.验证二叉搜索树
java·算法·leetcode
HLAIA光子34 分钟前
LLM缓存机制:你的API账单可以砍掉75%
后端·llm·ai编程
卷无止境35 分钟前
统计质量控制(SQC / SPC):用数据说话的质量哲学
后端
XovH37 分钟前
第 44篇 k8s之实战:将 Web 应用迁移到 Kubernetes(上)
后端