|
|
package com.monitor.common.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.monitor.common.config.SendsmsConfig;
|
|
|
import com.monitor.common.config.SnsMobileConfig;
|
|
|
import com.monitor.common.util.MD5Util;
|
|
|
import com.monitor.influxdb.contants.InfluxDBContants;
|
|
|
import com.monitor.common.service.AlarmMsgService;
|
|
|
import com.monitor.common.service.HttpRestClientService;
|
|
|
import com.monitor.influxdb.mapper.MonitorAlarmMapper;
|
|
|
import com.monitor.model.domain.QcloudSms;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -36,9 +39,6 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { |
|
|
private SendsmsConfig sendsmsConfig;
|
|
|
|
|
|
@Autowired
|
|
|
private SnsMobileConfig snsMobileConfig;
|
|
|
|
|
|
@Autowired
|
|
|
private MonitorAlarmMapper monitorAlarmMapper;
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(AlarmMsgServiceImpl.class);
|
...
|
...
|
@@ -78,41 +78,18 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { |
|
|
return true;
|
|
|
}
|
|
|
|
|
|
logger.warn("Send msg type {} content {} alarmInfo {} moniole {}...", type, content, alarmInfo, mobile);
|
|
|
|
|
|
Map<String, String> contentMap = new HashMap<String, String>();
|
|
|
contentMap.put("OperID", sendsmsConfig.getUserName());
|
|
|
contentMap.put("OperPass", sendsmsConfig.getPwd());
|
|
|
contentMap.put("DesMobile", mobile);
|
|
|
contentMap.put("ContentType", sendsmsConfig.getNoticeProductid());
|
|
|
|
|
|
boolean sendStatus = true;
|
|
|
|
|
|
// // 如果短信内容不超过指定字符字符,则单条发送,如果超过,则分割多条发送
|
|
|
// while (content.length() > CONTENT_SUB_LENGTH) {
|
|
|
// String contentSubStr = content.substring(0, CONTENT_SUB_LENGTH);
|
|
|
// content = content.substring(CONTENT_SUB_LENGTH);
|
|
|
//
|
|
|
// // 发送被切割的字符串
|
|
|
// contentMap.put("content", contentSubStr);
|
|
|
// boolean sendSingleSmsStatus = sendSingleSms(contentMap);
|
|
|
//
|
|
|
// if (sendSingleSmsStatus == false) {
|
|
|
// sendStatus = false;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
logger.info("Send msg type {} content {} alarmInfo {} moniole {}...", type, content, alarmInfo, mobile);
|
|
|
if (StringUtils.isBlank(content)) {
|
|
|
return false;
|
|
|
}
|
|
|
contentMap.put("Content", content);
|
|
|
boolean sendSingleSmsStatus = sendSingleSms(contentMap);
|
|
|
if (sendSingleSmsStatus == false) {
|
|
|
String result = sendSingleSms(content, mobile);
|
|
|
boolean sendStatus = true;
|
|
|
if (result == null) {
|
|
|
sendStatus = false;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "failed");
|
|
|
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "faild", result);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("insert sms into influxdb failed", e);
|
|
|
}
|
...
|
...
|
@@ -121,29 +98,30 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送单条短信
|
|
|
* 发送短信
|
|
|
*
|
|
|
* @param smsMap
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean sendSingleSms(Map<String, String> smsMap) {
|
|
|
private String sendSingleSms(String content, String mobile) {
|
|
|
|
|
|
try {
|
|
|
smsMap.put("Content", URLEncoder.encode("【有货运维】" + smsMap.get("Content"), "UTF-8"));
|
|
|
String result = httpRestClientService.get(sendsmsConfig.getSendsmsUrl(), smsMap, String.class);
|
|
|
|
|
|
if (result == null || !("01".equals(result.split(",")[0]) || "00".equals(result.split(",")[0]) || "03".equals(result.split(",")[0]))) {
|
|
|
logger.error("发送短信失败,短信内容|" + JSONArray.toJSONString(smsMap));
|
|
|
smsMap.put("Content", URLEncoder.encode("【有货运维】发送短信告警失败!!!", "UTF-8"));
|
|
|
smsMap.put("DesMobile", snsMobileConfig.getBaseMobile());
|
|
|
// 短信发送失败 发送短信给开发回来改bug
|
|
|
httpRestClientService.get(sendsmsConfig.getSendsmsUrl(), smsMap, String.class);
|
|
|
return false;
|
|
|
QcloudSms qcloudSms = new QcloudSms();
|
|
|
List<QcloudSms.Tel> telList = new ArrayList<>();
|
|
|
String[] mobiles = mobile.split(",");
|
|
|
QcloudSms.Tel tel;
|
|
|
for (String mob : mobiles) {
|
|
|
tel = new QcloudSms.Tel();
|
|
|
tel.setPhone(mob);
|
|
|
telList.add(tel);
|
|
|
}
|
|
|
return true;
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
e.printStackTrace();
|
|
|
return false;
|
|
|
qcloudSms.setTel(telList);
|
|
|
qcloudSms.setMsg("故障:"+content);
|
|
|
qcloudSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + mobile));
|
|
|
String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudSmsUrl(), JSON.toJSONString(qcloudSms));
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("send sms failed", e);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
|