优化代码
This commit is contained in:
parent
29cfc30459
commit
a40c0e273d
|
@ -18,7 +18,7 @@ public enum SmsPlatformEnum {
|
|||
/**
|
||||
* 腾讯云
|
||||
*/
|
||||
QCLOUD(1),
|
||||
TENCENT(1),
|
||||
/**
|
||||
* 七牛云
|
||||
*/
|
||||
|
|
|
@ -17,8 +17,8 @@ public class SmsContext {
|
|||
public SmsContext(SmsConfig config) {
|
||||
if (config.getPlatform() == SmsPlatformEnum.ALIYUN.getValue()) {
|
||||
this.smsStrategy = new AliyunSmsStrategy(config);
|
||||
} else if (config.getPlatform() == SmsPlatformEnum.QCLOUD.getValue()) {
|
||||
this.smsStrategy = new QcloudSmsStrategy(config);
|
||||
} else if (config.getPlatform() == SmsPlatformEnum.TENCENT.getValue()) {
|
||||
this.smsStrategy = new TencentSmsStrategy(config);
|
||||
} else if (config.getPlatform() == SmsPlatformEnum.QINIU.getValue()) {
|
||||
this.smsStrategy = new QiniuSmsStrategy(config);
|
||||
} else if (config.getPlatform() == SmsPlatformEnum.HUAWEI.getValue()) {
|
||||
|
|
|
@ -5,8 +5,8 @@ import com.tencentcloudapi.common.Credential;
|
|||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
||||
import net.maku.framework.common.constant.Constant;
|
||||
import net.maku.framework.common.exception.FastException;
|
||||
|
@ -19,11 +19,11 @@ import java.util.Map;
|
|||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
public class QcloudSmsStrategy implements SmsStrategy {
|
||||
public class TencentSmsStrategy implements SmsStrategy {
|
||||
private final SmsConfig smsConfig;
|
||||
private SmsClient client;
|
||||
|
||||
public QcloudSmsStrategy(SmsConfig smsConfig){
|
||||
public TencentSmsStrategy(SmsConfig smsConfig) {
|
||||
this.smsConfig = smsConfig;
|
||||
|
||||
try {
|
||||
|
@ -36,7 +36,7 @@ public class QcloudSmsStrategy implements SmsStrategy {
|
|||
|
||||
Credential cred = new Credential(smsConfig.getAccessKey(), smsConfig.getSecretKey());
|
||||
this.client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -49,12 +49,12 @@ public class QcloudSmsStrategy implements SmsStrategy {
|
|||
request.setTemplateId(smsConfig.getTemplateId());
|
||||
|
||||
// 有参数则设置
|
||||
if(MapUtil.isNotEmpty(params)){
|
||||
if (MapUtil.isNotEmpty(params)) {
|
||||
request.setTemplateParamSet(params.values().toArray(new String[0]));
|
||||
}
|
||||
|
||||
// 手机号
|
||||
String[] phoneNumberSet = { "+86" + mobile };
|
||||
String[] phoneNumberSet = {"+86" + mobile};
|
||||
request.setPhoneNumberSet(phoneNumberSet);
|
||||
|
||||
// 国际、港澳台短信,需要添加SenderId,国内短信填空,默认未开通
|
||||
|
@ -66,7 +66,7 @@ public class QcloudSmsStrategy implements SmsStrategy {
|
|||
SendStatus sendStatus = response.getSendStatusSet()[0];
|
||||
|
||||
// 发送失败
|
||||
if(!Constant.OK.equalsIgnoreCase(sendStatus.getCode())) {
|
||||
if (!Constant.OK.equalsIgnoreCase(sendStatus.getCode())) {
|
||||
throw new FastException(sendStatus.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
Loading…
Reference in New Issue
Block a user