赞
踩
后端 Spring Boot 微服务开发
注意 :aliyun-java-vod-upload-1.4.14.jar 还未开源,需要手动下载添加到Maven仓库
- public class VodEntity implements InitializingBean {
- @Value("${aliyun.vod.file.keyid}")
- private String keyId;
-
- @Value("${aliyun.vod.file.keysecret}")
- private String keySecret;
-
- public static String ACCESS_KEY_ID;
- public static String ACCESS_KEY_SECRET;
-
- @Override
- public void afterPropertiesSet() throws Exception {
- ACCESS_KEY_ID = keyId;
- ACCESS_KEY_SECRET = keySecret;
- }
- }
新建一个类写入以下
- public class VodUtils {
- public static DefaultAcsClient initVodClient(String accessKeyId,String accessKeySecret) throws ClientException {
- String regionId = "cn-shanghai";
- DefaultProfile profile = DefaultProfile.getProfile(regionId,accessKeyId,accessKeySecret);
- DefaultAcsClient client = new DefaultAcsClient(profile);
- return client;
- }
- }
注意 :String regionId = "cn-shanghai"; 会不同,一定要查好服务器的所在地 。
- public String playVod(String vid) {
- try {
- DefaultAcsClient client = VodUtils.initVodClient(VodEntity.ACCESS_KEY_ID, VodEntity.ACCESS_KEY_SECRET);
- // 获取凭证对象
- GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
- // 设置视频id
- request.setVideoId(vid);
- // 执行请求
- GetVideoPlayAuthResponse response = client.getAcsResponse(request);
- String playAuth = response.getPlayAuth();
- // 返回凭证
- return playAuth;
- } catch (ClientException e) {
- e.printStackTrace();
- }
- return null;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。