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

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);
    }
}
相关推荐
码农阿豪4 分钟前
Oracle 到金仓数据库迁移实战:一次真正“落地”的国产替代之旅
java·数据库·oracle
小王不爱笑13224 分钟前
SpringBoot 整合 Ollama + 本地 DeepSeek 模型
java·spring boot·后端
毕设源码-钟学长25 分钟前
【开题答辩全过程】以 高校宿舍分配系统设计与实现为例,包含答辩的问题和答案
java
何中应26 分钟前
IDEA 中让 Git 忽略 .idea 目录
java·git·intellij-idea
無森~27 分钟前
HBase优化面试题
java·面试·hbase
PPPPickup38 分钟前
easymall---管理后端商品属性管理
java
人道领域41 分钟前
SSM框架从入门到入土(SpringFrameWork)
java·spring boot·tomcat
源力祁老师1 小时前
深入解析 Odoo 中 default_get 方法的功能
java·服务器·前端
团子的二进制世界1 小时前
Sentinel-服务保护(限流、熔断降级)
java·开发语言·sentinel·异常处理
NWU_白杨1 小时前
多线程安全与通信问题
java