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

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);
    }
}
相关推荐
mit6.8245 分钟前
[Meetily后端框架] AI摘要结构化 | `SummaryResponse`模型 | Pydantic库 | vs marshmallow库
c++·人工智能·后端
陈随易18 分钟前
VSCode v1.102发布,AI体验大幅提升
前端·后端·程序员
生无谓31 分钟前
什么是跨域,如何处理跨域
后端
咖啡啡不加糖32 分钟前
RabbitMQ 消息队列:从入门到Spring Boot实战
java·spring boot·rabbitmq
Smilejudy33 分钟前
极具特色的位置运算
后端
码出极致34 分钟前
支付线上问题复盘的“5W”框架
后端
玩代码39 分钟前
Java线程池原理概述
java·开发语言·线程池
ezl1fe42 分钟前
RAG 每日一技(三):不止文本,代码和Markdown如何优雅地分块?
后端
NE_STOP42 分钟前
SpringBoot--如何给项目添加配置属性及读取属性
java
jack_yin43 分钟前
手把手教你玩转 telegram-deepseek-bot 的 Admin 管理后台!
后端