From f995f031b4982391999819a76d7628df83ef4f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Wed, 24 Aug 2022 11:02:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9F=AD=E4=BF=A1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/net/maku/message/sms/AliyunSmsStrategy.java | 12 +++++++----- .../main/java/net/maku/message/sms/HuaweiSmsStrategy.java | 7 ++----- .../src/main/java/net/maku/message/sms/QiniuSmsStrategy.java | 2 +- .../main/java/net/maku/message/sms/TencentSmsStrategy.java | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java index a87d6c3..e3b95bd 100644 --- a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java +++ b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/AliyunSmsStrategy.java @@ -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; @@ -43,7 +45,7 @@ public class AliyunSmsStrategy implements SmsStrategy { request.setTemplateCode(smsConfig.getTemplateId()); request.setPhoneNumbers(mobile); // request.setTemplateParam("{\"code\":\"1234\"}"); - if(MapUtil.isNotEmpty(params)){ + if (MapUtil.isNotEmpty(params)) { request.setTemplateParam(JsonUtils.toJsonString(params)); } @@ -52,11 +54,11 @@ public class AliyunSmsStrategy implements SmsStrategy { SendSmsResponse response = client.sendSms(request); // 发送失败 - if(!Constant.OK.equalsIgnoreCase(response.getBody().getCode())) { + if (!Constant.OK.equalsIgnoreCase(response.getBody().getCode())) { throw new FastException(response.getBody().getMessage()); } } catch (Exception e) { - throw new FastException("短信发送失败:", e); + throw new FastException(e.getMessage()); } } } diff --git a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java index 7894408..2f22ae4 100644 --- a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java +++ b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/HuaweiSmsStrategy.java @@ -38,9 +38,6 @@ public class HuaweiSmsStrategy implements SmsStrategy { @Override public void send(String mobile, Map 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()); } } diff --git a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java index 736fdc6..a71a0a2 100644 --- a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java +++ b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java @@ -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()); } } } diff --git a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java index a91b933..9434693 100644 --- a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java +++ b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/TencentSmsStrategy.java @@ -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()); } } }