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

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);
    }
}
相关推荐
时艰.几秒前
JVM — Java 类加载机制
java·开发语言·jvm
J_liaty2 分钟前
分库分表深度解析
后端
哪里不会点哪里.34 分钟前
Spring MVC 核心原理解析:从请求到响应到底发生了什么?
java·spring·mvc
WKP941836 分钟前
线程并行控制CompletableFuture
java·开发语言
九皇叔叔40 分钟前
application.yml 文件无 Spring 图标 + 无自动提示
java·spring boot·spring
马猴烧酒.1 小时前
JAVA后端用户登录与鉴权详解
java·数据库·sql
乐之者v1 小时前
软件开发常规流程的版本缩写
java
DN20201 小时前
靠谱的AI销售机器人哪家好
java·人工智能·机器人
黎雁·泠崖1 小时前
Java继承细节:子类继承父类成员的底层逻辑
java·开发语言
冷雨夜中漫步1 小时前
Java中strip与trim()的区别
java·开发语言