杨杰 6 năm trước cách đây
mục cha
commit
445a3ed260

+ 35 - 35
pom.xml

@@ -3,28 +3,28 @@
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
-	
+
 	<groupId>com.llisoft</groupId>
-    <artifactId>mta-service-file</artifactId>
-    <version>1.0.0</version>
-    <packaging>jar</packaging>
+	<artifactId>mta-service-file</artifactId>
+	<version>1.0.0</version>
+	<packaging>jar</packaging>
+
+	<name>mta-service-file</name>
+	<description>Demo project for Spring Boot</description>
 
-    <name>mta-service-file</name>
-    <description>Demo project for Spring Boot</description>
-	
 	<parent>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter-parent</artifactId>
-        <version>2.0.3.RELEASE</version>
-        <relativePath/> <!-- lookup parent from repository -->
-    </parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.0.3.RELEASE</version>
+		<relativePath /> <!-- lookup parent from repository -->
+	</parent>
 
-    <properties>
-        <java.version>1.8</java.version>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
-    </properties>
+	<properties>
+		<java.version>1.8</java.version>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+		<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
+	</properties>
 
 	<dependencies>
 		<dependency>
@@ -45,9 +45,9 @@
 			<version>2.0.1</version>
 		</dependency>
 		<dependency>
-			<groupId>com.aliyun.oss</groupId>
-			<artifactId>aliyun-sdk-oss</artifactId>
-			<version>3.1.0</version>
+			<groupId>com.aliyun</groupId>
+			<artifactId>aliyun-java-sdk-core</artifactId>
+			<version>4.1.0</version>
 		</dependency>
 		<dependency>
 			<groupId>io.springfox</groupId>
@@ -59,7 +59,7 @@
 			<artifactId>springfox-swagger-ui</artifactId>
 			<version>2.7.0</version>
 		</dependency>
-		
+
 		<dependency>
 			<groupId>com.llisoft</groupId>
 			<artifactId>mta-common</artifactId>
@@ -77,19 +77,19 @@
 			<optional>true</optional>
 		</dependency>
 	</dependencies>
-	
+
 	<dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.springframework.cloud</groupId>
-                <artifactId>spring-cloud-dependencies</artifactId>
-                <version>${spring-cloud.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-	
+		<dependencies>
+			<dependency>
+				<groupId>org.springframework.cloud</groupId>
+				<artifactId>spring-cloud-dependencies</artifactId>
+				<version>${spring-cloud.version}</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+		</dependencies>
+	</dependencyManagement>
+
 	<build>
 		<plugins>
 			<plugin>
@@ -105,5 +105,5 @@
 			</plugin>
 		</plugins>
 	</build>
-	
+
 </project>

+ 1 - 1
readme.md

@@ -1 +1 @@
-#### 文件服务
+#### 短信服务

+ 0 - 41
src/main/java/com/llisoft/service/file/controller/FileController.java

@@ -1,41 +0,0 @@
-package com.llisoft.service.file.controller;
-
-import javax.validation.Valid;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.llisoft.common.vo.ResponseVo;
-import com.llisoft.service.file.service.OssService;
-import com.llisoft.service.file.vo.DownloadRequestVo;
-import com.llisoft.service.file.vo.UploadRequestVo;
-import com.llisoft.service.file.vo.UploadResponseVo;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-
-@Api(tags="文件接口")
-@RestController
-@RequestMapping("/file")
-public class FileController {
-	
-	@Autowired
-	private OssService ossService;
-	
-	
-	@ApiOperation(value="上传")
-	@PostMapping("/upload")
-	public ResponseVo<UploadResponseVo> upload(@Valid @RequestBody UploadRequestVo vo) throws Exception{
-		return ResponseVo.success(ossService.upload(vo.getPrefix(), vo.getSuffix(), vo.isCdn()));
-	}
-	
-	@ApiOperation(value="下载")
-	@PostMapping("/download")
-	public ResponseVo<String> download(@Valid @RequestBody DownloadRequestVo vo) throws Exception{
-		return ResponseVo.success(ossService.download(vo.getKey()));
-	}
-	
-}

+ 0 - 105
src/main/java/com/llisoft/service/file/service/OssService.java

@@ -1,105 +0,0 @@
-package com.llisoft.service.file.service;
-
-import java.net.URL;
-import java.util.Date;
-import java.util.Objects;
-import java.util.UUID;
-
-import javax.annotation.PostConstruct;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-import com.aliyun.oss.ClientConfiguration;
-import com.aliyun.oss.OSSClient;
-import com.aliyun.oss.common.auth.DefaultCredentialProvider;
-import com.aliyun.oss.common.utils.BinaryUtil;
-import com.aliyun.oss.model.MatchMode;
-import com.aliyun.oss.model.PolicyConditions;
-import com.llisoft.service.file.vo.UploadCdnResponseVo;
-import com.llisoft.service.file.vo.UploadResponseVo;
-
-/**
- * 阿里云OSS接口调用
- * @author YangJie [2019年2月18日]
- */
-@Service
-public class OssService {
-	
-	private Logger logger = LoggerFactory.getLogger(OssService.class);
-	
-	@Value("${mta.debug}")
-	private boolean debug;
-	
-	@Value("${oss.url}")
-	private String url;
-	@Value("${oss.bucket}")
-	private String bucket;
-	@Value("${oss.endpoint}")
-	private String endpoint;
-	@Value("${oss.accessKeyId}")
-	private String accessKeyId;
-	@Value("${oss.accessKeySecret}")
-	private String accessKeySecret;
-	
-	
-	// OSS客户端
-	private OSSClient ossClient;
-	
-	@PostConstruct
-	public void init() {
-		ossClient = new OSSClient(endpoint,new DefaultCredentialProvider(accessKeyId, accessKeySecret), new ClientConfiguration());
-	}
-
-	/**
-	 * 上传
-	 * @return
-	 * @throws Exception 
-	 */
-	public UploadResponseVo upload(String prefix, String suffix, boolean cdn) throws Exception {
-		suffix = Objects.nonNull(suffix) ? "."+suffix : "";
-		prefix = Objects.nonNull(prefix) ? prefix : "";
-		prefix = cdn ? "public/" + prefix : "private/" + prefix; // 区分公开资源和私有资源
-		prefix = debug ? "test/" + prefix : prefix; // 测试环境下添加固定前缀, 定时清理
-		PolicyConditions policyConditions = new PolicyConditions();
-		policyConditions.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1024*1024*1024*1); // 内容长度范围1G
-		policyConditions.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, prefix); // key前缀
-		String postPolicy = ossClient.generatePostPolicy(this.getExpiration(10), policyConditions); // 有效期10分钟
-		UploadResponseVo uploadBean = cdn ? new UploadCdnResponseVo() : new UploadResponseVo();
-		uploadBean.setKey(prefix + UUID.randomUUID().toString().replace("-", "") + suffix);
-		uploadBean.setPolicy(BinaryUtil.toBase64String(postPolicy.getBytes("utf-8")));
-		uploadBean.setSignature(ossClient.calculatePostSignature(postPolicy));
-		uploadBean.setAccessid(accessKeyId);
-		uploadBean.setUrl(url);
-		return uploadBean;
-	}
-	
-	/**
-	 * 下载
-	 * @param key
-	 * @return
-	 */
-	public String download(String key) {
-		logger.info("oss下载请求: {}", key);
-		if(Objects.isNull(key) || key.trim().isEmpty()) {
-			return null;
-		}
-		URL url = ossClient.generatePresignedUrl(bucket, key, this.getExpiration(30)); // 授权有效期30分钟
-		String result = url.toString();
-		logger.info("oss下载返回: {}", result);
-		return result;
-	}
-
-	/**
-	 * 获取有效期
-	 * @param minute 分钟
-	 * @return
-	 */
-	private Date getExpiration(int minute) {
-		return new Date(System.currentTimeMillis() + 1000*60*minute);
-	}
-	
-	
-}

+ 0 - 35
src/main/java/com/llisoft/service/file/vo/UploadCdnResponseVo.java

@@ -1,35 +0,0 @@
-package com.llisoft.service.file.vo;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel("上传返回实体CDN")
-public class UploadCdnResponseVo extends UploadResponseVo{
-	
-	@ApiModelProperty("宽度200缩略图")
-	private String w200 = "!w200";
-	@ApiModelProperty("宽度缩400略图")
-	private String w400 = "!w400";
-	@ApiModelProperty("宽度800缩略图")
-	private String w800 = "!w800";
-	
-	public String getW200() {
-		return w200;
-	}
-	public void setW200(String w200) {
-		this.w200 = w200;
-	}
-	public String getW400() {
-		return w400;
-	}
-	public void setW400(String w400) {
-		this.w400 = w400;
-	}
-	public String getW800() {
-		return w800;
-	}
-	public void setW800(String w800) {
-		this.w800 = w800;
-	}
-	
-}

+ 0 - 35
src/main/java/com/llisoft/service/file/vo/UploadRequestVo.java

@@ -1,35 +0,0 @@
-package com.llisoft.service.file.vo;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel("上传请求实体")
-public class UploadRequestVo {
-	
-	@ApiModelProperty("前缀")
-	private String prefix;
-	@ApiModelProperty("后缀")
-	private String suffix;
-	@ApiModelProperty("CDN")
-	private boolean cdn;
-	
-	public String getPrefix() {
-		return prefix;
-	}
-	public void setPrefix(String prefix) {
-		this.prefix = prefix;
-	}
-	public String getSuffix() {
-		return suffix;
-	}
-	public void setSuffix(String suffix) {
-		this.suffix = suffix;
-	}
-	public boolean isCdn() {
-		return cdn;
-	}
-	public void setCdn(boolean cdn) {
-		this.cdn = cdn;
-	}
-	
-}

+ 0 - 52
src/main/java/com/llisoft/service/file/vo/UploadResponseVo.java

@@ -1,52 +0,0 @@
-package com.llisoft.service.file.vo;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel("上传返回实体")
-public class UploadResponseVo {
-	
-	@ApiModelProperty("地址")
-	private String url;
-	@ApiModelProperty("ID")
-	private String accessid;
-	@ApiModelProperty("凭证")
-	private String policy;
-	@ApiModelProperty("签名")
-	private String signature;
-	@ApiModelProperty("KEY")
-	private String key;
-	
-	public String getAccessid() {
-		return accessid;
-	}
-	public void setAccessid(String accessid) {
-		this.accessid = accessid;
-	}
-	public String getPolicy() {
-		return policy;
-	}
-	public void setPolicy(String policy) {
-		this.policy = policy;
-	}
-	public String getSignature() {
-		return signature;
-	}
-	public void setSignature(String signature) {
-		this.signature = signature;
-	}
-	public String getKey() {
-		return key;
-	}
-	public void setKey(String key) {
-		this.key = key;
-	}
-	public String getUrl() {
-		return url;
-	}
-	public void setUrl(String url) {
-		this.url = url;
-	}
-
-	
-}

+ 1 - 1
src/main/java/com/llisoft/service/file/Application.java → src/main/java/com/llisoft/service/msg/Application.java

@@ -1,4 +1,4 @@
-package com.llisoft.service.file;
+package com.llisoft.service.msg;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 1 - 1
src/main/java/com/llisoft/service/file/config/ErrorConfig.java → src/main/java/com/llisoft/service/msg/config/ErrorConfig.java

@@ -1,4 +1,4 @@
-package com.llisoft.service.file.config;
+package com.llisoft.service.msg.config;
 
 import java.util.Objects;
 

+ 1 - 1
src/main/java/com/llisoft/service/file/config/ExceptionConfig.java → src/main/java/com/llisoft/service/msg/config/ExceptionConfig.java

@@ -1,4 +1,4 @@
-package com.llisoft.service.file.config;
+package com.llisoft.service.msg.config;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 1 - 1
src/main/java/com/llisoft/service/file/config/SpringMvcConfig.java → src/main/java/com/llisoft/service/msg/config/SpringMvcConfig.java

@@ -1,4 +1,4 @@
-package com.llisoft.service.file.config;
+package com.llisoft.service.msg.config;
 
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;

+ 2 - 2
src/main/java/com/llisoft/service/file/config/SwaggerConfig.java → src/main/java/com/llisoft/service/msg/config/SwaggerConfig.java

@@ -1,4 +1,4 @@
-package com.llisoft.service.file.config;
+package com.llisoft.service.msg.config;
 
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
@@ -24,7 +24,7 @@ public class SwaggerConfig {
 	@Bean  
 	public Docket docket() {  
 		return new Docket(DocumentationType.SWAGGER_2)
-			.apiInfo(new ApiInfoBuilder().title("文件服务API").version("v1.0.0").build())
+			.apiInfo(new ApiInfoBuilder().title("短信服务API").version("v1.0.0").build())
 			.directModelSubstitute(byte.class, int.class) //修正byte转string的Bug
 			.select()
 			// 文档中需要屏蔽的接口

+ 14 - 0
src/main/java/com/llisoft/service/msg/controller/MsgController.java

@@ -0,0 +1,14 @@
+package com.llisoft.service.msg.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.annotations.Api;
+
+@Api(tags="短信接口")
+@RestController
+@RequestMapping("/msg")
+public class MsgController {
+	
+	
+}

+ 13 - 0
src/main/java/com/llisoft/service/msg/service/MsgService.java

@@ -0,0 +1,13 @@
+package com.llisoft.service.msg.service;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * 阿里云OSS接口调用
+ * https://help.aliyun.com/document_detail/101414.html
+ * @author YangJie [2019年2月18日]
+ */
+@Service
+public class MsgService {
+	
+}

+ 3 - 3
src/main/java/com/llisoft/service/file/vo/DownloadRequestVo.java → src/main/java/com/llisoft/service/msg/vo/MsgRequestVo.java

@@ -1,12 +1,12 @@
-package com.llisoft.service.file.vo;
+package com.llisoft.service.msg.vo;
 
 import javax.validation.constraints.NotBlank;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
-@ApiModel("下载请求实体")
-public class DownloadRequestVo {
+@ApiModel("短信请求实体")
+public class MsgRequestVo {
 	
 	@ApiModelProperty("KEY")
 	@NotBlank(message="KEY不能为空")

+ 3 - 3
src/main/java/com/llisoft/service/file/vo/DownloadResponseVo.java → src/main/java/com/llisoft/service/msg/vo/MsgResponseVo.java

@@ -1,10 +1,10 @@
-package com.llisoft.service.file.vo;
+package com.llisoft.service.msg.vo;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
-@ApiModel("下载返回实体")
-public class DownloadResponseVo {
+@ApiModel("短信返回实体")
+public class MsgResponseVo {
 	
 	@ApiModelProperty("URL")
 	private String url;

+ 4 - 9
src/main/resources/application.yml

@@ -1,18 +1,13 @@
 ##服务配置
 server:
-  port: 8001 #监听端口
+  port: 8003 #监听端口
   
 ##自定义配置
 mta: 
   debug: true #是否测试
   
-##oss配置
-oss: 
-  url: http://yangjie-test.oss-cn-beijing.aliyuncs.com
-  bucket: yangjie-test
-  endpoint: http://oss-cn-beijing.aliyuncs.com
-  accessKeyId: LTAIbMS7HApX1Vz7
-  accessKeySecret: f1ro3QyunFsyElXfjCAJWtPozdCjNu
+##短信配置
+
     
 
 ##spring配置
@@ -36,7 +31,7 @@ eureka:
 
 ##监控配置    
 management:
-  server.port: 18001 #监控端口
+  server.port: 18003 #监控端口
   endpoints.web.exposure.include: "*" #开启所有端点
   endpoint.health.show-details: always #显示健康详情
   

+ 2 - 10
src/test/java/com/llisoft/service/file/ServiceTest.java → src/test/java/com/llisoft/service/msg/ServiceTest.java

@@ -1,25 +1,17 @@
-package com.llisoft.service.file;
+package com.llisoft.service.msg;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import com.llisoft.common.util.JsonUtil;
-import com.llisoft.service.file.service.OssService;
-
 @SpringBootTest
 @RunWith(SpringRunner.class)
 public class ServiceTest {
-	
-	@Autowired
-	private OssService ossService;
-	
+
 	@Test
 	public void test() throws Exception{
 		long begin = System.currentTimeMillis();
-		System.out.println(JsonUtil.toJson(ossService.upload("", "", true)));
 		System.out.println("耗时:"+ (System.currentTimeMillis() - begin));
 	}