diff --git a/pom.xml b/pom.xml index a29f566..f72f435 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ org.apache.httpcomponents httpclient - 4.5.9 + 4.5.13 @@ -152,6 +152,42 @@ 2.4.5 + + com.aliyun + dysmsapi20170525 + 2.0.1 + + + com.aliyun + tea-openapi + 0.0.13 + + + com.aliyun + tea-console + 0.0.1 + + + com.aliyun + darabonba-env + 0.1.1 + + + com.aliyun + tea-util + 0.2.11 + + + com.aliyun + darabonba-time + 0.0.1 + + + com.aliyun + tea + [1.0.3, 2.0.0) + + diff --git a/pom.xml b/pom.xml index a29f566..f72f435 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ org.apache.httpcomponents httpclient - 4.5.9 + 4.5.13 @@ -152,6 +152,42 @@ 2.4.5 + + com.aliyun + dysmsapi20170525 + 2.0.1 + + + com.aliyun + tea-openapi + 0.0.13 + + + com.aliyun + tea-console + 0.0.1 + + + com.aliyun + darabonba-env + 0.1.1 + + + com.aliyun + tea-util + 0.2.11 + + + com.aliyun + darabonba-time + 0.0.1 + + + com.aliyun + tea + [1.0.3, 2.0.0) + + diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 04eced2..b9437af 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,8 +2,10 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.config.AliYunConfig; import com.casic.dao.DataPressureMapper; import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; @@ -109,9 +111,12 @@ } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" // + "设备" + devcode + "发生了压力超标,压力值为" + presss // + @Autowired + private AliYunConfig aliYunConfig; private void alarmPushBuilder(String devcode, String presss) { ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); @@ -127,21 +132,27 @@ } } if (alarmPushConfig.getShortMessageAlarm().equals(1)) { - Map msgMap = new HashMap<>(); + JSONArray msglist = new JSONArray(); + JSONObject msgMap = new JSONObject(); msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); msgMap.put("devcode", devcode); msgMap.put("value", presss); msgMap.put("content", "压力超标"); String phoneJson = ""; - if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + List aliSignNameList = new ArrayList<>(); + String aliSignName = aliYunConfig.getSignNameJson(); + if (!org.apache.commons.lang3.StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { String[] phones = alarmPushConfig.getPhoneArray().split(","); List phoneList = new ArrayList<>(); for (String phone : phones) { + msglist.add(msgMap); phoneList.add(phone); + aliSignNameList.add(aliSignName); } + phoneJson = JSONObject.toJSONString(phoneList); } - sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap),JSONObject.toJSONString(aliSignNameList)); } } } diff --git a/pom.xml b/pom.xml index a29f566..f72f435 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ org.apache.httpcomponents httpclient - 4.5.9 + 4.5.13 @@ -152,6 +152,42 @@ 2.4.5 + + com.aliyun + dysmsapi20170525 + 2.0.1 + + + com.aliyun + tea-openapi + 0.0.13 + + + com.aliyun + tea-console + 0.0.1 + + + com.aliyun + darabonba-env + 0.1.1 + + + com.aliyun + tea-util + 0.2.11 + + + com.aliyun + darabonba-time + 0.0.1 + + + com.aliyun + tea + [1.0.3, 2.0.0) + + diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 04eced2..b9437af 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,8 +2,10 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.config.AliYunConfig; import com.casic.dao.DataPressureMapper; import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; @@ -109,9 +111,12 @@ } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" // + "设备" + devcode + "发生了压力超标,压力值为" + presss // + @Autowired + private AliYunConfig aliYunConfig; private void alarmPushBuilder(String devcode, String presss) { ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); @@ -127,21 +132,27 @@ } } if (alarmPushConfig.getShortMessageAlarm().equals(1)) { - Map msgMap = new HashMap<>(); + JSONArray msglist = new JSONArray(); + JSONObject msgMap = new JSONObject(); msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); msgMap.put("devcode", devcode); msgMap.put("value", presss); msgMap.put("content", "压力超标"); String phoneJson = ""; - if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + List aliSignNameList = new ArrayList<>(); + String aliSignName = aliYunConfig.getSignNameJson(); + if (!org.apache.commons.lang3.StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { String[] phones = alarmPushConfig.getPhoneArray().split(","); List phoneList = new ArrayList<>(); for (String phone : phones) { + msglist.add(msgMap); phoneList.add(phone); + aliSignNameList.add(aliSignName); } + phoneJson = JSONObject.toJSONString(phoneList); } - sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap),JSONObject.toJSONString(aliSignNameList)); } } } diff --git a/src/main/java/com/casic/util/SendBatchSmsUtil.java b/src/main/java/com/casic/util/SendBatchSmsUtil.java index ed043a4..6152c60 100644 --- a/src/main/java/com/casic/util/SendBatchSmsUtil.java +++ b/src/main/java/com/casic/util/SendBatchSmsUtil.java @@ -1,6 +1,7 @@ package com.casic.util; // This file is auto-generated, don't edit it. Thanks. +import com.alibaba.fastjson.JSONObject; import com.aliyun.auth.credentials.Credential; import com.aliyun.auth.credentials.provider.StaticCredentialProvider; import com.aliyun.sdk.service.dysmsapi20170525.models.*; @@ -12,6 +13,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.util.*; import java.util.concurrent.CompletableFuture; @AllArgsConstructor @@ -21,7 +25,7 @@ private AliYunConfig aliYunConfig; - public void sendMsg(String phoneJson, String msgJson) { + public void sendMsg(String phoneJson, String msgJson,String aliSignNameJson) { StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() .accessKeyId(aliYunConfig.getKey()) .accessKeySecret(aliYunConfig.getScrect()) @@ -33,12 +37,13 @@ .overrideConfiguration( ClientOverrideConfiguration.create() .setEndpointOverride(aliYunConfig.getUrl()) + .setConnectTimeout(Duration.ofSeconds(30)) ) .build(); SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() .phoneNumberJson(phoneJson) - .signNameJson(aliYunConfig.getSignNameJson()) + .signNameJson(aliSignNameJson) .templateCode(aliYunConfig.getTemplateCode()) .templateParamJson(msgJson) .build(); @@ -55,8 +60,7 @@ } -// public static void main(String [] args) throws Exception { -// +// public static void main(String[] args) throws Exception { // StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() // .accessKeyId("LTAI5tDFNucQF2Bdy4fHgzrN") // .accessKeySecret("hZ22QQPxQue1G0R8Ty2bo6GimrLdoB") @@ -68,16 +72,24 @@ // .overrideConfiguration( // ClientOverrideConfiguration.create() // .setEndpointOverride("dysmsapi.aliyuncs.com") +// .setConnectTimeout(Duration.ofSeconds(30)) // ) // .build(); -// +// List> msgList = new ArrayList<>(); +// Map msgMap = new HashMap<>(); +// msgMap.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); +// msgMap.put("devcode", "123456"); +// msgMap.put("value", "24Vol"); +// msgMap.put("content", "浓度超限"); +// msgList.add(msgMap); +// Map msgMapCoye=(Map)((HashMap) msgMap).clone(); +// msgList.add(msgMapCoye); +// System.out.println(JSONObject.toJSONString(msgList)); // SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() -// .phoneNumberJson("[\"13651065090\"]") -// .signNameJson("[\"阿里云短信测试\"]") -// .templateCode("SMS_154950909") -// .templateParamJson("[{\"code\":\"123456\"}]") -// // Request-level configuration rewrite, can set Http request parameters, etc. -// // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())) +// .phoneNumberJson("[\"13651065090\",\"13652031267\"]") +// .signNameJson("[\"柴壮告警提醒\",\"柴壮告警提醒\"]") +// .templateCode("SMS_268475055") +// .templateParamJson(JSONObject.toJSONString(msgList)) // .build(); // // CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); diff --git a/pom.xml b/pom.xml index a29f566..f72f435 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ org.apache.httpcomponents httpclient - 4.5.9 + 4.5.13 @@ -152,6 +152,42 @@ 2.4.5 + + com.aliyun + dysmsapi20170525 + 2.0.1 + + + com.aliyun + tea-openapi + 0.0.13 + + + com.aliyun + tea-console + 0.0.1 + + + com.aliyun + darabonba-env + 0.1.1 + + + com.aliyun + tea-util + 0.2.11 + + + com.aliyun + darabonba-time + 0.0.1 + + + com.aliyun + tea + [1.0.3, 2.0.0) + + diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 04eced2..b9437af 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,8 +2,10 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.config.AliYunConfig; import com.casic.dao.DataPressureMapper; import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; @@ -109,9 +111,12 @@ } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" // + "设备" + devcode + "发生了压力超标,压力值为" + presss // + @Autowired + private AliYunConfig aliYunConfig; private void alarmPushBuilder(String devcode, String presss) { ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); @@ -127,21 +132,27 @@ } } if (alarmPushConfig.getShortMessageAlarm().equals(1)) { - Map msgMap = new HashMap<>(); + JSONArray msglist = new JSONArray(); + JSONObject msgMap = new JSONObject(); msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); msgMap.put("devcode", devcode); msgMap.put("value", presss); msgMap.put("content", "压力超标"); String phoneJson = ""; - if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + List aliSignNameList = new ArrayList<>(); + String aliSignName = aliYunConfig.getSignNameJson(); + if (!org.apache.commons.lang3.StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { String[] phones = alarmPushConfig.getPhoneArray().split(","); List phoneList = new ArrayList<>(); for (String phone : phones) { + msglist.add(msgMap); phoneList.add(phone); + aliSignNameList.add(aliSignName); } + phoneJson = JSONObject.toJSONString(phoneList); } - sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap),JSONObject.toJSONString(aliSignNameList)); } } } diff --git a/src/main/java/com/casic/util/SendBatchSmsUtil.java b/src/main/java/com/casic/util/SendBatchSmsUtil.java index ed043a4..6152c60 100644 --- a/src/main/java/com/casic/util/SendBatchSmsUtil.java +++ b/src/main/java/com/casic/util/SendBatchSmsUtil.java @@ -1,6 +1,7 @@ package com.casic.util; // This file is auto-generated, don't edit it. Thanks. +import com.alibaba.fastjson.JSONObject; import com.aliyun.auth.credentials.Credential; import com.aliyun.auth.credentials.provider.StaticCredentialProvider; import com.aliyun.sdk.service.dysmsapi20170525.models.*; @@ -12,6 +13,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.util.*; import java.util.concurrent.CompletableFuture; @AllArgsConstructor @@ -21,7 +25,7 @@ private AliYunConfig aliYunConfig; - public void sendMsg(String phoneJson, String msgJson) { + public void sendMsg(String phoneJson, String msgJson,String aliSignNameJson) { StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() .accessKeyId(aliYunConfig.getKey()) .accessKeySecret(aliYunConfig.getScrect()) @@ -33,12 +37,13 @@ .overrideConfiguration( ClientOverrideConfiguration.create() .setEndpointOverride(aliYunConfig.getUrl()) + .setConnectTimeout(Duration.ofSeconds(30)) ) .build(); SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() .phoneNumberJson(phoneJson) - .signNameJson(aliYunConfig.getSignNameJson()) + .signNameJson(aliSignNameJson) .templateCode(aliYunConfig.getTemplateCode()) .templateParamJson(msgJson) .build(); @@ -55,8 +60,7 @@ } -// public static void main(String [] args) throws Exception { -// +// public static void main(String[] args) throws Exception { // StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() // .accessKeyId("LTAI5tDFNucQF2Bdy4fHgzrN") // .accessKeySecret("hZ22QQPxQue1G0R8Ty2bo6GimrLdoB") @@ -68,16 +72,24 @@ // .overrideConfiguration( // ClientOverrideConfiguration.create() // .setEndpointOverride("dysmsapi.aliyuncs.com") +// .setConnectTimeout(Duration.ofSeconds(30)) // ) // .build(); -// +// List> msgList = new ArrayList<>(); +// Map msgMap = new HashMap<>(); +// msgMap.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); +// msgMap.put("devcode", "123456"); +// msgMap.put("value", "24Vol"); +// msgMap.put("content", "浓度超限"); +// msgList.add(msgMap); +// Map msgMapCoye=(Map)((HashMap) msgMap).clone(); +// msgList.add(msgMapCoye); +// System.out.println(JSONObject.toJSONString(msgList)); // SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() -// .phoneNumberJson("[\"13651065090\"]") -// .signNameJson("[\"阿里云短信测试\"]") -// .templateCode("SMS_154950909") -// .templateParamJson("[{\"code\":\"123456\"}]") -// // Request-level configuration rewrite, can set Http request parameters, etc. -// // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())) +// .phoneNumberJson("[\"13651065090\",\"13652031267\"]") +// .signNameJson("[\"柴壮告警提醒\",\"柴壮告警提醒\"]") +// .templateCode("SMS_268475055") +// .templateParamJson(JSONObject.toJSONString(msgList)) // .build(); // // CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 0e2b972..81bed8c 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -39,8 +39,8 @@ key: LTAI5tDFNucQF2Bdy4fHgzrN secret: hZ22QQPxQue1G0R8Ty2bo6GimrLdoB url: dysmsapi.aliyuncs.com - signNameJson: 阿里云短信测试 - templateCode: SMS_154950909 + signNameJson: 柴壮告警提醒 + templateCode: SMS_268475055 swagger: enable: true groupName: "硫化氢课题" \ No newline at end of file