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

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);
    }
}
相关推荐
计算机程序设计小李同学5 小时前
基于位置服务的二手图书回收平台
java·前端·vue.js·spring boot·后端
青云交5 小时前
Java 大视界 -- 基于 Java+Flink 构建实时风控规则引擎:动态规则配置与热更新(446)
java·nacos·flink·规则引擎·aviator·实时风控·动态规则
想逃离铁厂的老铁5 小时前
Day51 >> 99、计数孤岛 + 100、最大岛屿面积
java·服务器
Java程序员威哥5 小时前
SpringBoot多环境配置实战:从基础用法到源码解析与生产避坑
java·开发语言·网络·spring boot·后端·python·spring
Thanwind5 小时前
系统可观测性解析与其常用套件
java
茶本无香5 小时前
设计模式之六—组合模式:构建树形结构的艺术
java·设计模式·组合模式
LJianK15 小时前
select .. group by
java·数据库·sql
猿小羽5 小时前
[TEST] Spring Boot 快速入门指南 - 1769246843980
java·spring boot·后端
阿蒙Amon5 小时前
C#每日面试题-简述this和base的作用
java·面试·c#
毕设源码-朱学姐5 小时前
【开题答辩全过程】以 基于SSM的航班管理系统的设计与实现为例,包含答辩的问题和答案
java