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

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);
    }
}
相关推荐
小雅痞6 分钟前
[Java][Leetcode simple] 1. 两数之和
java·算法·leetcode
bingd016 分钟前
慕课网、CSDN、菜鸟教程…2026 国内编程学习平台实测对比
java·开发语言·人工智能·python·学习
精品源码屋7 分钟前
千万级CSV/Excel表统计教程:基于本地数据库的自然语言单表、多表分析 | DT-Bot工作流
后端
大飞哥~BigFei9 分钟前
缓存一致性终极解决方案之Facebook租约机制的开源实现集成改造
java·缓存·开源
凌冰_13 分钟前
Thymeleaf 核心语法详解
java·前端·javascript
AIBox36515 分钟前
claude 镜像 api 使用指南(2026 年4 月更新)
java·服务器·前端·人工智能·gpt·前端框架
极光代码工作室16 分钟前
基于SpringBoot的在线考试系统
java·springboot·web开发·后端开发
Gopher_HBo19 分钟前
CompletableFuture运用原理
java·后端
庞轩px21 分钟前
反射与动态代理——Java语言动态性的核心
java·spring·反射·aop·动态代理·类型
Leinwin27 分钟前
GPT-6 API接入完全指南:Symphony架构下的多模态调用与最佳实践
后端·python·flask