Commit 45b7074e authored by liuyang's avatar liuyang

添加oss的cdn配置

parent f5fe8e50
...@@ -22,5 +22,7 @@ public class AliyunConfig { ...@@ -22,5 +22,7 @@ public class AliyunConfig {
private String bucket; private String bucket;
@Value("${aliyun.vod.region}") @Value("${aliyun.vod.region}")
private String region; private String region;
@Value("${aliyun.oss.cdn:''}")
private String cdn;
} }
package com.qkdata.aliyun.service; package com.qkdata.aliyun.service;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSS; import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSClientBuilder;
...@@ -187,7 +188,12 @@ public class AliyunService { ...@@ -187,7 +188,12 @@ public class AliyunService {
} }
public String getPublicUrl() { public String getPublicUrl() {
return "https://"+aliyunConfig.getBucket()+"."+aliyunConfig.getEndpoint(); if (StrUtil.isNotBlank(aliyunConfig.getCdn())){
return aliyunConfig.getCdn();
}else {
return "https://"+aliyunConfig.getBucket()+"."+aliyunConfig.getEndpoint();
}
} }
/** /**
......
...@@ -127,6 +127,7 @@ aliyun: ...@@ -127,6 +127,7 @@ aliyun:
oss: oss:
endpoint: oss-cn-beijing.aliyuncs.com endpoint: oss-cn-beijing.aliyuncs.com
bucket: qkdata-online-edu bucket: qkdata-online-edu
cdn:
vod: vod:
region: cn-shanghai region: cn-shanghai
alipay: alipay:
......
package com.qkdata.test;
import com.qkdata.aliyun.service.AliyunService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
public class AliyunServiceTest extends BaseTest{
@Autowired
private AliyunService aliyunService;
@Test
public void getPublicUrlTest(){
System.out.println(">>>>>>>>>>>>>>>>>"+aliyunService.getPublicUrl());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment