mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Add test case.
This commit is contained in:
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.cloud.alicloud.sms;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pbting
|
||||
@@ -29,6 +29,7 @@ public abstract class AbstractSmsService implements ISmsService {
|
||||
|
||||
private ConcurrentHashMap<String, IAcsClient> acsClientConcurrentHashMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public IAcsClient getHangZhouRegionClientProfile(String accessKeyId,
|
||||
String accessKeySecret) {
|
||||
|
||||
|
@@ -18,7 +18,7 @@ package org.springframework.cloud.alicloud.sms;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsConfigProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsProperties;
|
||||
import org.springframework.cloud.alicloud.sms.base.MessageListener;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -35,11 +35,11 @@ public class SmsInitializerEventListener
|
||||
|
||||
private final AtomicBoolean isCalled = new AtomicBoolean(false);
|
||||
|
||||
private SmsConfigProperties msConfigProperties;
|
||||
private SmsProperties msConfigProperties;
|
||||
|
||||
private ISmsService smsService;
|
||||
|
||||
public SmsInitializerEventListener(SmsConfigProperties msConfigProperties,
|
||||
public SmsInitializerEventListener(SmsProperties msConfigProperties,
|
||||
ISmsService smsService) {
|
||||
this.msConfigProperties = msConfigProperties;
|
||||
this.smsService = smsService;
|
||||
@@ -54,13 +54,13 @@ public class SmsInitializerEventListener
|
||||
// 整个application context refreshed then do
|
||||
// 可自助调整超时时间
|
||||
System.setProperty("sun.net.client.defaultConnectTimeout",
|
||||
msConfigProperties.getConnnectTimeout());
|
||||
msConfigProperties.getConnectTimeout());
|
||||
System.setProperty("sun.net.client.defaultReadTimeout",
|
||||
msConfigProperties.getReadTimeout());
|
||||
// 初始化acsClient,暂不支持region化
|
||||
try {
|
||||
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou",
|
||||
SmsConfigProperties.smsProduct, SmsConfigProperties.smsDomain);
|
||||
SmsProperties.smsProduct, SmsProperties.smsDomain);
|
||||
Collection<MessageListener> messageListeners = event.getApplicationContext()
|
||||
.getBeansOfType(MessageListener.class).values();
|
||||
if (messageListeners.isEmpty()) {
|
||||
|
@@ -15,17 +15,19 @@
|
||||
*/
|
||||
package org.springframework.cloud.alicloud.sms;
|
||||
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.*;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.exceptions.ServerException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsConfigProperties;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsProperties;
|
||||
import org.springframework.cloud.alicloud.sms.base.DefaultAlicomMessagePuller;
|
||||
import org.springframework.cloud.alicloud.sms.endpoint.EndpointManager;
|
||||
import org.springframework.cloud.alicloud.sms.endpoint.ReceiveMessageEntity;
|
||||
|
||||
import java.text.ParseException;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.*;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.exceptions.ServerException;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
@@ -38,17 +40,22 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @param sendSmsRequest
|
||||
* @return
|
||||
*/
|
||||
private SmsConfigProperties smsConfigProperties;
|
||||
private SmsProperties smsProperties;
|
||||
|
||||
public SmsServiceImpl(SmsConfigProperties smsConfigProperties) {
|
||||
this.smsConfigProperties = smsConfigProperties;
|
||||
private AliCloudProperties aliCloudProperties;
|
||||
|
||||
public SmsServiceImpl(AliCloudProperties aliCloudProperties,
|
||||
SmsProperties smsProperties) {
|
||||
this.aliCloudProperties = aliCloudProperties;
|
||||
this.smsProperties = smsProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest)
|
||||
throws ClientException {
|
||||
|
||||
return sendSmsRequest(sendSmsRequest, smsConfigProperties.getAccessKeyId(),
|
||||
smsConfigProperties.getAccessKeySecret());
|
||||
return sendSmsRequest(sendSmsRequest, aliCloudProperties.getAccessKey(),
|
||||
aliCloudProperties.getSecretKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +69,7 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @throws ClientException
|
||||
* @return SendSmsResponse
|
||||
*/
|
||||
@Override
|
||||
public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest,
|
||||
String accessKeyId, String accessKeySecret)
|
||||
throws ServerException, ClientException {
|
||||
@@ -76,10 +84,12 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @param smsReportMessageListener
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean startSmsReportMessageListener(
|
||||
SmsReportMessageListener smsReportMessageListener) {
|
||||
String messageType = "SmsReport";// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String queueName = smsConfigProperties.getReportQueueName();
|
||||
// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String messageType = "SmsReport";
|
||||
String queueName = smsProperties.getReportQueueName();
|
||||
return startReceiveMsg(messageType, queueName, smsReportMessageListener);
|
||||
}
|
||||
|
||||
@@ -88,9 +98,11 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @param smsUpMessageListener
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener) {
|
||||
String messageType = "SmsUp";// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String queueName = smsConfigProperties.getUpQueueName();
|
||||
// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String messageType = "SmsUp";
|
||||
String queueName = smsProperties.getUpQueueName();
|
||||
return startReceiveMsg(messageType, queueName, smsUpMessageListener);
|
||||
}
|
||||
|
||||
@@ -103,8 +115,8 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
*/
|
||||
private boolean startReceiveMsg(String messageType, String queueName,
|
||||
SmsMessageListener messageListener) {
|
||||
String accessKeyId = smsConfigProperties.getAccessKeyId();
|
||||
String accessKeySecret = smsConfigProperties.getAccessKeySecret();
|
||||
String accessKeyId = aliCloudProperties.getAccessKey();
|
||||
String accessKeySecret = aliCloudProperties.getSecretKey();
|
||||
boolean result = true;
|
||||
try {
|
||||
new DefaultAlicomMessagePuller().startReceiveMsg(accessKeyId, accessKeySecret,
|
||||
@@ -135,9 +147,8 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
SendBatchSmsRequest sendBatchSmsRequest)
|
||||
throws ServerException, ClientException {
|
||||
|
||||
return sendSmsBatchRequest(sendBatchSmsRequest,
|
||||
smsConfigProperties.getAccessKeyId(),
|
||||
smsConfigProperties.getAccessKeySecret());
|
||||
return sendSmsBatchRequest(sendBatchSmsRequest, aliCloudProperties.getAccessKey(),
|
||||
aliCloudProperties.getSecretKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,7 +192,7 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
@Override
|
||||
public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request)
|
||||
throws ClientException {
|
||||
return querySendDetails(request, smsConfigProperties.getAccessKeyId(),
|
||||
smsConfigProperties.getAccessKeySecret());
|
||||
return querySendDetails(request, aliCloudProperties.getAccessKey(),
|
||||
aliCloudProperties.getSecretKey());
|
||||
}
|
||||
}
|
@@ -18,7 +18,8 @@ package org.springframework.cloud.alicloud.sms.config;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsConfigProperties;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsProperties;
|
||||
import org.springframework.cloud.alicloud.sms.ISmsService;
|
||||
import org.springframework.cloud.alicloud.sms.SmsInitializerEventListener;
|
||||
import org.springframework.cloud.alicloud.sms.SmsServiceImpl;
|
||||
@@ -37,13 +38,14 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
||||
public class SmsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public SmsServiceImpl smsService(SmsConfigProperties smsConfigProperties) {
|
||||
return new SmsServiceImpl(smsConfigProperties);
|
||||
public SmsServiceImpl smsService(AliCloudProperties aliCloudProperties,
|
||||
SmsProperties smsProperties) {
|
||||
return new SmsServiceImpl(aliCloudProperties, smsProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SmsInitializerEventListener smsInitializePostListener(
|
||||
SmsConfigProperties msConfigProperties, ISmsService smsService) {
|
||||
return new SmsInitializerEventListener(msConfigProperties, smsService);
|
||||
SmsProperties smsProperties, ISmsService smsService) {
|
||||
return new SmsInitializerEventListener(smsProperties, smsService);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user