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

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);
    }
}
相关推荐
GetcharZp3 小时前
告别 jq 噩梦!这款 JSON 神器 fx 让你在终端体验“丝滑”的数据操作
后端
MY_TEUCK4 小时前
Sealos 平台部署实战指南:结合 Cursor 与版本发布流程
java·人工智能·学习·aigc
我爱cope4 小时前
【从0开始学设计模式-10| 装饰模式】
java·开发语言·设计模式
朝新_5 小时前
【Spring AI 】图像与语音模型实战
java·人工智能·spring
小码哥_常5 小时前
告别臃肿!Elasticsearch平替Manticore登场
后端
RH2312115 小时前
2026.4.16Linux 管道
java·linux·服务器
zmsofts5 小时前
java面试必问13:MyBatis 一级缓存、二级缓存:从原理到脏数据,一篇讲透
java·面试·mybatis
苍何6 小时前
万字保姆级教程:Hermes+Kimi K2.6 打造7x24h Agent军团
后端
我叫黑大帅6 小时前
为什么map查找时间复杂度是O(1)?
后端·算法·面试
aq55356007 小时前
编程语言三巨头:汇编、C++与PHP大比拼
java·开发语言