Merge branch 'master' into tmp
# Conflicts: # README.md # UPDATE.md # pom.xml # yexuejc-springboot-base/pom.xml # yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/MutiRedisAutoConfiguration.java # yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/RedisTest.java # yexuejc-springboot-base/src/test/resources/application.properties
This commit is contained in:
commit
7fb712c596
|
@ -12,8 +12,8 @@ parent:版本封装<br/>
|
|||
base:功能封装
|
||||
|
||||
#### 最新版本
|
||||
>yexuejc.springboot.version=2.0.0 <br>
|
||||
>yexuejc.base.version=1.1.9
|
||||
>yexuejc.springboot.version=2.0.2 <br>
|
||||
>yexuejc.base.version=1.2.0
|
||||
|
||||
pom.xml
|
||||
```
|
||||
|
@ -104,5 +104,4 @@ pom.xml
|
|||
|
||||
[更新记录](UPDATE.md)
|
||||
<br/>
|
||||
[1.0.6新增 针对API请求安全解决方案](PARAMS_RSA_DECRYPT_ENCRYPT.md)<br/>
|
||||
[1.0.6新增 加密功能](PARAMS_RSA_DECRYPT_ENCRYPT.md)
|
||||
[相关功能使用指南](doc/MENU.md)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
功能目录
|
||||
------------------------
|
||||
|
||||
### 第三方集成
|
||||
#
|
||||
* [redis 集成](REDIS.md)
|
||||
* [Aliyun MNS 消息队列](MNS.md)
|
||||
* [Aliyun OSS 对象存储](OSS.md)
|
||||
|
||||
### 内部集成
|
||||
#
|
||||
* [1.0.6新增 针对API请求安全解决方案](PARAMS_RSA_DECRYPT_ENCRYPT.md)<br/>
|
||||
* [1.0.6新增 加密功能](PARAMS_RSA_DECRYPT_ENCRYPT.md)
|
|
@ -0,0 +1,34 @@
|
|||
aliyun MNS 消息队列 使用指南
|
||||
-------------
|
||||
* 本项目依赖不向下传递
|
||||
* 开通请参考[阿里云-消息服务-MNS](https://help.aliyun.com/product/27412.html?spm=5176.7944397.207973.oss4.4d1ab2418oQPP0)
|
||||
|
||||
> 引入依赖 pom.xml
|
||||
|
||||
```mxml
|
||||
<dependencies>
|
||||
<!-- 阿里云基础SDK -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
</dependency>
|
||||
<!-- 阿里云消息服务MNS相关SDK -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.mns</groupId>
|
||||
<artifactId>aliyun-sdk-mns</artifactId>
|
||||
<classifier>jar-with-dependencies</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
> 配置 application.properties
|
||||
```
|
||||
#mns
|
||||
yexuejc.alibaba.mns.access-key-id=阿里MNS提供的AccessKey
|
||||
yexuejc.alibaba.mns.access-key-secret=阿里MNS提供的的SecretKey
|
||||
yexuejc.alibaba.mns.endpoint=MNS接入endpoint,公网,私网,VPC各不相同,需要分环境配置
|
||||
yexuejc.alibaba.mns.queue-name-prefix=队列名称前缀
|
||||
```
|
||||
|
||||
> 使用example
|
||||
|
||||
参考[MnsTest.java](../yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/MnsTest.java)
|
|
@ -0,0 +1,36 @@
|
|||
aliyun OSS 对象存储 使用指南
|
||||
-------------
|
||||
* 本项目依赖不向下传递
|
||||
* 开通请参考[阿里云对象存储-OSS](https://help.aliyun.com/document_detail/32008.html?spm=5176.87240.400427.45.1dd74614DiKpxR)
|
||||
|
||||
_本工程暂提供上传功能_
|
||||
|
||||
> 引入依赖 pom.xml
|
||||
|
||||
```mxml
|
||||
<dependencies>
|
||||
<!-- 阿里云基础SDK -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
</dependency>
|
||||
<!-- 阿里云OSS相关SDK -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
> 配置
|
||||
``` application.properties
|
||||
#OSS
|
||||
yexuejc.alibaba.oss.endpoint=阿里OSS提供的endpoint
|
||||
yexuejc.alibaba.oss.access-key-secret=阿里OSS提供的SecretKey
|
||||
yexuejc.alibaba.oss.access-key-id=阿里OSS提供的AccessKey
|
||||
yexuejc.alibaba.oss.bucket=阿里OSS提供的bucket
|
||||
|
||||
```
|
||||
|
||||
> 使用example
|
||||
|
||||
参考[OssTest.java](../yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/OssTest.java)
|
|
@ -0,0 +1,30 @@
|
|||
redis 使用指南
|
||||
-------------
|
||||
* 本项目依赖不向下传递
|
||||
|
||||
> 引入依赖 pom.xml
|
||||
|
||||
```mxml
|
||||
<dependencies>
|
||||
<!-- 使用Redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
> 配置 application.properties
|
||||
```
|
||||
#reids
|
||||
spring.redis.host=你的reids地址
|
||||
spring.redis.password=密码
|
||||
spring.redis.port=端口
|
||||
```
|
||||
|
||||
> 使用example
|
||||
|
||||
参考[RedisTest.java](../yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/RedisTest.java)
|
6
pom.xml
6
pom.xml
|
@ -38,11 +38,11 @@
|
|||
<fastjson.version>1.2.49</fastjson.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<!-- 阿里云相关 -->
|
||||
<aliyun-java-sdk-core.version>4.0.8</aliyun-java-sdk-core.version>
|
||||
<aliyun-java-sdk-core.version>4.1.1</aliyun-java-sdk-core.version>
|
||||
<aliyun-java-sdk-sts.version>3.0.0</aliyun-java-sdk-sts.version>
|
||||
<aliyun-sdk-oss.version>3.1.0</aliyun-sdk-oss.version>
|
||||
<aliyun-java-sdk-dysmsapi.version>1.1.0</aliyun-java-sdk-dysmsapi.version>
|
||||
<aliyun-sdk-mns.version>1.1.8.6</aliyun-sdk-mns.version>
|
||||
<aliyun-sdk-mns.version>1.1.8</aliyun-sdk-mns.version>
|
||||
<!-- 支付宝相关 -->
|
||||
<alipay-sdk-java.version>3.3.49.ALL</alipay-sdk-java.version>
|
||||
<!-- 微信相关 -->
|
||||
|
@ -180,14 +180,12 @@
|
|||
<version>${aliyun-sdk-mns.version}</version>
|
||||
<classifier>jar-with-dependencies</classifier>
|
||||
</dependency>
|
||||
|
||||
<!-- copy对象 -->
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware.reflectasm</groupId>
|
||||
<artifactId>reflectasm</artifactId>
|
||||
<version>${reflectasm.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
|
|
|
@ -79,6 +79,13 @@
|
|||
<artifactId>jedis</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- 阿里云消息服务MNS相关SDK -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.mns</groupId>
|
||||
<artifactId>aliyun-sdk-mns</artifactId>
|
||||
<classifier>jar-with-dependencies</classifier>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.yexuejc.springboot.base.autoconfigure;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.aliyun.mns.client.MNSClient;
|
||||
|
||||
/**
|
||||
* 阿里云消息服务MNS相关配置
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName MnsAutoConfiguration
|
||||
* @Description
|
||||
* @date 2018/11/1 10:04
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(MNSClient.class)
|
||||
@EnableConfigurationProperties(MnsProperties.class)
|
||||
public class MnsAutoConfiguration {
|
||||
private final MnsProperties properties;
|
||||
|
||||
public MnsAutoConfiguration(MnsProperties properties) {
|
||||
super();
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MnsFacade mnsFacade() {
|
||||
return new MnsFacade(properties);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
|
||||
package com.yexuejc.springboot.base.autoconfigure;
|
||||
|
||||
import com.aliyun.mns.client.CloudAccount;
|
||||
import com.aliyun.mns.client.CloudTopic;
|
||||
import com.aliyun.mns.client.MNSClient;
|
||||
import com.aliyun.mns.model.*;
|
||||
import com.yexuejc.springboot.base.util.LogUtil;
|
||||
|
||||
/**
|
||||
* 阿里云消息服务MNS操作类
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName MnsFacade
|
||||
* @Description
|
||||
* @date 2018/11/1 10:21
|
||||
*/
|
||||
public class MnsFacade {
|
||||
/**
|
||||
* 默认长轮询等待秒数
|
||||
*/
|
||||
private static int DEFAULT_WAIT_SECONDS = 15;
|
||||
|
||||
/**
|
||||
* 项目中需要用到的所有队列
|
||||
*/
|
||||
private MNSClient client;
|
||||
/**
|
||||
* MNS相关配置
|
||||
*/
|
||||
private MnsProperties properties;
|
||||
|
||||
public MnsFacade(MnsProperties properties) {
|
||||
CloudAccount account = new CloudAccount(properties.getAccessKeyId(), properties.getAccessKeySecret(),
|
||||
properties.getEndpoint());
|
||||
this.client = account.getMNSClient();
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param queueName 发送对象队列名
|
||||
* @param msg 发送的消息字符串,使用json格式
|
||||
* @param delaySeconds 发送成功的Message对象
|
||||
* @return
|
||||
*/
|
||||
public Message sendMsg(String queueName, String msg, int delaySeconds) {
|
||||
Message message = new Message();
|
||||
message.setMessageBody(msg);
|
||||
message.setDelaySeconds(delaySeconds);
|
||||
LogUtil.bizLogger.debug("[alibaba-MNS]发送消息{}:{}", queueName, msg);
|
||||
return client.getQueueRef(queueFullName(queueName)).putMessage(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取出消息
|
||||
*
|
||||
* @param queueName 接收对象对列名
|
||||
* @return 接收成功的Message对象
|
||||
*/
|
||||
public Message popMsg(String queueName) {
|
||||
return client.getQueueRef(queueFullName(queueName)).popMessage(DEFAULT_WAIT_SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取出消息 长轮询
|
||||
*
|
||||
* @param queueName 接收对象对列名
|
||||
* @param waitSeconds 接收成功的Message对象
|
||||
* @return
|
||||
*/
|
||||
public Message popMsg(String queueName, int waitSeconds) {
|
||||
return client.getQueueRef(queueFullName(queueName)).popMessage(waitSeconds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除消息
|
||||
*
|
||||
* @param queueName 删除对象对列名
|
||||
* @param msg 需要删除的Message对象
|
||||
*/
|
||||
public void deleteMsg(String queueName, Message msg) {
|
||||
LogUtil.bizLogger.info("删除对象--:queueName{},msg{}", queueName, msg);
|
||||
client.getQueueRef(queueFullName(queueName)).deleteMessage(msg.getReceiptHandle());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回队列全称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String queueFullName(String queueName) {
|
||||
return properties.getQueueNamePrefix() + "-" + queueName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建主题
|
||||
*/
|
||||
public CloudTopic crtTopic() {
|
||||
TopicMeta topicMeta = new TopicMeta();
|
||||
topicMeta.setTopicName(properties.getTopicName());
|
||||
//是否启用日志
|
||||
topicMeta.setLoggingEnabled(true);
|
||||
return client.createTopic(topicMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除主题
|
||||
*/
|
||||
public void delTopic() {
|
||||
getTopic().delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主题
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CloudTopic getTopic() {
|
||||
return client.getTopicRef(properties.getTopicName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订阅
|
||||
*/
|
||||
public void subscribe(String subscriptionName, String queueName) {
|
||||
CloudTopic topic = getTopic();
|
||||
SubscriptionMeta subMeta = new SubscriptionMeta();
|
||||
subMeta.setSubscriptionName(subscriptionName);
|
||||
subMeta.setNotifyContentFormat(SubscriptionMeta.NotifyContentFormat.SIMPLIFIED);
|
||||
subMeta.setEndpoint(topic.generateQueueEndpoint(queueFullName(queueName)));
|
||||
topic.subscribe(subMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public TopicMessage publishMessage(String message) {
|
||||
CloudTopic topic = getTopic();
|
||||
//可以使用TopicMessage结构,选择不进行Base64加密
|
||||
TopicMessage msg = new Base64TopicMessage();
|
||||
msg.setMessageBody(message);
|
||||
msg = topic.publishMessage(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取出消息
|
||||
*
|
||||
* @param queueName
|
||||
* @return
|
||||
*/
|
||||
public Message popTopicMessage(String queueName) {
|
||||
QueueMeta queueMeta = new QueueMeta();
|
||||
queueMeta.setQueueName(queueFullName(queueName));
|
||||
return client.createQueue(queueMeta).popMessage(DEFAULT_WAIT_SECONDS);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.yexuejc.springboot.base.autoconfigure;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* 阿里云消息服务MNS相关配置
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName MnsProperties
|
||||
* @Description
|
||||
* @date 2018/11/1 10:27
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "yexuejc.alibaba.mns")
|
||||
public class MnsProperties {
|
||||
/**
|
||||
* 在RAM创建的AccessKey
|
||||
*/
|
||||
private String accessKeyId="xxxxxxxxxx";
|
||||
/**
|
||||
* 在RAM创建的SecretKey
|
||||
*/
|
||||
private String accessKeySecret="xxxxxxxxx";
|
||||
/**
|
||||
* MNS接入endpoint,公网,私网,VPC各不相同,需要分环境配置
|
||||
*/
|
||||
private String endpoint="http://00000000.mns.cn-hangzhou.aliyuncs.com";
|
||||
|
||||
/**
|
||||
* 队列名称前缀(消费端为CONSUMER,测试环境为IVT-CONSUMER)
|
||||
*/
|
||||
private String queueNamePrefix;
|
||||
private String topicName = "IVT";
|
||||
|
||||
public String getAccessKeyId() {
|
||||
return accessKeyId;
|
||||
}
|
||||
|
||||
public void setAccessKeyId(String accessKeyId) {
|
||||
this.accessKeyId = accessKeyId;
|
||||
}
|
||||
|
||||
public String getAccessKeySecret() {
|
||||
return accessKeySecret;
|
||||
}
|
||||
|
||||
public void setAccessKeySecret(String accessKeySecret) {
|
||||
this.accessKeySecret = accessKeySecret;
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public String getQueueNamePrefix() {
|
||||
return queueNamePrefix;
|
||||
}
|
||||
|
||||
public void setQueueNamePrefix(String queueNamePrefix) {
|
||||
this.queueNamePrefix = queueNamePrefix;
|
||||
}
|
||||
|
||||
public String getTopicName() {
|
||||
return topicName;
|
||||
}
|
||||
|
||||
public void setTopicName(String topicName) {
|
||||
this.topicName = topicName;
|
||||
}
|
||||
}
|
|
@ -9,10 +9,16 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* OSS相关配置
|
||||
* 阿里OSS相关配置
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName OssAutoConfiguration
|
||||
* @Description
|
||||
* @date 2018/11/1 10:30
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ OSSClient.class })
|
||||
@ConditionalOnClass({OSSClient.class})
|
||||
@EnableConfigurationProperties(OssProperties.class)
|
||||
public class OssAutoConfiguration {
|
||||
|
||||
|
|
|
@ -9,6 +9,12 @@ import java.io.InputStream;
|
|||
|
||||
/**
|
||||
* 阿里云OSS服务MNS操作类
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName OssFacade
|
||||
* @Description
|
||||
* @date 2018/11/1 10:30
|
||||
*/
|
||||
public class OssFacade {
|
||||
|
||||
|
|
|
@ -2,17 +2,34 @@ package com.yexuejc.springboot.base.autoconfigure;
|
|||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "yexuejc.oss")
|
||||
/**
|
||||
* 阿里OSS相关配置
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName OssProperties
|
||||
* @Description
|
||||
* @date 2018/11/1 10:30
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "yexuejc.alibaba.oss")
|
||||
public class OssProperties {
|
||||
|
||||
/** Endpoint 默认内网,外网需要自行配置:http://oss-cn-hangzhou.aliyuncs.com */
|
||||
private String endpoint = "oss-cn-hangzhou-internal.aliyuncs.com";
|
||||
/** 产品域名(固定) */
|
||||
private String accessKeyID = "LTAInCYwtsprAu8g";
|
||||
/** 区域ID(固定) */
|
||||
private String accessKeySecret = "6aqMtyFuJPUPChYpZSLsQ11cg4qby7";
|
||||
/** 默认bucket */
|
||||
private String bucket = "ecentm-res";
|
||||
/**
|
||||
* Endpoint 默认内网,外网需要自行配置:http://oss-cn-hangzhou.aliyuncs.com
|
||||
*/
|
||||
private String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
|
||||
/**
|
||||
* 产品域名(固定)
|
||||
*/
|
||||
private String accessKeyId = "xxxxx";
|
||||
/**
|
||||
* 区域ID(固定)
|
||||
*/
|
||||
private String accessKeySecret = "xxxxx";
|
||||
/**
|
||||
* 默认bucket
|
||||
*/
|
||||
private String bucket = "xxxxx";
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
|
@ -22,12 +39,12 @@ public class OssProperties {
|
|||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public String getAccessKeyID() {
|
||||
return accessKeyID;
|
||||
public String getAccessKeyId() {
|
||||
return accessKeyId;
|
||||
}
|
||||
|
||||
public void setAccessKeyID(String accessKeyID) {
|
||||
this.accessKeyID = accessKeyID;
|
||||
public void setAccessKeyId(String accessKeyId) {
|
||||
this.accessKeyId = accessKeyId;
|
||||
}
|
||||
|
||||
public String getAccessKeySecret() {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
package com.yexuejc.springboot.base.exception;
|
||||
|
||||
public class ImageException extends RuntimeException {
|
||||
private static final long serialVersionUID = -2390195902982826130L;
|
||||
private String code = "E";
|
||||
|
||||
public ImageException() {
|
||||
super("图片异常");
|
||||
}
|
||||
|
||||
public ImageException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ImageException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
public ImageException(String code, String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
|
@ -35,4 +35,5 @@ public class LogUtil {
|
|||
}
|
||||
return msg.replaceAll(";", "_");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,5 +3,6 @@ com.yexuejc.springboot.base.autoconfigure.WebAutoConfiguration,\
|
|||
com.yexuejc.springboot.base.autoconfigure.OssAutoConfiguration,\
|
||||
com.yexuejc.springboot.base.autoconfigure.MutiRedisAutoConfiguration,\
|
||||
com.yexuejc.springboot.base.filter.ParamsRequestBodyAdvice,\
|
||||
com.yexuejc.springboot.base.filter.ParamsResponseBodyAdvice
|
||||
com.yexuejc.springboot.base.filter.ParamsResponseBodyAdvice,\
|
||||
com.yexuejc.springboot.base.autoconfigure.MnsAutoConfiguration
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.yexuejc.springboot.base.test;
|
||||
|
||||
import com.aliyun.mns.model.Message;
|
||||
import com.yexuejc.base.util.JsonUtil;
|
||||
import com.yexuejc.base.util.StrUtil;
|
||||
import com.yexuejc.springboot.base.autoconfigure.MnsFacade;
|
||||
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 java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName MnsTest
|
||||
* @Description
|
||||
* @date 2018/11/1 14:25
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class MnsTest {
|
||||
|
||||
@Autowired
|
||||
MnsFacade mnsFacade;
|
||||
|
||||
/**
|
||||
* 发送MNS
|
||||
*/
|
||||
@Test
|
||||
public void sendMms() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", StrUtil.genUUID());
|
||||
map.put("type", "shop");
|
||||
mnsFacade.sendMsg("SHOP", JsonUtil.obj2Json(map), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取出消息->删除消息
|
||||
*/
|
||||
public void get() {
|
||||
Message msg = mnsFacade.popMsg("SHOP");
|
||||
if (msg == null) {
|
||||
System.out.println("取出空消息");
|
||||
}
|
||||
if (msg.getMessageBody() == null) {
|
||||
System.out.println("取出消息无内容");
|
||||
//删除
|
||||
mnsFacade.deleteMsg("SHOP", msg);
|
||||
}
|
||||
Map<String, Object> map = JsonUtil.json2Obj(msg.getMessageBody(), Map.class);
|
||||
System.out.println(String.format("取出消息:%s", JsonUtil.obj2Json(map)));
|
||||
//操作完成后删除消息
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.yexuejc.springboot.base.test;
|
||||
|
||||
import com.aliyun.oss.model.PutObjectResult;
|
||||
import com.yexuejc.base.util.ImgUtil;
|
||||
import com.yexuejc.base.util.StrUtil;
|
||||
import com.yexuejc.springboot.base.autoconfigure.OssFacade;
|
||||
import com.yexuejc.springboot.base.exception.ImageException;
|
||||
import com.yexuejc.springboot.base.util.LogUtil;
|
||||
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 java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName OssTest
|
||||
* @Description
|
||||
* @date 2018/11/1 14:58
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class OssTest {
|
||||
@Autowired
|
||||
OssFacade ossFacade;
|
||||
|
||||
/**
|
||||
* 上传图片到oss
|
||||
* <p>
|
||||
* 这里是模拟微信登录时,获取到微信头像地址,缓存到base64,然后上传到OSS
|
||||
* </p>
|
||||
*/
|
||||
@Test
|
||||
public void put(){
|
||||
putOss4Head(null, "https://avatar.csdn.net/7/8/1/3_wulex.jpg");
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传网络头像至OSS
|
||||
*
|
||||
* @param url 网络图片地址
|
||||
* @return String 本OSS地址
|
||||
*/
|
||||
public String putOss4Head(String name, String url) throws ImageException {
|
||||
if (StrUtil.isEmpty(name)) {
|
||||
name = StrUtil.genUUID();
|
||||
}
|
||||
if (name.indexOf(".") == 0) {
|
||||
throw new ImageException("图片名称第一个字符不能为.");
|
||||
}
|
||||
name = "head/" + name;
|
||||
try {
|
||||
LogUtil.bizLogger.info("[第三方登录/注册]上传头像开始:{}", url);
|
||||
InputStream is = ImgUtil.getImageInputStreamFromUrl(url);
|
||||
byte[] b = ImgUtil.getByteArray(is);
|
||||
ImgUtil.ImageInfo imageInfo = ImgUtil.getImageInfoFromInputStream(b);
|
||||
if (name.indexOf(".") < 0) {
|
||||
name = name + "." + imageInfo.getType();
|
||||
}
|
||||
PutObjectResult head = ossFacade.putObject(name, new ByteArrayInputStream(b));
|
||||
} catch (IOException e) {
|
||||
LogUtil.bizLogger.error("[第三方登录/注册]读取网络头像为IO异常:{}", url);
|
||||
e.printStackTrace();
|
||||
throw new ImageException("[第三方登录/注册]读取网络头像为IO异常:" + e.getMessage());
|
||||
}
|
||||
LogUtil.bizLogger.info("[[第三方登录/注册]上传头像结束:{}", url);
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.yexuejc.springboot.base.test;
|
||||
|
||||
import com.yexuejc.base.util.JsonUtil;
|
||||
import com.yexuejc.springboot.base.ApplicationRun;
|
||||
import com.yexuejc.base.util.StrUtil;
|
||||
import com.yexuejc.springboot.base.autoconfigure.MutiRedisAutoConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -9,53 +9,100 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* redis 操作
|
||||
*
|
||||
* @author maxf
|
||||
* @PackageName com.yexuejc.springboot.base.test
|
||||
* @version 1.0
|
||||
* @ClassName RedisTest
|
||||
* @Description
|
||||
* @date 2018/9/26 16:28
|
||||
* @date 2018/11/1 11:16
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = ApplicationRun.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class RedisTest {
|
||||
/**
|
||||
* 指向redis 0库
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier(MutiRedisAutoConfiguration.BEAN_REDIS_TEMPLATE0)
|
||||
RedisTemplate redisTemplate;
|
||||
private RedisTemplate<Object, Object> redisTemplate0;
|
||||
|
||||
/**
|
||||
* 保存用户登录信息
|
||||
* name:张三
|
||||
*/
|
||||
@Test
|
||||
public void insert() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("a", "b");
|
||||
map.put("c", 1);
|
||||
map.put("aac", true);
|
||||
map.put("q", "asdb");
|
||||
redisTemplate.opsForHash().putAll("test.redis", map);
|
||||
redisTemplate.expire("test.redis", 10, TimeUnit.MINUTES);
|
||||
public void save() {
|
||||
redisTemplate0.afterPropertiesSet();
|
||||
redisTemplate0.opsForHash().put("login.user.userId1", "name", "张三");
|
||||
redisTemplate0.expire("login.user.userId1", 10, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户登录信息
|
||||
* name:张三
|
||||
* sex:男
|
||||
*/
|
||||
@Test
|
||||
public void save2() {
|
||||
redisTemplate0.afterPropertiesSet();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", "张三");
|
||||
map.put("sex", "男");
|
||||
redisTemplate0.opsForHash().putAll("login.user.userId1", map);
|
||||
redisTemplate0.expire("login.user.userId1", 10, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存授权zhangsan的token,过期时间10分钟
|
||||
*/
|
||||
@Test
|
||||
public void accessToken() {
|
||||
redisTemplate0.afterPropertiesSet();
|
||||
redisTemplate0.opsForValue().append("zhangsan.access_token", StrUtil.genUUID());
|
||||
redisTemplate0.expire("zhangsan.access_token", 10, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户登录信息
|
||||
* name:张三
|
||||
*/
|
||||
@Test
|
||||
public void get() {
|
||||
Map<String, Object> map = redisTemplate.opsForHash().entries("test.redis");
|
||||
System.out.println(JsonUtil.obj2Json(map));
|
||||
redisTemplate0.afterPropertiesSet();
|
||||
String name = (String) redisTemplate0.opsForHash().get("login.user.userId1", "name");
|
||||
System.out.println(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户登录信息
|
||||
* name:张三->李四
|
||||
* age:20
|
||||
*/
|
||||
@Test
|
||||
public void update() {
|
||||
Map<String, Object> map = redisTemplate.opsForHash().entries("test.redis");
|
||||
redisTemplate.opsForHash().put("test.redis", "q", "123456798");
|
||||
public void put() {
|
||||
redisTemplate0.afterPropertiesSet();
|
||||
redisTemplate0.opsForHash().put("login.user.userId1", "name", "张三");
|
||||
redisTemplate0.opsForHash().put("login.user.userId1", "age", "20");
|
||||
Map<String, Object> map = (Map) redisTemplate0.opsForHash().entries("login.user.userId1");
|
||||
System.out.println(JsonUtil.obj2Json(map));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@Test
|
||||
public void del() {
|
||||
Boolean delete = redisTemplate.delete("test.redis");
|
||||
System.out.println(delete);
|
||||
redisTemplate0.afterPropertiesSet();
|
||||
redisTemplate0.delete("login.user.userId1");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ spring.application.name=@pom.artifactId@
|
|||
|
||||
#log
|
||||
logging.level.root=info
|
||||
logging.path=/logs/yexuejc-springboot-base
|
||||
logging.path=/logs/yexuejc-springboot-parent
|
||||
|
||||
|
||||
yexuejc.http.filter.type=0
|
||||
|
||||
|
@ -28,8 +29,23 @@ server.tomcat.uri-encoding=UTF-8
|
|||
#是否开启HTTPS(SSL)请求证书验证忽略:默认false
|
||||
yexuejc.enable.ssl-ignore=true
|
||||
|
||||
#reids
|
||||
#开启指定redis库db0默认开启
|
||||
yexuejc.redis.db1=true
|
||||
yexuejc.redis.db2=true
|
||||
spring.redis.host=121.42.165.89
|
||||
spring.redis.password=
|
||||
spring.redis.port=16379
|
||||
|
||||
|
||||
#mns
|
||||
yexuejc.alibaba.mns.access-key-id=
|
||||
yexuejc.alibaba.mns.access-key-secret=
|
||||
yexuejc.alibaba.mns.endpoint=http://1734411100610331.mns.cn-hangzhou.aliyuncs.com/
|
||||
yexuejc.alibaba.mns.queue-name-prefix=IVT-CONSUMER
|
||||
|
||||
#OSS
|
||||
yexuejc.alibaba.oss.endpoint=oss-cn-beijing.aliyuncs.com
|
||||
yexuejc.alibaba.oss.access-key-secret=
|
||||
yexuejc.alibaba.oss.access-key-id=
|
||||
yexuejc.alibaba.oss.bucket=guansichou
|
||||
|
|
Loading…
Reference in New Issue