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

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);
    }
}
相关推荐
Jiude7 分钟前
AI 全栈时代的工程化护栏:Vben-Nest 让 Mock 契约落地成真实后端
前端·后端·nestjs
菜鸡儿齐18 分钟前
leetcode-最小栈
java·算法·leetcode
每天进步一点_JL25 分钟前
分布式系统中如何保证幂等,数据一致性 - 案例
后端
嘻哈baby32 分钟前
MySQL数据库cpu飙升到500%该如何处理?
后端
莫寒清44 分钟前
Spring MVC:@PathVariable 注解详解
java·spring·mvc
AKA__Zas1 小时前
初识基本排序
java·数据结构·学习方法·排序
彡Summer丶1 小时前
后台管理系统实战
后端
Java编程爱好者1 小时前
字节Trae IDE全模式深度解析+Java后端实战技巧,架构师面试效率拉满
后端
Java水解1 小时前
你真的会打印日志吗?基于 Spring Boot 的全方位日志指南
spring boot·后端
Gogo11211 小时前
架构的宿命:深入对比 NestJS (Node.js) 与 Java 的垃圾回收机制
java·node.js