优化短信代码
This commit is contained in:
parent
6a63833611
commit
f995f031b4
|
@ -2,8 +2,9 @@ package net.maku.message.sms;
|
|||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.aliyun.dysmsapi20170525.models.*;
|
||||
import com.aliyun.teaopenapi.models.*;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.maku.framework.common.constant.Constant;
|
||||
import net.maku.framework.common.exception.FastException;
|
||||
|
@ -21,6 +22,7 @@ import java.util.Map;
|
|||
public class AliyunSmsStrategy implements SmsStrategy {
|
||||
private final Client client;
|
||||
private final SmsConfig smsConfig;
|
||||
|
||||
public AliyunSmsStrategy(SmsConfig smsConfig) {
|
||||
this.smsConfig = smsConfig;
|
||||
|
||||
|
@ -56,7 +58,7 @@ public class AliyunSmsStrategy implements SmsStrategy {
|
|||
throw new FastException(response.getBody().getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FastException("短信发送失败:", e);
|
||||
throw new FastException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,9 +38,6 @@ public class HuaweiSmsStrategy implements SmsStrategy {
|
|||
|
||||
@Override
|
||||
public void send(String mobile, Map<String, String> params) {
|
||||
// APP接入地址(在控制台"应用管理"页面获取)+接口访问URI
|
||||
String url = "https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1";
|
||||
|
||||
// 有参数则设置
|
||||
String templateParas = null;
|
||||
if (MapUtil.isNotEmpty(params)) {
|
||||
|
@ -63,7 +60,7 @@ public class HuaweiSmsStrategy implements SmsStrategy {
|
|||
// 使用 https
|
||||
trustAllHttpsCertificates();
|
||||
|
||||
URL realUrl = new URL(url);
|
||||
URL realUrl = new URL(smsConfig.getUrl());
|
||||
HttpsURLConnection connection = (HttpsURLConnection) realUrl.openConnection();
|
||||
HostnameVerifier hv = (hostname, session) -> true;
|
||||
connection.setHostnameVerifier(hv);
|
||||
|
@ -92,7 +89,7 @@ public class HuaweiSmsStrategy implements SmsStrategy {
|
|||
throw new FastException(IoUtil.read(connection.getErrorStream(), CharsetUtil.CHARSET_UTF_8));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FastException("短信发送失败:", e);
|
||||
throw new FastException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class QiniuSmsStrategy implements SmsStrategy {
|
|||
throw new FastException(response.error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FastException("短信发送失败:", e);
|
||||
throw new FastException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class TencentSmsStrategy implements SmsStrategy {
|
|||
throw new FastException(sendStatus.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FastException("短信发送失败:", e);
|
||||
throw new FastException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user