mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-07 01:18:33 +08:00
commit
528077a358
15
pom.xml
15
pom.xml
@ -169,15 +169,20 @@
|
|||||||
<artifactId>activation</artifactId>
|
<artifactId>activation</artifactId>
|
||||||
<version>${activation.version}</version>
|
<version>${activation.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- hutool 的依赖配置-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-bom</artifactId>
|
||||||
|
<version>${hutool.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-all</artifactId>
|
|
||||||
<version>${hutool.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import java.util.Objects;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SmsInvocationHandler implements InvocationHandler {
|
public class SmsInvocationHandler implements InvocationHandler {
|
||||||
private SmsBlend smsBlend;
|
private final SmsBlend smsBlend;
|
||||||
private SmsConfig config;
|
private final SmsConfig config;
|
||||||
private static RestrictedProcess restrictedProcess = new RestrictedProcess();
|
private static RestrictedProcess restrictedProcess = new RestrictedProcess();
|
||||||
|
|
||||||
private SmsInvocationHandler(SmsBlend smsBlend, SmsConfig config) {
|
private SmsInvocationHandler(SmsBlend smsBlend, SmsConfig config) {
|
||||||
@ -26,7 +26,7 @@ public class SmsInvocationHandler implements InvocationHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
|
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
|
||||||
Object result = null;
|
Object result;
|
||||||
if ("sendMessage".equals(method.getName()) || "massTexting".equals(method.getName())) {
|
if ("sendMessage".equals(method.getName()) || "massTexting".equals(method.getName())) {
|
||||||
//取手机号作为参数
|
//取手机号作为参数
|
||||||
String phone = (String) objects[0];
|
String phone = (String) objects[0];
|
||||||
|
|||||||
@ -19,5 +19,10 @@
|
|||||||
<groupId>com.dtflys.forest</groupId>
|
<groupId>com.dtflys.forest</groupId>
|
||||||
<artifactId>forest-core</artifactId>
|
<artifactId>forest-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-json</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package org.dromara.sms4j.comm.constant;
|
package org.dromara.sms4j.comm.constant;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant
|
* Constant
|
||||||
* <p> 短信应用常量
|
* <p> 短信应用常量
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package org.dromara.sms4j.comm.utils;
|
package org.dromara.sms4j.comm.utils;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||||
@ -27,8 +26,8 @@ public class TimeExpiredPoolCache {
|
|||||||
* 持久化文件格式
|
* 持久化文件格式
|
||||||
*/
|
*/
|
||||||
private static final String FILE_TYPE = "persistence.data";
|
private static final String FILE_TYPE = "persistence.data";
|
||||||
private static long defaultCachedMillis = 24 * 60 * 60 * 1000L;//过期时间默认24小时
|
private static final long defaultCachedMillis = 24 * 60 * 60 * 1000L;//过期时间默认24小时
|
||||||
private static long timerMillis = 30 * 1000L;//定时清理默认1分钟
|
private static final long timerMillis = 30 * 1000L;//定时清理默认1分钟
|
||||||
/**
|
/**
|
||||||
* 对象池
|
* 对象池
|
||||||
*/
|
*/
|
||||||
@ -40,7 +39,7 @@ public class TimeExpiredPoolCache {
|
|||||||
/**
|
/**
|
||||||
* 定时器定时清理过期缓存
|
* 定时器定时清理过期缓存
|
||||||
*/
|
*/
|
||||||
private static Timer timer = new Timer();
|
private static final Timer timer = new Timer();
|
||||||
|
|
||||||
private TimeExpiredPoolCache() {
|
private TimeExpiredPoolCache() {
|
||||||
}
|
}
|
||||||
@ -48,7 +47,7 @@ public class TimeExpiredPoolCache {
|
|||||||
private static synchronized void syncInit() {
|
private static synchronized void syncInit() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new TimeExpiredPoolCache();
|
instance = new TimeExpiredPoolCache();
|
||||||
dataPool = new ConcurrentHashMap<String, DataWrapper<?>>();
|
dataPool = new ConcurrentHashMap<>();
|
||||||
initTimer();
|
initTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,8 +69,8 @@ public class TimeExpiredPoolCache {
|
|||||||
if (dataPool != null) {
|
if (dataPool != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (IOException ignored) {
|
} catch (IOException e) {
|
||||||
log.error(ignored.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -101,7 +100,7 @@ public class TimeExpiredPoolCache {
|
|||||||
* 清除过期的缓存
|
* 清除过期的缓存
|
||||||
*/
|
*/
|
||||||
private static void clearExpiredCaches() {
|
private static void clearExpiredCaches() {
|
||||||
List<String> expiredKeyList = new LinkedList<String>();
|
List<String> expiredKeyList = new LinkedList<>();
|
||||||
|
|
||||||
for (Entry<String, DataWrapper<?>> entry : dataPool.entrySet()) {
|
for (Entry<String, DataWrapper<?>> entry : dataPool.entrySet()) {
|
||||||
if (entry.getValue().isExpired()) {
|
if (entry.getValue().isExpired()) {
|
||||||
@ -135,7 +134,7 @@ public class TimeExpiredPoolCache {
|
|||||||
//更新
|
//更新
|
||||||
dataWrapper.update(data, cachedMillis);
|
dataWrapper.update(data, cachedMillis);
|
||||||
} else {
|
} else {
|
||||||
dataWrapper = new DataWrapper<T>(data, cachedMillis);
|
dataWrapper = new DataWrapper<>(data, cachedMillis);
|
||||||
dataPool.put(key, dataWrapper);
|
dataPool.put(key, dataWrapper);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@ -210,7 +209,7 @@ public class TimeExpiredPoolCache {
|
|||||||
/**
|
/**
|
||||||
* 数据封装
|
* 数据封装
|
||||||
*/
|
*/
|
||||||
private class DataWrapper<T> {
|
private static class DataWrapper<T> {
|
||||||
/**
|
/**
|
||||||
* 数据
|
* 数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import java.util.Objects;
|
|||||||
**/
|
**/
|
||||||
public abstract class SmsFactory {
|
public abstract class SmsFactory {
|
||||||
|
|
||||||
private static Map<SupplierType, SmsBlend> beans = new HashMap<>();
|
private static final Map<SupplierType, SmsBlend> beans = new HashMap<>();
|
||||||
|
|
||||||
private SmsFactory() {
|
private SmsFactory() {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,5 +45,11 @@
|
|||||||
<groupId>javax.activation</groupId>
|
<groupId>javax.activation</groupId>
|
||||||
<artifactId>activation</artifactId>
|
<artifactId>activation</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-crypto</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -5,7 +5,6 @@ import org.dromara.sms4j.aliyun.service.AlibabaSmsImpl;
|
|||||||
import org.dromara.sms4j.comm.factory.BeanFactory;
|
import org.dromara.sms4j.comm.factory.BeanFactory;
|
||||||
import org.dromara.sms4j.provider.base.BaseProviderFactory;
|
import org.dromara.sms4j.provider.base.BaseProviderFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AlibabaSmsConfig
|
* AlibabaSmsConfig
|
||||||
* <p> 阿里巴巴对象建造者
|
* <p> 阿里巴巴对象建造者
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
* @author :Wind
|
* @author :Wind
|
||||||
* 2023/3/26 17:16
|
* 2023/3/26 17:16
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AlibabaSmsImpl extends AbstractSmsBlend {
|
public class AlibabaSmsImpl extends AbstractSmsBlend {
|
||||||
|
|
||||||
@ -86,12 +85,8 @@ public class AlibabaSmsImpl extends AbstractSmsBlend {
|
|||||||
super.http.post(requestUrl)
|
super.http.post(requestUrl)
|
||||||
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.addBody(paramStr)
|
.addBody(paramStr)
|
||||||
.onSuccess(((data, req, res) -> {
|
.onSuccess(((data, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class)))))
|
||||||
reference.set(this.getResponse(res.get(JSONObject.class)));
|
.onError((ex, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class))))
|
||||||
}))
|
|
||||||
.onError((ex, req, res) -> {
|
|
||||||
reference.set(this.getResponse(res.get(JSONObject.class)));
|
|
||||||
})
|
|
||||||
.execute();
|
.execute();
|
||||||
return reference.get();
|
return reference.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public class CloopenConfig extends BaseConfig implements SupplierConfig {
|
|||||||
* Rest URL 域名
|
* Rest URL 域名
|
||||||
*
|
*
|
||||||
* @deprecated v2.0.1
|
* @deprecated v2.0.1
|
||||||
* @see baseUrl
|
* @see #baseUrl
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private String serverIp;
|
private String serverIp;
|
||||||
@ -44,7 +44,7 @@ public class CloopenConfig extends BaseConfig implements SupplierConfig {
|
|||||||
* Rest URL 端口
|
* Rest URL 端口
|
||||||
*
|
*
|
||||||
* @deprecated v2.0.1
|
* @deprecated v2.0.1
|
||||||
* @see baseUrl
|
* @see #baseUrl
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private String serverPort;
|
private String serverPort;
|
||||||
|
|||||||
@ -29,7 +29,6 @@ public class CtyunSmsImpl extends AbstractSmsBlend {
|
|||||||
|
|
||||||
private final CtyunConfig ctyunConfig;
|
private final CtyunConfig ctyunConfig;
|
||||||
|
|
||||||
|
|
||||||
public CtyunSmsImpl(CtyunConfig ctyunConfig, Executor pool, DelayedTime delayedTime) {
|
public CtyunSmsImpl(CtyunConfig ctyunConfig, Executor pool, DelayedTime delayedTime) {
|
||||||
super(pool, delayedTime);
|
super(pool, delayedTime);
|
||||||
this.ctyunConfig = ctyunConfig;
|
this.ctyunConfig = ctyunConfig;
|
||||||
@ -80,12 +79,8 @@ public class CtyunSmsImpl extends AbstractSmsBlend {
|
|||||||
http.post(requestUrl)
|
http.post(requestUrl)
|
||||||
.addHeader(CtyunUtils.signHeader(paramStr, ctyunConfig.getAccessKeyId(), ctyunConfig.getAccessKeySecret()))
|
.addHeader(CtyunUtils.signHeader(paramStr, ctyunConfig.getAccessKeyId(), ctyunConfig.getAccessKeySecret()))
|
||||||
.addBody(paramStr)
|
.addBody(paramStr)
|
||||||
.onSuccess(((data, req, res) -> {
|
.onSuccess(((data, req, res) -> smsResponse.set(this.getResponse(res.get(JSONObject.class)))))
|
||||||
smsResponse.set(this.getResponse(res.get(JSONObject.class)));
|
.onError((ex, req, res) -> smsResponse.set(this.getResponse(res.get(JSONObject.class))))
|
||||||
}))
|
|
||||||
.onError((ex, req, res) -> {
|
|
||||||
smsResponse.set(this.getResponse(res.get(JSONObject.class)));
|
|
||||||
})
|
|
||||||
.execute();
|
.execute();
|
||||||
return smsResponse.get();
|
return smsResponse.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package org.dromara.sms4j.ctyun.utils;
|
package org.dromara.sms4j.ctyun.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.crypto.digest.HMac;
|
import cn.hutool.crypto.digest.HMac;
|
||||||
import cn.hutool.crypto.digest.HmacAlgorithm;
|
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
@ -12,7 +13,6 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -56,7 +56,7 @@ public class CtyunUtils {
|
|||||||
// 报文原封不动进行sha256摘要
|
// 报文原封不动进行sha256摘要
|
||||||
String signatureStr = String.format("ctyun-eop-request-id:%s\neop-date:%s\n", uuid, signatureTime) + "\n\n" + calculateContentHash;
|
String signatureStr = String.format("ctyun-eop-request-id:%s\neop-date:%s\n", uuid, signatureTime) + "\n\n" + calculateContentHash;
|
||||||
// 构造签名
|
// 构造签名
|
||||||
String signature = Base64.getEncoder().encodeToString(hmacSHA256(signatureStr.getBytes(StandardCharsets.UTF_8), kDate));
|
String signature = Base64.encode(hmacSHA256(signatureStr.getBytes(StandardCharsets.UTF_8), kDate));
|
||||||
String signHeader = String.format("%s Headers=ctyun-eop-request-id;eop-date Signature=%s", key, signature);
|
String signHeader = String.format("%s Headers=ctyun-eop-request-id;eop-date Signature=%s", key, signature);
|
||||||
map.put("Content-Type", "application/json;charset=UTF-8");
|
map.put("Content-Type", "application/json;charset=UTF-8");
|
||||||
map.put("ctyun-eop-request-id", uuid);
|
map.put("ctyun-eop-request-id", uuid);
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Richard
|
* @author Richard
|
||||||
* @date 2023-04-11 12:00
|
* @date 2023-04-11 12:00
|
||||||
@ -31,7 +30,7 @@ public class EmaySmsImpl extends AbstractSmsBlend {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmayConfig config;
|
private final EmayConfig config;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Restricted
|
@Restricted
|
||||||
@ -84,20 +83,13 @@ public class EmaySmsImpl extends AbstractSmsBlend {
|
|||||||
AtomicReference<SmsResponse> smsResponse = new AtomicReference<>();
|
AtomicReference<SmsResponse> smsResponse = new AtomicReference<>();
|
||||||
http.post(requestUrl)
|
http.post(requestUrl)
|
||||||
.addBody(body)
|
.addBody(body)
|
||||||
.onSuccess(((data, req, res) -> {
|
.onSuccess(((data, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class)))))
|
||||||
JSONObject jsonBody = res.get(JSONObject.class);
|
.onError((ex, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class))))
|
||||||
smsResponse.set(getSmsResponse(jsonBody));
|
|
||||||
}))
|
|
||||||
.onError((ex, req, res) -> {
|
|
||||||
JSONObject jsonBody = res.get(JSONObject.class);
|
|
||||||
smsResponse.set(getSmsResponse(jsonBody));
|
|
||||||
})
|
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
return smsResponse.get();
|
return smsResponse.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static SmsResponse getSmsResponse(JSONObject execute) {
|
private static SmsResponse getSmsResponse(JSONObject execute) {
|
||||||
SmsResponse smsResponse = new SmsResponse();
|
SmsResponse smsResponse = new SmsResponse();
|
||||||
if (execute == null) {
|
if (execute == null) {
|
||||||
|
|||||||
@ -20,13 +20,11 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class EmayBuilder {
|
public class EmayBuilder {
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, Object> buildRequestBody(String appId, String secretKey, String phone,
|
public static Map<String, Object> buildRequestBody(String appId, String secretKey, String phone,
|
||||||
String message) throws SmsBlendException {
|
String message) throws SmsBlendException {
|
||||||
return getParamsMap(appId, secretKey, phone, message);
|
return getParamsMap(appId, secretKey, phone, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param appId 用户Appid(必填)
|
* @param appId 用户Appid(必填)
|
||||||
* @param secretKey 加密key
|
* @param secretKey 加密key
|
||||||
|
|||||||
@ -27,5 +27,4 @@ public class SmsId {
|
|||||||
/** 短信资源的创建时间,即短信平台接收到用户发送短信请求的时间,为UTC时间*/
|
/** 短信资源的创建时间,即短信平台接收到用户发送短信请求的时间,为UTC时间*/
|
||||||
private String createTime;
|
private String createTime;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
import static org.dromara.sms4j.huawei.utils.HuaweiBuilder.listToString;
|
import static org.dromara.sms4j.huawei.utils.HuaweiBuilder.listToString;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HuaweiSmsImpl extends AbstractSmsBlend {
|
public class HuaweiSmsImpl extends AbstractSmsBlend {
|
||||||
public HuaweiSmsImpl(HuaweiConfig config, Executor pool, DelayedTime delayed) {
|
public HuaweiSmsImpl(HuaweiConfig config, Executor pool, DelayedTime delayed) {
|
||||||
@ -27,7 +26,7 @@ public class HuaweiSmsImpl extends AbstractSmsBlend {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HuaweiConfig config;
|
private final HuaweiConfig config;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Restricted
|
@Restricted
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package org.dromara.sms4j.huawei.utils;
|
package org.dromara.sms4j.huawei.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
import org.dromara.sms4j.comm.constant.Constant;
|
import org.dromara.sms4j.comm.constant.Constant;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
@ -10,11 +11,9 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -47,7 +46,7 @@ public class HuaweiBuilder {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
String passwordDigestBase64Str = Base64.getEncoder().encodeToString(passwordDigest); //PasswordDigest
|
String passwordDigestBase64Str = Base64.encode(passwordDigest); //PasswordDigest
|
||||||
//若passwordDigestBase64Str中包含换行符,请执行如下代码进行修正
|
//若passwordDigestBase64Str中包含换行符,请执行如下代码进行修正
|
||||||
//passwordDigestBase64Str = passwordDigestBase64Str.replaceAll("[\\s*\t\n\r]", "");
|
//passwordDigestBase64Str = passwordDigestBase64Str.replaceAll("[\\s*\t\n\r]", "");
|
||||||
return String.format(Constant.HUAWEI_WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time);
|
return String.format(Constant.HUAWEI_WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time);
|
||||||
@ -56,11 +55,9 @@ public class HuaweiBuilder {
|
|||||||
static void trustAllHttpsCertificates() throws Exception {
|
static void trustAllHttpsCertificates() throws Exception {
|
||||||
TrustManager[] trustAllCerts = new TrustManager[] {
|
TrustManager[] trustAllCerts = new TrustManager[] {
|
||||||
new X509TrustManager() {
|
new X509TrustManager() {
|
||||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
public void checkServerTrusted(X509Certificate[] chain, String authType) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
return null;
|
return null;
|
||||||
@ -75,11 +72,11 @@ public class HuaweiBuilder {
|
|||||||
/**
|
/**
|
||||||
* buildRequestBody
|
* buildRequestBody
|
||||||
* <p>构造请求Body体
|
* <p>构造请求Body体
|
||||||
* @param sender
|
* @param sender 国内短信签名通道号
|
||||||
* @param receiver
|
* @param receiver 短信接收者
|
||||||
* @param templateId
|
* @param templateId 短信模板id
|
||||||
* @param templateParas
|
* @param templateParas 模板参数
|
||||||
* @param statusCallBack
|
* @param statusCallBack 短信状态报告接收地
|
||||||
* @param signature | 签名名称,使用国内短信通用模板时填写
|
* @param signature | 签名名称,使用国内短信通用模板时填写
|
||||||
* @author :Wind
|
* @author :Wind
|
||||||
*/
|
*/
|
||||||
@ -135,16 +132,16 @@ public class HuaweiBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String dateFormat(Date date){
|
static String dateFormat(Date date){
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(Constant.HUAWEI_JAVA_DATE);
|
return SDF.format(date);
|
||||||
return sdf.format(date);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Date strForDate(String date){
|
static Date strForDate(String date){
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(Constant.HUAWEI_JAVA_DATE);
|
|
||||||
try {
|
try {
|
||||||
return sdf.parse(date);
|
return SDF.parse(date);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final SimpleDateFormat SDF = new SimpleDateFormat(Constant.HUAWEI_JAVA_DATE);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import java.util.concurrent.Executor;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class TencentSmsImpl extends AbstractSmsBlend {
|
public class TencentSmsImpl extends AbstractSmsBlend {
|
||||||
|
|
||||||
private TencentConfig tencentSmsConfig;
|
private final TencentConfig tencentSmsConfig;
|
||||||
|
|
||||||
public TencentSmsImpl(TencentConfig tencentSmsConfig, Executor pool, DelayedTime delayed) {
|
public TencentSmsImpl(TencentConfig tencentSmsConfig, Executor pool, DelayedTime delayed) {
|
||||||
super(pool, delayed);
|
super(pool, delayed);
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
package org.dromara.sms4j.tencent.utils;
|
package org.dromara.sms4j.tencent.utils;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.HMac;
|
||||||
|
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.sms4j.tencent.config.TencentConfig;
|
import org.dromara.sms4j.tencent.config.TencentConfig;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@ -34,11 +34,9 @@ public class TencentUtils {
|
|||||||
private static final String CT_JSON = "application/json; charset=utf-8";
|
private static final String CT_JSON = "application/json; charset=utf-8";
|
||||||
|
|
||||||
|
|
||||||
private static byte[] hmac256(byte[] key, String msg) throws Exception {
|
private static byte[] hmac256(byte[] key, String msg) {
|
||||||
Mac mac = Mac.getInstance("HmacSHA256");
|
HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, key);
|
||||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key, mac.getAlgorithm());
|
return hMac.digest(msg.getBytes(StandardCharsets.UTF_8));
|
||||||
mac.init(secretKeySpec);
|
|
||||||
return mac.doFinal(msg.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String sha256Hex(String s) throws Exception {
|
private static String sha256Hex(String s) throws Exception {
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
package org.dromara.sms4j.unisms.core;
|
package org.dromara.sms4j.unisms.core;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
|
import cn.hutool.crypto.digest.HMac;
|
||||||
|
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.dtflys.forest.config.ForestConfiguration;
|
import com.dtflys.forest.config.ForestConfiguration;
|
||||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||||
import org.dromara.sms4j.comm.factory.BeanFactory;
|
import org.dromara.sms4j.comm.factory.BeanFactory;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -36,12 +36,9 @@ public class UniClient {
|
|||||||
|
|
||||||
private static String getSignature(final String message, final String secretKey) {
|
private static String getSignature(final String message, final String secretKey) {
|
||||||
try {
|
try {
|
||||||
Mac hmac = Mac.getInstance("HmacSHA256");
|
HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, secretKey.getBytes());
|
||||||
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
|
byte[] bytes = hMac.digest(message.getBytes());
|
||||||
hmac.init(secretKeySpec);
|
return Base64.encode(bytes);
|
||||||
|
|
||||||
byte[] bytes = hmac.doFinal(message.getBytes());
|
|
||||||
return Base64.getEncoder().encodeToString(bytes);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import org.dromara.sms4j.comm.exception.SmsBlendException;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
public class UniResponse {
|
public class UniResponse {
|
||||||
public static final String REQUEST_ID_HEADER_KEY = "x-uni-request-id";
|
public static final String REQUEST_ID_HEADER_KEY = "x-uni-request-id";
|
||||||
public String requestId;
|
public String requestId;
|
||||||
|
|||||||
@ -17,18 +17,16 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>类名: UniSmsImpl
|
* <p>类名: UniSmsImpl
|
||||||
* <p>说明: uniSms短信实现
|
* <p>说明: uniSms短信实现
|
||||||
* @author :Wind
|
* @author :Wind
|
||||||
* 2023/3/26 17:10
|
* 2023/3/26 17:10
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UniSmsImpl extends AbstractSmsBlend {
|
public class UniSmsImpl extends AbstractSmsBlend {
|
||||||
|
|
||||||
private UniConfig config;
|
private final UniConfig config;
|
||||||
|
|
||||||
public UniSmsImpl(UniConfig config, Executor pool, DelayedTime delayed) {
|
public UniSmsImpl(UniConfig config, Executor pool, DelayedTime delayed) {
|
||||||
super(pool,delayed);
|
super(pool,delayed);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public class YunPianSmsImpl extends AbstractSmsBlend {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private YunpianConfig config;
|
private final YunpianConfig config;
|
||||||
|
|
||||||
private static SmsResponse getSmsResponse(JSONObject execute) {
|
private static SmsResponse getSmsResponse(JSONObject execute) {
|
||||||
SmsResponse smsResponse = new SmsResponse();
|
SmsResponse smsResponse = new SmsResponse();
|
||||||
@ -121,14 +121,8 @@ public class YunPianSmsImpl extends AbstractSmsBlend {
|
|||||||
http.post(Constant.YUNPIAN_URL + "/sms/tpl_single_send.json")
|
http.post(Constant.YUNPIAN_URL + "/sms/tpl_single_send.json")
|
||||||
.addHeader(headers)
|
.addHeader(headers)
|
||||||
.addBody(body)
|
.addBody(body)
|
||||||
.onSuccess(((data, req, res) -> {
|
.onSuccess(((data, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class)))))
|
||||||
JSONObject jsonBody = res.get(JSONObject.class);
|
.onError((ex, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class))))
|
||||||
smsResponse.set(getSmsResponse(jsonBody));
|
|
||||||
}))
|
|
||||||
.onError((ex, req, res) -> {
|
|
||||||
JSONObject jsonBody = res.get(JSONObject.class);
|
|
||||||
smsResponse.set(getSmsResponse(jsonBody));
|
|
||||||
})
|
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
return smsResponse.get();
|
return smsResponse.get();
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import org.noear.solon.core.Plugin;
|
|||||||
*/
|
*/
|
||||||
public class XPluginImpl implements Plugin {
|
public class XPluginImpl implements Plugin {
|
||||||
@Override
|
@Override
|
||||||
public void start(AopContext context) throws Throwable {
|
public void start(AopContext context) {
|
||||||
context.beanMake(SmsAutowiredConfig.class);
|
context.beanMake(SmsAutowiredConfig.class);
|
||||||
SmsAutowiredConfig.aopContext = context;
|
SmsAutowiredConfig.aopContext = context;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class SolonRestrictedProcess extends RestrictedProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SmsBlendException process(SmsConfig config, String args) throws Exception {
|
public SmsBlendException process(SmsConfig config, String args) {
|
||||||
Integer accountMax = config.getAccountMax();//每日最大发送量
|
Integer accountMax = config.getAccountMax();//每日最大发送量
|
||||||
Integer minuteMax = config.getMinuteMax();//每分钟最大发送量
|
Integer minuteMax = config.getMinuteMax();//每分钟最大发送量
|
||||||
if (SmsUtil.isNotEmpty(accountMax)) { //是否配置了每日限制
|
if (SmsUtil.isNotEmpty(accountMax)) { //是否配置了每日限制
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import org.noear.solon.core.Props;
|
|||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SmsAutowiredConfig {
|
public class SmsAutowiredConfig {
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RedisUtils {
|
public class RedisUtils {
|
||||||
|
|
||||||
@ -97,9 +96,7 @@ public class RedisUtils {
|
|||||||
*/
|
*/
|
||||||
public boolean multiSet(Map valueMap) {
|
public boolean multiSet(Map valueMap) {
|
||||||
try {
|
try {
|
||||||
valueMap.forEach((key, val) -> {
|
valueMap.forEach((key, val) -> redisTemplate.getBucket((String) key).set(val));
|
||||||
redisTemplate.getBucket((String) key).set(val);
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.toString());
|
log.error(e.toString());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user