!52 update 优化 正确使用注释中实现链接跳转

update 优化 正确使用注释中实现链接跳转
This commit is contained in:
风如歌 2023-05-31 09:38:57 +00:00 committed by Gitee
commit 528077a358
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
27 changed files with 78 additions and 108 deletions

15
pom.xml
View File

@ -169,15 +169,20 @@
<artifactId>activation</artifactId>
<version>${activation.version}</version>
</dependency>
<!-- hutool 的依赖配置-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-bom</artifactId>
<version>${hutool.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>

View File

@ -11,8 +11,8 @@ import java.util.Objects;
@Slf4j
public class SmsInvocationHandler implements InvocationHandler {
private SmsBlend smsBlend;
private SmsConfig config;
private final SmsBlend smsBlend;
private final SmsConfig config;
private static RestrictedProcess restrictedProcess = new RestrictedProcess();
private SmsInvocationHandler(SmsBlend smsBlend, SmsConfig config) {
@ -26,7 +26,7 @@ public class SmsInvocationHandler implements InvocationHandler {
@Override
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())) {
//取手机号作为参数
String phone = (String) objects[0];

View File

@ -19,5 +19,10 @@
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-core</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-json</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,5 @@
package org.dromara.sms4j.comm.constant;
/**
* Constant
* <p> 短信应用常量

View File

@ -1,6 +1,5 @@
package org.dromara.sms4j.comm.utils;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.comm.exception.SmsBlendException;
@ -27,8 +26,8 @@ public class TimeExpiredPoolCache {
* 持久化文件格式
*/
private static final String FILE_TYPE = "persistence.data";
private static long defaultCachedMillis = 24 * 60 * 60 * 1000L;//过期时间默认24小时
private static long timerMillis = 30 * 1000L;//定时清理默认1分钟
private static final long defaultCachedMillis = 24 * 60 * 60 * 1000L;//过期时间默认24小时
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() {
}
@ -48,7 +47,7 @@ public class TimeExpiredPoolCache {
private static synchronized void syncInit() {
if (instance == null) {
instance = new TimeExpiredPoolCache();
dataPool = new ConcurrentHashMap<String, DataWrapper<?>>();
dataPool = new ConcurrentHashMap<>();
initTimer();
}
}
@ -70,8 +69,8 @@ public class TimeExpiredPoolCache {
if (dataPool != null) {
return true;
}
} catch (IOException ignored) {
log.error(ignored.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
return false;
}
@ -101,7 +100,7 @@ public class TimeExpiredPoolCache {
* 清除过期的缓存
*/
private static void clearExpiredCaches() {
List<String> expiredKeyList = new LinkedList<String>();
List<String> expiredKeyList = new LinkedList<>();
for (Entry<String, DataWrapper<?>> entry : dataPool.entrySet()) {
if (entry.getValue().isExpired()) {
@ -135,7 +134,7 @@ public class TimeExpiredPoolCache {
//更新
dataWrapper.update(data, cachedMillis);
} else {
dataWrapper = new DataWrapper<T>(data, cachedMillis);
dataWrapper = new DataWrapper<>(data, cachedMillis);
dataPool.put(key, dataWrapper);
}
return data;
@ -210,7 +209,7 @@ public class TimeExpiredPoolCache {
/**
* 数据封装
*/
private class DataWrapper<T> {
private static class DataWrapper<T> {
/**
* 数据
*/

View File

@ -24,7 +24,7 @@ import java.util.Objects;
**/
public abstract class SmsFactory {
private static Map<SupplierType, SmsBlend> beans = new HashMap<>();
private static final Map<SupplierType, SmsBlend> beans = new HashMap<>();
private SmsFactory() {
}

View File

@ -45,5 +45,11 @@
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-crypto</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -5,7 +5,6 @@ import org.dromara.sms4j.aliyun.service.AlibabaSmsImpl;
import org.dromara.sms4j.comm.factory.BeanFactory;
import org.dromara.sms4j.provider.base.BaseProviderFactory;
/**
* AlibabaSmsConfig
* <p> 阿里巴巴对象建造者

View File

@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicReference;
* @author :Wind
* 2023/3/26 17:16
**/
@Slf4j
public class AlibabaSmsImpl extends AbstractSmsBlend {
@ -86,12 +85,8 @@ public class AlibabaSmsImpl extends AbstractSmsBlend {
super.http.post(requestUrl)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addBody(paramStr)
.onSuccess(((data, req, res) -> {
reference.set(this.getResponse(res.get(JSONObject.class)));
}))
.onError((ex, req, res) -> {
reference.set(this.getResponse(res.get(JSONObject.class)));
})
.onSuccess(((data, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class)))))
.onError((ex, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class))))
.execute();
return reference.get();
}

View File

@ -35,7 +35,7 @@ public class CloopenConfig extends BaseConfig implements SupplierConfig {
* Rest URL 域名
*
* @deprecated v2.0.1
* @see baseUrl
* @see #baseUrl
*/
@Deprecated
private String serverIp;
@ -44,7 +44,7 @@ public class CloopenConfig extends BaseConfig implements SupplierConfig {
* Rest URL 端口
*
* @deprecated v2.0.1
* @see baseUrl
* @see #baseUrl
*/
@Deprecated
private String serverPort;

View File

@ -29,7 +29,6 @@ public class CtyunSmsImpl extends AbstractSmsBlend {
private final CtyunConfig ctyunConfig;
public CtyunSmsImpl(CtyunConfig ctyunConfig, Executor pool, DelayedTime delayedTime) {
super(pool, delayedTime);
this.ctyunConfig = ctyunConfig;
@ -80,12 +79,8 @@ public class CtyunSmsImpl extends AbstractSmsBlend {
http.post(requestUrl)
.addHeader(CtyunUtils.signHeader(paramStr, ctyunConfig.getAccessKeyId(), ctyunConfig.getAccessKeySecret()))
.addBody(paramStr)
.onSuccess(((data, req, res) -> {
smsResponse.set(this.getResponse(res.get(JSONObject.class)));
}))
.onError((ex, req, res) -> {
smsResponse.set(this.getResponse(res.get(JSONObject.class)));
})
.onSuccess(((data, req, res) -> smsResponse.set(this.getResponse(res.get(JSONObject.class)))))
.onError((ex, req, res) -> smsResponse.set(this.getResponse(res.get(JSONObject.class))))
.execute();
return smsResponse.get();
}

View File

@ -1,5 +1,6 @@
package org.dromara.sms4j.ctyun.utils;
import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.digest.HMac;
import cn.hutool.crypto.digest.HmacAlgorithm;
import cn.hutool.json.JSONUtil;
@ -12,7 +13,6 @@ import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
@ -56,7 +56,7 @@ public class CtyunUtils {
// 报文原封不动进行sha256摘要
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);
map.put("Content-Type", "application/json;charset=UTF-8");
map.put("ctyun-eop-request-id", uuid);

View File

@ -19,7 +19,6 @@ import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author Richard
* @date 2023-04-11 12:00
@ -31,7 +30,7 @@ public class EmaySmsImpl extends AbstractSmsBlend {
this.config = config;
}
private EmayConfig config;
private final EmayConfig config;
@Override
@Restricted
@ -84,20 +83,13 @@ public class EmaySmsImpl extends AbstractSmsBlend {
AtomicReference<SmsResponse> smsResponse = new AtomicReference<>();
http.post(requestUrl)
.addBody(body)
.onSuccess(((data, req, res) -> {
JSONObject jsonBody = res.get(JSONObject.class);
smsResponse.set(getSmsResponse(jsonBody));
}))
.onError((ex, req, res) -> {
JSONObject jsonBody = res.get(JSONObject.class);
smsResponse.set(getSmsResponse(jsonBody));
})
.onSuccess(((data, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class)))))
.onError((ex, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class))))
.execute();
return smsResponse.get();
}
private static SmsResponse getSmsResponse(JSONObject execute) {
SmsResponse smsResponse = new SmsResponse();
if (execute == null) {

View File

@ -20,13 +20,11 @@ import java.util.Map;
@Slf4j
public class EmayBuilder {
public static Map<String, Object> buildRequestBody(String appId, String secretKey, String phone,
String message) throws SmsBlendException {
return getParamsMap(appId, secretKey, phone, message);
}
/**
* @param appId 用户Appid(必填)
* @param secretKey 加密key

View File

@ -27,5 +27,4 @@ public class SmsId {
/** 短信资源的创建时间即短信平台接收到用户发送短信请求的时间为UTC时间*/
private String createTime;
}

View File

@ -19,7 +19,6 @@ import java.util.concurrent.Executor;
import static org.dromara.sms4j.huawei.utils.HuaweiBuilder.listToString;
@Slf4j
public class HuaweiSmsImpl extends AbstractSmsBlend {
public HuaweiSmsImpl(HuaweiConfig config, Executor pool, DelayedTime delayed) {
@ -27,7 +26,7 @@ public class HuaweiSmsImpl extends AbstractSmsBlend {
this.config = config;
}
private HuaweiConfig config;
private final HuaweiConfig config;
@Override
@Restricted

View File

@ -1,5 +1,6 @@
package org.dromara.sms4j.huawei.utils;
import cn.hutool.core.codec.Base64;
import org.dromara.sms4j.comm.constant.Constant;
import javax.net.ssl.HttpsURLConnection;
@ -10,11 +11,9 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -47,7 +46,7 @@ public class HuaweiBuilder {
e.printStackTrace();
}
String passwordDigestBase64Str = Base64.getEncoder().encodeToString(passwordDigest); //PasswordDigest
String passwordDigestBase64Str = Base64.encode(passwordDigest); //PasswordDigest
//若passwordDigestBase64Str中包含换行符,请执行如下代码进行修正
//passwordDigestBase64Str = passwordDigestBase64Str.replaceAll("[\\s*\t\n\r]", "");
return String.format(Constant.HUAWEI_WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time);
@ -56,11 +55,9 @@ public class HuaweiBuilder {
static void trustAllHttpsCertificates() throws Exception {
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return;
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return;
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
@ -75,11 +72,11 @@ public class HuaweiBuilder {
/**
* buildRequestBody
* <p>构造请求Body体
* @param sender
* @param receiver
* @param templateId
* @param templateParas
* @param statusCallBack
* @param sender 国内短信签名通道号
* @param receiver 短信接收者
* @param templateId 短信模板id
* @param templateParas 模板参数
* @param statusCallBack 短信状态报告接收地
* @param signature | 签名名称,使用国内短信通用模板时填写
* @author :Wind
*/
@ -135,16 +132,16 @@ public class HuaweiBuilder {
}
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){
SimpleDateFormat sdf = new SimpleDateFormat(Constant.HUAWEI_JAVA_DATE);
try {
return sdf.parse(date);
return SDF.parse(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
private static final SimpleDateFormat SDF = new SimpleDateFormat(Constant.HUAWEI_JAVA_DATE);
}

View File

@ -26,7 +26,7 @@ import java.util.concurrent.Executor;
@Slf4j
public class TencentSmsImpl extends AbstractSmsBlend {
private TencentConfig tencentSmsConfig;
private final TencentConfig tencentSmsConfig;
public TencentSmsImpl(TencentConfig tencentSmsConfig, Executor pool, DelayedTime delayed) {
super(pool, delayed);

View File

@ -1,11 +1,11 @@
package org.dromara.sms4j.tencent.utils;
import cn.hutool.crypto.digest.HMac;
import cn.hutool.crypto.digest.HmacAlgorithm;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.tencent.config.TencentConfig;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
@ -34,11 +34,9 @@ public class TencentUtils {
private static final String CT_JSON = "application/json; charset=utf-8";
private static byte[] hmac256(byte[] key, String msg) throws Exception {
Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(key, mac.getAlgorithm());
mac.init(secretKeySpec);
return mac.doFinal(msg.getBytes(StandardCharsets.UTF_8));
private static byte[] hmac256(byte[] key, String msg) {
HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, key);
return hMac.digest(msg.getBytes(StandardCharsets.UTF_8));
}
private static String sha256Hex(String s) throws Exception {

View File

@ -1,13 +1,13 @@
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 com.dtflys.forest.config.ForestConfiguration;
import org.dromara.sms4j.comm.exception.SmsBlendException;
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.Date;
import java.util.HashMap;
@ -36,12 +36,9 @@ public class UniClient {
private static String getSignature(final String message, final String secretKey) {
try {
Mac hmac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
hmac.init(secretKeySpec);
byte[] bytes = hmac.doFinal(message.getBytes());
return Base64.getEncoder().encodeToString(bytes);
HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, secretKey.getBytes());
byte[] bytes = hMac.digest(message.getBytes());
return Base64.encode(bytes);
} catch (Exception e) {
return null;
}

View File

@ -5,7 +5,6 @@ import org.dromara.sms4j.comm.exception.SmsBlendException;
import java.util.Objects;
public class UniResponse {
public static final String REQUEST_ID_HEADER_KEY = "x-uni-request-id";
public String requestId;

View File

@ -17,18 +17,16 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
/**
* <p>类名: UniSmsImpl
* <p>说明 uniSms短信实现
* @author :Wind
* 2023/3/26 17:10
**/
@Slf4j
public class UniSmsImpl extends AbstractSmsBlend {
private UniConfig config;
private final UniConfig config;
public UniSmsImpl(UniConfig config, Executor pool, DelayedTime delayed) {
super(pool,delayed);

View File

@ -27,7 +27,7 @@ public class YunPianSmsImpl extends AbstractSmsBlend {
this.config = config;
}
private YunpianConfig config;
private final YunpianConfig config;
private static SmsResponse getSmsResponse(JSONObject execute) {
SmsResponse smsResponse = new SmsResponse();
@ -121,14 +121,8 @@ public class YunPianSmsImpl extends AbstractSmsBlend {
http.post(Constant.YUNPIAN_URL + "/sms/tpl_single_send.json")
.addHeader(headers)
.addBody(body)
.onSuccess(((data, req, res) -> {
JSONObject jsonBody = res.get(JSONObject.class);
smsResponse.set(getSmsResponse(jsonBody));
}))
.onError((ex, req, res) -> {
JSONObject jsonBody = res.get(JSONObject.class);
smsResponse.set(getSmsResponse(jsonBody));
})
.onSuccess(((data, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class)))))
.onError((ex, req, res) -> smsResponse.set(getSmsResponse(res.get(JSONObject.class))))
.execute();
return smsResponse.get();

View File

@ -9,7 +9,7 @@ import org.noear.solon.core.Plugin;
*/
public class XPluginImpl implements Plugin {
@Override
public void start(AopContext context) throws Throwable {
public void start(AopContext context) {
context.beanMake(SmsAutowiredConfig.class);
SmsAutowiredConfig.aopContext = context;
}

View File

@ -23,7 +23,7 @@ public class SolonRestrictedProcess extends RestrictedProcess {
}
@Override
public SmsBlendException process(SmsConfig config, String args) throws Exception {
public SmsBlendException process(SmsConfig config, String args) {
Integer accountMax = config.getAccountMax();//每日最大发送量
Integer minuteMax = config.getMinuteMax();//每分钟最大发送量
if (SmsUtil.isNotEmpty(accountMax)) { //是否配置了每日限制

View File

@ -22,7 +22,6 @@ import org.noear.solon.core.Props;
import java.util.concurrent.Executor;
@Slf4j
@Configuration
public class SmsAutowiredConfig {

View File

@ -8,7 +8,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Slf4j
public class RedisUtils {
@ -97,9 +96,7 @@ public class RedisUtils {
*/
public boolean multiSet(Map valueMap) {
try {
valueMap.forEach((key, val) -> {
redisTemplate.getBucket((String) key).set(val);
});
valueMap.forEach((key, val) -> redisTemplate.getBucket((String) key).set(val));
return true;
} catch (Exception e) {
log.error(e.toString());