报警优化
This commit is contained in:
parent
883cd67f79
commit
3a9409a7bb
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.axzo.framework</groupId>
|
<groupId>cn.axzo.framework</groupId>
|
||||||
<artifactId>alarm-spring-boot-starter</artifactId>
|
<artifactId>alarm-spring-boot-starter</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@ -24,14 +24,31 @@ public class AlarmProperties {
|
|||||||
@Data
|
@Data
|
||||||
public static final class Destination {
|
public static final class Destination {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报警名称
|
||||||
|
*/
|
||||||
private String alarmName;
|
private String alarmName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
private String messageType;
|
/**
|
||||||
|
* 通知地址
|
||||||
|
*/
|
||||||
private String alarmUrl;
|
private String alarmUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密钥
|
||||||
|
*/
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息类型
|
||||||
|
*/
|
||||||
|
private String messageType;
|
||||||
|
|
||||||
private List<String> atMobiles = new ArrayList<>();
|
private List<String> atMobiles = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,8 +50,9 @@ public class DingDingAlarmService implements AlarmService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String appName = getAppName();
|
String appName = getAppName();
|
||||||
|
String serverUrl = destination.getAlarmUrl() + destination.getSecretKey();
|
||||||
log.info("[{} -> ding] AlarmService.alarm request param is {}", appName, JSON.toJSONString(request));
|
log.info("[{} -> ding] AlarmService.alarm request param is {}", appName, JSON.toJSONString(request));
|
||||||
DingMessageResponse response = restTemplate.postForObject(destination.getAlarmUrl(), request, DingMessageResponse.class);
|
DingMessageResponse response = restTemplate.postForObject(serverUrl, request, DingMessageResponse.class);
|
||||||
log.info("[{} <- ding] AlarmService.alarm response is {}", appName, JSON.toJSONString(response));
|
log.info("[{} <- ding] AlarmService.alarm response is {}", appName, JSON.toJSONString(response));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[alarm <- ding] AlarmService.alarm response is error", e);
|
log.error("[alarm <- ding] AlarmService.alarm response is error", e);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.axzo.framework</groupId>
|
<groupId>cn.axzo.framework</groupId>
|
||||||
<artifactId>common-common</artifactId>
|
<artifactId>common-common</artifactId>
|
||||||
<version>1.0.12</version>
|
<version>1.0.13</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@ -0,0 +1,107 @@
|
|||||||
|
package cn.azxo.framework.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.MD5;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监管签名工具类
|
||||||
|
*
|
||||||
|
* @author zhaoyong
|
||||||
|
* @see RegulateSign
|
||||||
|
* @since 2021-11-29 11:05
|
||||||
|
*/
|
||||||
|
public class RegulateSign {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app key
|
||||||
|
*/
|
||||||
|
public static final String APP_KEY = "appSecret";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sign
|
||||||
|
*/
|
||||||
|
public static final String SIGN = "sign";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签名
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T extends Object> boolean checkSign(String appSecret, String sign,
|
||||||
|
Map<String, T> params) {
|
||||||
|
String tobeSignedStr = geneTobeSignedStr(params);
|
||||||
|
tobeSignedStr = tobeSignedStr.concat("&").concat(APP_KEY + "=" + appSecret);
|
||||||
|
String str = signByMd5(tobeSignedStr);
|
||||||
|
return str.equals(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签名
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T extends Object> boolean checkSign(String appSecret, Map<String, T> params) {
|
||||||
|
T signStr = params.get(SIGN);
|
||||||
|
if (signStr == null) {
|
||||||
|
throw new RuntimeException("sign 不存在");
|
||||||
|
}
|
||||||
|
params.remove(SIGN);
|
||||||
|
return checkSign(appSecret, signStr.toString(), params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成待签名字符串
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T extends Object> String geneTobeSignedStr(Map<String, T> params) {
|
||||||
|
Map<String, Object> sortedMap = new TreeMap<>(params);
|
||||||
|
StringBuilder tobeSignedStr = new StringBuilder();
|
||||||
|
sortedMap.forEach((k, v) -> {
|
||||||
|
if (Objects.isNull(v)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(v)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (v instanceof Date) {
|
||||||
|
long time = ((Date) v).getTime();
|
||||||
|
v = time;
|
||||||
|
}
|
||||||
|
if (v instanceof Collection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tobeSignedStr.append(k).append("=").append(v).append("&");
|
||||||
|
});
|
||||||
|
return tobeSignedStr.substring(0, tobeSignedStr.length() -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* md5 签名
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String signByMd5(String data, String appSecret) {
|
||||||
|
return signByMd5(data.concat("&" + APP_KEY + "=" + appSecret));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* md5 签名
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String signByMd5(String data) {
|
||||||
|
MD5 md5 = MD5.create();
|
||||||
|
String str = md5.digestHex(data).toUpperCase();
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user