Merge branch 'master' of http://git.yoho.cn/ops/monitor-service
Showing
18 changed files
with
259 additions
and
81 deletions
@@ -18,6 +18,15 @@ public class SendsmsConfig { | @@ -18,6 +18,15 @@ public class SendsmsConfig { | ||
18 | @Value("${sendsms.notice.productid}") | 18 | @Value("${sendsms.notice.productid}") |
19 | private String noticeProductid;// 产品id | 19 | private String noticeProductid;// 产品id |
20 | 20 | ||
21 | + @Value("${qcloud_sms_key}") | ||
22 | + private String qcloudSmsKey; | ||
23 | + | ||
24 | + @Value("${qcloud_sms_url}") | ||
25 | + private String qcloudSmsUrl; | ||
26 | + | ||
27 | + @Value("${qcloud_voice_url}") | ||
28 | + private String qcloudVoiceUrl; | ||
29 | + | ||
21 | public String getSendsmsUrl() { | 30 | public String getSendsmsUrl() { |
22 | return sendsmsUrl; | 31 | return sendsmsUrl; |
23 | } | 32 | } |
@@ -33,4 +42,16 @@ public class SendsmsConfig { | @@ -33,4 +42,16 @@ public class SendsmsConfig { | ||
33 | public String getNoticeProductid() { | 42 | public String getNoticeProductid() { |
34 | return noticeProductid; | 43 | return noticeProductid; |
35 | } | 44 | } |
45 | + | ||
46 | + public String getQcloudSmsUrl() { | ||
47 | + return qcloudSmsUrl; | ||
48 | + } | ||
49 | + | ||
50 | + public String getQcloudSmsKey() { | ||
51 | + return qcloudSmsKey; | ||
52 | + } | ||
53 | + | ||
54 | + public String getQcloudVoiceUrl() { | ||
55 | + return qcloudVoiceUrl; | ||
56 | + } | ||
36 | } | 57 | } |
1 | package com.monitor.common.service.impl; | 1 | package com.monitor.common.service.impl; |
2 | 2 | ||
3 | +import com.alibaba.fastjson.JSON; | ||
3 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
4 | import com.monitor.common.config.SendsmsConfig; | 5 | import com.monitor.common.config.SendsmsConfig; |
5 | import com.monitor.common.config.SnsMobileConfig; | 6 | import com.monitor.common.config.SnsMobileConfig; |
7 | +import com.monitor.common.util.MD5Util; | ||
6 | import com.monitor.influxdb.contants.InfluxDBContants; | 8 | import com.monitor.influxdb.contants.InfluxDBContants; |
7 | import com.monitor.common.service.AlarmMsgService; | 9 | import com.monitor.common.service.AlarmMsgService; |
8 | import com.monitor.common.service.HttpRestClientService; | 10 | import com.monitor.common.service.HttpRestClientService; |
9 | import com.monitor.influxdb.mapper.MonitorAlarmMapper; | 11 | import com.monitor.influxdb.mapper.MonitorAlarmMapper; |
12 | +import com.monitor.model.domain.QcloudSms; | ||
10 | import org.apache.commons.lang.StringUtils; | 13 | import org.apache.commons.lang.StringUtils; |
11 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
12 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
@@ -36,9 +39,6 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -36,9 +39,6 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
36 | private SendsmsConfig sendsmsConfig; | 39 | private SendsmsConfig sendsmsConfig; |
37 | 40 | ||
38 | @Autowired | 41 | @Autowired |
39 | - private SnsMobileConfig snsMobileConfig; | ||
40 | - | ||
41 | - @Autowired | ||
42 | private MonitorAlarmMapper monitorAlarmMapper; | 42 | private MonitorAlarmMapper monitorAlarmMapper; |
43 | 43 | ||
44 | private Logger logger = LoggerFactory.getLogger(AlarmMsgServiceImpl.class); | 44 | private Logger logger = LoggerFactory.getLogger(AlarmMsgServiceImpl.class); |
@@ -78,41 +78,18 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -78,41 +78,18 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
78 | return true; | 78 | return true; |
79 | } | 79 | } |
80 | 80 | ||
81 | - logger.warn("Send msg type {} content {} alarmInfo {} moniole {}...", type, content, alarmInfo, mobile); | ||
82 | - | ||
83 | - Map<String, String> contentMap = new HashMap<String, String>(); | ||
84 | - contentMap.put("OperID", sendsmsConfig.getUserName()); | ||
85 | - contentMap.put("OperPass", sendsmsConfig.getPwd()); | ||
86 | - contentMap.put("DesMobile", mobile); | ||
87 | - contentMap.put("ContentType", sendsmsConfig.getNoticeProductid()); | ||
88 | - | ||
89 | - boolean sendStatus = true; | ||
90 | - | ||
91 | -// // 如果短信内容不超过指定字符字符,则单条发送,如果超过,则分割多条发送 | ||
92 | -// while (content.length() > CONTENT_SUB_LENGTH) { | ||
93 | -// String contentSubStr = content.substring(0, CONTENT_SUB_LENGTH); | ||
94 | -// content = content.substring(CONTENT_SUB_LENGTH); | ||
95 | -// | ||
96 | -// // 发送被切割的字符串 | ||
97 | -// contentMap.put("content", contentSubStr); | ||
98 | -// boolean sendSingleSmsStatus = sendSingleSms(contentMap); | ||
99 | -// | ||
100 | -// if (sendSingleSmsStatus == false) { | ||
101 | -// sendStatus = false; | ||
102 | -// } | ||
103 | -// } | ||
104 | - | 81 | + logger.info("Send msg type {} content {} alarmInfo {} moniole {}...", type, content, alarmInfo, mobile); |
105 | if (StringUtils.isBlank(content)) { | 82 | if (StringUtils.isBlank(content)) { |
106 | return false; | 83 | return false; |
107 | } | 84 | } |
108 | - contentMap.put("Content", content); | ||
109 | - boolean sendSingleSmsStatus = sendSingleSms(contentMap); | ||
110 | - if (sendSingleSmsStatus == false) { | 85 | + String result = sendSingleSms(content, mobile); |
86 | + boolean sendStatus = true; | ||
87 | + if (result == null) { | ||
111 | sendStatus = false; | 88 | sendStatus = false; |
112 | } | 89 | } |
113 | 90 | ||
114 | try { | 91 | try { |
115 | - monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "failed"); | 92 | + monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, type, content, alarmInfo, sendStatus ? "successed" : "faild", result); |
116 | } catch (Exception e) { | 93 | } catch (Exception e) { |
117 | logger.error("insert sms into influxdb failed", e); | 94 | logger.error("insert sms into influxdb failed", e); |
118 | } | 95 | } |
@@ -121,29 +98,30 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | @@ -121,29 +98,30 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { | ||
121 | } | 98 | } |
122 | 99 | ||
123 | /** | 100 | /** |
124 | - * 发送单条短信 | 101 | + * 发送短信 |
125 | * | 102 | * |
126 | - * @param smsMap | ||
127 | * @return | 103 | * @return |
128 | */ | 104 | */ |
129 | - private boolean sendSingleSms(Map<String, String> smsMap) { | 105 | + private String sendSingleSms(String content, String mobile) { |
130 | 106 | ||
131 | try { | 107 | try { |
132 | - smsMap.put("Content", URLEncoder.encode("【有货运维】" + smsMap.get("Content"), "UTF-8")); | ||
133 | - String result = httpRestClientService.get(sendsmsConfig.getSendsmsUrl(), smsMap, String.class); | ||
134 | - | ||
135 | - if (result == null || !("01".equals(result.split(",")[0]) || "00".equals(result.split(",")[0]) || "03".equals(result.split(",")[0]))) { | ||
136 | - logger.error("发送短信失败,短信内容|" + JSONArray.toJSONString(smsMap)); | ||
137 | - smsMap.put("Content", URLEncoder.encode("【有货运维】发送短信告警失败!!!", "UTF-8")); | ||
138 | - smsMap.put("DesMobile", snsMobileConfig.getBaseMobile()); | ||
139 | - // 短信发送失败 发送短信给开发回来改bug | ||
140 | - httpRestClientService.get(sendsmsConfig.getSendsmsUrl(), smsMap, String.class); | ||
141 | - return false; | 108 | + QcloudSms qcloudSms = new QcloudSms(); |
109 | + List<QcloudSms.Tel> telList = new ArrayList<>(); | ||
110 | + String[] mobiles = mobile.split(","); | ||
111 | + QcloudSms.Tel tel; | ||
112 | + for (String mob : mobiles) { | ||
113 | + tel = new QcloudSms.Tel(); | ||
114 | + tel.setPhone(mob); | ||
115 | + telList.add(tel); | ||
142 | } | 116 | } |
143 | - return true; | ||
144 | - } catch (UnsupportedEncodingException e) { | ||
145 | - e.printStackTrace(); | ||
146 | - return false; | 117 | + qcloudSms.setTel(telList); |
118 | + qcloudSms.setMsg("故障:"+content); | ||
119 | + qcloudSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + mobile)); | ||
120 | + String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudSmsUrl(), JSON.toJSONString(qcloudSms)); | ||
121 | + return result; | ||
122 | + } catch (Exception e) { | ||
123 | + logger.error("send sms failed", e); | ||
124 | + return null; | ||
147 | } | 125 | } |
148 | 126 | ||
149 | } | 127 | } |
1 | package com.monitor.common.service.impl; | 1 | package com.monitor.common.service.impl; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | +import com.monitor.common.config.SendsmsConfig; | ||
5 | +import com.monitor.common.config.SnsMobileConfig; | ||
4 | import com.monitor.common.service.HttpRestClientService; | 6 | import com.monitor.common.service.HttpRestClientService; |
5 | import com.monitor.common.service.VoiceMsgService; | 7 | import com.monitor.common.service.VoiceMsgService; |
6 | import com.monitor.common.util.MD5Util; | 8 | import com.monitor.common.util.MD5Util; |
@@ -27,6 +29,9 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | @@ -27,6 +29,9 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | ||
27 | @Autowired | 29 | @Autowired |
28 | private HttpRestClientService httpRestClientService; | 30 | private HttpRestClientService httpRestClientService; |
29 | 31 | ||
32 | + @Autowired | ||
33 | + private SendsmsConfig sendsmsConfig; | ||
34 | + | ||
30 | public final Logger DEBUG = LoggerFactory.getLogger(getClass()); | 35 | public final Logger DEBUG = LoggerFactory.getLogger(getClass()); |
31 | 36 | ||
32 | @Override | 37 | @Override |
@@ -42,10 +47,10 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | @@ -42,10 +47,10 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | ||
42 | VoiceSms.Tel tel = new VoiceSms.Tel(); | 47 | VoiceSms.Tel tel = new VoiceSms.Tel(); |
43 | tel.setNationcode("86"); | 48 | tel.setNationcode("86"); |
44 | tel.setPhone(str); | 49 | tel.setPhone(str); |
45 | - voiceSms.setSig(MD5Util.encryption("6e56f948f6f1c0a1bc359e23f7acc140" + str)); | 50 | + voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str)); |
46 | voiceSms.setTel(tel); | 51 | voiceSms.setTel(tel); |
47 | DEBUG.info("send voice msg,content:{}", JSON.toJSONString(voiceSms)); | 52 | DEBUG.info("send voice msg,content:{}", JSON.toJSONString(voiceSms)); |
48 | - String result = httpRestClientService.doPostStringJson("https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoice?sdkappid=1400021400&random=123", JSON.toJSONString(voiceSms)); | 53 | + String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms)); |
49 | DEBUG.info("send voice msg,result:{}", result); | 54 | DEBUG.info("send voice msg,result:{}", result); |
50 | } | 55 | } |
51 | 56 | ||
@@ -67,13 +72,13 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | @@ -67,13 +72,13 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | ||
67 | String[] mobiles = mobile.split(","); | 72 | String[] mobiles = mobile.split(","); |
68 | for (String str : mobiles) { | 73 | for (String str : mobiles) { |
69 | VoiceSmsNotice.Tel tel = new VoiceSmsNotice.Tel(); | 74 | VoiceSmsNotice.Tel tel = new VoiceSmsNotice.Tel(); |
70 | - tel.setNationcode("86"); | ||
71 | tel.setPhone(str); | 75 | tel.setPhone(str); |
72 | - voiceSms.setSig(MD5Util.encryption("6e56f948f6f1c0a1bc359e23f7acc140" + str)); | 76 | + voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str)); |
73 | voiceSms.setTel(tel); | 77 | voiceSms.setTel(tel); |
74 | DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms)); | 78 | DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms)); |
75 | - String result = httpRestClientService.doPostStringJson("https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123", JSON.toJSONString(voiceSms)); | 79 | + String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms)); |
76 | DEBUG.info("send voice notice msg,result:{}", result); | 80 | DEBUG.info("send voice notice msg,result:{}", result); |
81 | + monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", "请及时处理故障:紧急故障", "null", result!=null ? "successed" : "faild", result); | ||
77 | } | 82 | } |
78 | 83 | ||
79 | } catch (Exception e) { | 84 | } catch (Exception e) { |
@@ -31,7 +31,6 @@ | @@ -31,7 +31,6 @@ | ||
31 | <property name="messageConverters"> | 31 | <property name="messageConverters"> |
32 | <list> | 32 | <list> |
33 | <bean class="org.springframework.http.converter.StringHttpMessageConverter"> | 33 | <bean class="org.springframework.http.converter.StringHttpMessageConverter"> |
34 | - <constructor-arg value="UTF-8" /> | ||
35 | </bean> | 34 | </bean> |
36 | <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" /> | 35 | <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" /> |
37 | <bean class="org.springframework.http.converter.FormHttpMessageConverter" /> | 36 | <bean class="org.springframework.http.converter.FormHttpMessageConverter" /> |
@@ -9,7 +9,7 @@ public interface MonitorAlarmMapper { | @@ -9,7 +9,7 @@ public interface MonitorAlarmMapper { | ||
9 | * @param influxDBName | 9 | * @param influxDBName |
10 | * @param snsContent | 10 | * @param snsContent |
11 | */ | 11 | */ |
12 | - void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus); | 12 | + void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result); |
13 | 13 | ||
14 | /** | 14 | /** |
15 | * 查询type的tag-value | 15 | * 查询type的tag-value |
1 | package com.monitor.influxdb.mapper; | 1 | package com.monitor.influxdb.mapper; |
2 | 2 | ||
3 | -import com.monitor.model.domain.QcloudSmsUpBody; | ||
4 | -import com.monitor.model.request.SmsUp; | 3 | +import com.monitor.model.domain.QcloudSmsUp; |
4 | +import com.monitor.model.domain.QcloudVoiceUpBody; | ||
5 | import org.influxdb.dto.QueryResult; | 5 | import org.influxdb.dto.QueryResult; |
6 | 6 | ||
7 | /** | 7 | /** |
@@ -9,7 +9,7 @@ import org.influxdb.dto.QueryResult; | @@ -9,7 +9,7 @@ import org.influxdb.dto.QueryResult; | ||
9 | */ | 9 | */ |
10 | public interface SmsUpMapper { | 10 | public interface SmsUpMapper { |
11 | 11 | ||
12 | - void insert(QcloudSmsUpBody qcloudSmsUpBody); | ||
13 | - | 12 | + void insert(QcloudVoiceUpBody qcloudSmsUpBody); |
13 | + void insert(QcloudSmsUp qcloudSmsUp); | ||
14 | QueryResult select(int min); | 14 | QueryResult select(int min); |
15 | } | 15 | } |
@@ -26,7 +26,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar | @@ -26,7 +26,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar | ||
26 | * @param alarmInfo | 26 | * @param alarmInfo |
27 | */ | 27 | */ |
28 | @Override | 28 | @Override |
29 | - public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus) { | 29 | + public void insertAlarmMsg(String influxDBName, String alarmType, String snsContent, String alarmInfo, String sendStatus,String result) { |
30 | BatchPoints batchPoints = BatchPoints | 30 | BatchPoints batchPoints = BatchPoints |
31 | .database(InfluxDBContants.YOMO_MONITOR).tag("event", "alarm").retentionPolicy("default") | 31 | .database(InfluxDBContants.YOMO_MONITOR).tag("event", "alarm").retentionPolicy("default") |
32 | .build(); | 32 | .build(); |
@@ -34,6 +34,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar | @@ -34,6 +34,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar | ||
34 | .tag("type", alarmType) | 34 | .tag("type", alarmType) |
35 | .tag("send_status", sendStatus) | 35 | .tag("send_status", sendStatus) |
36 | .addField("sms_content", snsContent) | 36 | .addField("sms_content", snsContent) |
37 | + .addField("result", result) | ||
37 | .addField("alarm_info", alarmInfo).build(); | 38 | .addField("alarm_info", alarmInfo).build(); |
38 | batchPoints.point(point); | 39 | batchPoints.point(point); |
39 | inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB() | 40 | inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB() |
@@ -3,8 +3,8 @@ package com.monitor.influxdb.mapper.impl; | @@ -3,8 +3,8 @@ package com.monitor.influxdb.mapper.impl; | ||
3 | import com.monitor.influxdb.InfluxDBQuery; | 3 | import com.monitor.influxdb.InfluxDBQuery; |
4 | import com.monitor.influxdb.contants.InfluxDBContants; | 4 | import com.monitor.influxdb.contants.InfluxDBContants; |
5 | import com.monitor.influxdb.mapper.SmsUpMapper; | 5 | import com.monitor.influxdb.mapper.SmsUpMapper; |
6 | -import com.monitor.model.domain.QcloudSmsUpBody; | ||
7 | -import com.monitor.model.request.SmsUp; | 6 | +import com.monitor.model.domain.QcloudSmsUp; |
7 | +import com.monitor.model.domain.QcloudVoiceUpBody; | ||
8 | import org.apache.commons.lang.StringUtils; | 8 | import org.apache.commons.lang.StringUtils; |
9 | import org.influxdb.dto.BatchPoints; | 9 | import org.influxdb.dto.BatchPoints; |
10 | import org.influxdb.dto.Point; | 10 | import org.influxdb.dto.Point; |
@@ -18,11 +18,11 @@ import org.springframework.stereotype.Component; | @@ -18,11 +18,11 @@ import org.springframework.stereotype.Component; | ||
18 | public class SmsUpMapperImpl extends InfluxDBQuery implements SmsUpMapper { | 18 | public class SmsUpMapperImpl extends InfluxDBQuery implements SmsUpMapper { |
19 | 19 | ||
20 | @Override | 20 | @Override |
21 | - public void insert(QcloudSmsUpBody qcloudSmsUpBody) { | 21 | + public void insert(QcloudVoiceUpBody qcloudSmsUpBody) { |
22 | BatchPoints batchPoints = BatchPoints | 22 | BatchPoints batchPoints = BatchPoints |
23 | .database(InfluxDBContants.YOMO_MONITOR).retentionPolicy("default") | 23 | .database(InfluxDBContants.YOMO_MONITOR).retentionPolicy("default") |
24 | .build(); | 24 | .build(); |
25 | - Point point = Point.measurement("sms_up") | 25 | + Point point = Point.measurement("voice_up") |
26 | .addField("result", qcloudSmsUpBody.getResult()) | 26 | .addField("result", qcloudSmsUpBody.getResult()) |
27 | .addField("callid", StringUtils.isBlank(qcloudSmsUpBody.getCallid()) ? " " : qcloudSmsUpBody.getCallid()) | 27 | .addField("callid", StringUtils.isBlank(qcloudSmsUpBody.getCallid()) ? " " : qcloudSmsUpBody.getCallid()) |
28 | .addField("mobile", StringUtils.isBlank(qcloudSmsUpBody.getMobile())?" ":qcloudSmsUpBody.getMobile()) | 28 | .addField("mobile", StringUtils.isBlank(qcloudSmsUpBody.getMobile())?" ":qcloudSmsUpBody.getMobile()) |
@@ -37,9 +37,26 @@ public class SmsUpMapperImpl extends InfluxDBQuery implements SmsUpMapper { | @@ -37,9 +37,26 @@ public class SmsUpMapperImpl extends InfluxDBQuery implements SmsUpMapper { | ||
37 | } | 37 | } |
38 | 38 | ||
39 | @Override | 39 | @Override |
40 | + public void insert(QcloudSmsUp qcloudSmsUp) { | ||
41 | + BatchPoints batchPoints = BatchPoints | ||
42 | + .database(InfluxDBContants.YOMO_MONITOR).retentionPolicy("default") | ||
43 | + .build(); | ||
44 | + Point point = Point.measurement("sms_up") | ||
45 | + .addField("sign", StringUtils.isBlank(qcloudSmsUp.getSign()) ? " " : qcloudSmsUp.getSign()) | ||
46 | + .addField("text", StringUtils.isBlank(qcloudSmsUp.getText()) ? " " : qcloudSmsUp.getText()) | ||
47 | + .addField("mobile", StringUtils.isBlank(qcloudSmsUp.getMobile())?" ":qcloudSmsUp.getMobile()) | ||
48 | + .addField("time", StringUtils.isBlank(qcloudSmsUp.getTime())?" ":qcloudSmsUp.getTime()) | ||
49 | + .addField("time", StringUtils.isBlank(qcloudSmsUp.getNationcode())?" ":qcloudSmsUp.getNationcode()) | ||
50 | + .addField("extend", StringUtils.isBlank(qcloudSmsUp.getExtend())?" ":qcloudSmsUp.getExtend()).build(); | ||
51 | + batchPoints.point(point); | ||
52 | + inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB() | ||
53 | + .write(batchPoints); | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
40 | public QueryResult select(int min) { | 57 | public QueryResult select(int min) { |
41 | 58 | ||
42 | - String command = "SELECT count(nationcode) FROM sms_up where time > now() - "+ min+"m and result = '0'"; | 59 | + String command = "SELECT count(text) FROM sms_up where time > now() - "+ min+"m"; |
43 | return query(InfluxDBContants.AWS, command, InfluxDBContants.YOMO_MONITOR); | 60 | return query(InfluxDBContants.AWS, command, InfluxDBContants.YOMO_MONITOR); |
44 | 61 | ||
45 | 62 |
1 | +package com.monitor.model.domain; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | + | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by zhengyouwei on 2016/12/19. | ||
9 | + */ | ||
10 | +@Data | ||
11 | +public class QcloudSms { | ||
12 | + | ||
13 | + private List<Tel> tel; | ||
14 | + | ||
15 | + private String type="0"; | ||
16 | + | ||
17 | + private String sig ; | ||
18 | + | ||
19 | + private String ext; | ||
20 | + | ||
21 | + private String msg; | ||
22 | + | ||
23 | + private String extend; | ||
24 | + | ||
25 | + public static class Tel{ | ||
26 | + private String nationcode="86"; | ||
27 | + | ||
28 | + private String phone; | ||
29 | + | ||
30 | + public String getNationcode() { | ||
31 | + return nationcode; | ||
32 | + } | ||
33 | + | ||
34 | + public void setNationcode(String nationcode) { | ||
35 | + this.nationcode = nationcode; | ||
36 | + } | ||
37 | + | ||
38 | + public String getPhone() { | ||
39 | + return phone; | ||
40 | + } | ||
41 | + | ||
42 | + public void setPhone(String phone) { | ||
43 | + this.phone = phone; | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | +} |
@@ -8,7 +8,17 @@ import lombok.Data; | @@ -8,7 +8,17 @@ import lombok.Data; | ||
8 | @Data | 8 | @Data |
9 | public class QcloudSmsUp { | 9 | public class QcloudSmsUp { |
10 | 10 | ||
11 | - private QcloudSmsUpBody voiceprompt_callback; | 11 | + private String nationcode; |
12 | + | ||
13 | + private String mobile; | ||
14 | + | ||
15 | + private String text; | ||
16 | + | ||
17 | + private String sign; | ||
18 | + | ||
19 | + private String time; | ||
20 | + | ||
21 | + private String extend; | ||
12 | 22 | ||
13 | 23 | ||
14 | } | 24 | } |
@@ -6,7 +6,7 @@ import lombok.Data; | @@ -6,7 +6,7 @@ import lombok.Data; | ||
6 | * Created by zhengyouwei on 2016/12/16. | 6 | * Created by zhengyouwei on 2016/12/16. |
7 | */ | 7 | */ |
8 | @Data | 8 | @Data |
9 | -public class QcloudSmsUpBody { | 9 | +public class QcloudVoiceUpBody { |
10 | 10 | ||
11 | private String result; | 11 | private String result; |
12 | private String callid; | 12 | private String callid; |
@@ -19,7 +19,7 @@ public class VoiceSmsNotice { | @@ -19,7 +19,7 @@ public class VoiceSmsNotice { | ||
19 | private String ext; | 19 | private String ext; |
20 | 20 | ||
21 | public static class Tel{ | 21 | public static class Tel{ |
22 | - private String nationcode; | 22 | + private String nationcode="86"; |
23 | 23 | ||
24 | private String phone; | 24 | private String phone; |
25 | 25 |
@@ -3,7 +3,7 @@ package com.monitor.other.smsUp; | @@ -3,7 +3,7 @@ package com.monitor.other.smsUp; | ||
3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
4 | import com.monitor.influxdb.mapper.SmsUpMapper; | 4 | import com.monitor.influxdb.mapper.SmsUpMapper; |
5 | import com.monitor.model.domain.QcloudSmsUp; | 5 | import com.monitor.model.domain.QcloudSmsUp; |
6 | -import com.monitor.model.request.SmsUp; | 6 | +import com.monitor.model.domain.QcloudVoiceUp; |
7 | import com.monitor.model.response.BaseResponse; | 7 | import com.monitor.model.response.BaseResponse; |
8 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
9 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
@@ -25,16 +25,32 @@ public class SmsUpctrl { | @@ -25,16 +25,32 @@ public class SmsUpctrl { | ||
25 | private SmsUpMapper smsUpMapper; | 25 | private SmsUpMapper smsUpMapper; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | - * 删除 | 28 | + * 语音上行 |
29 | * @return | 29 | * @return |
30 | */ | 30 | */ |
31 | - @RequestMapping("/smsup") | 31 | + @RequestMapping("/voiceUp") |
32 | @ResponseBody | 32 | @ResponseBody |
33 | - public BaseResponse smsup(@RequestBody QcloudSmsUp qcloudSmsUp) { | ||
34 | - logger.info("smsup req :{}", JSON.toJSONString(qcloudSmsUp)); | 33 | + public BaseResponse voiceUp(@RequestBody QcloudVoiceUp qcloudSmsUp) { |
34 | + logger.info("voiceUp req :{}", JSON.toJSONString(qcloudSmsUp)); | ||
35 | try { | 35 | try { |
36 | smsUpMapper.insert(qcloudSmsUp.getVoiceprompt_callback()); | 36 | smsUpMapper.insert(qcloudSmsUp.getVoiceprompt_callback()); |
37 | }catch (Exception e){ | 37 | }catch (Exception e){ |
38 | + logger.error("voiceUp",e); | ||
39 | + } | ||
40 | + return new BaseResponse(); | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * 短信上行 | ||
45 | + * @return | ||
46 | + */ | ||
47 | + @RequestMapping("/smsUp") | ||
48 | + @ResponseBody | ||
49 | + public BaseResponse smsUp(@RequestBody QcloudSmsUp qcloudSmsUp) { | ||
50 | + logger.info("smsup req :{}", JSON.toJSONString(qcloudSmsUp)); | ||
51 | + try { | ||
52 | + smsUpMapper.insert(qcloudSmsUp); | ||
53 | + }catch (Exception e){ | ||
38 | logger.error("smsup",e); | 54 | logger.error("smsup",e); |
39 | } | 55 | } |
40 | return new BaseResponse(); | 56 | return new BaseResponse(); |
@@ -49,24 +49,25 @@ public class AlarmSendVoiceTask { | @@ -49,24 +49,25 @@ public class AlarmSendVoiceTask { | ||
49 | DEBUG.info("alarmSendVoice task sms count = {}", count); | 49 | DEBUG.info("alarmSendVoice task sms count = {}", count); |
50 | 50 | ||
51 | 51 | ||
52 | - if (count > 5) {//大于无 | ||
53 | - //todo 查询是否需要语音通知 | 52 | + if (count > 5) {//大于5 |
54 | boolean needVoice = true; | 53 | boolean needVoice = true; |
55 | 54 | ||
56 | -// QueryResult queryResult1 = smsUpMapper.select(30); | ||
57 | -// int voiceCount = QueryResultUtil.getCount(queryResult1); | 55 | + QueryResult queryResult1 = smsUpMapper.select(30); |
56 | + int voiceCount = QueryResultUtil.getCount(queryResult1); | ||
58 | 57 | ||
59 | -// DEBUG.info("alarmSendVoice task sms voiceCount = {}", voiceCount); | 58 | + DEBUG.info("alarmSendVoice task sms voiceCount = {}", voiceCount); |
60 | 59 | ||
61 | -// if (voiceCount > 0) { | 60 | + if (voiceCount > 0) { |
61 | + needVoice = false; | ||
62 | + }else { | ||
62 | if (lastTime == 0) { | 63 | if (lastTime == 0) { |
63 | lastTime = now; | 64 | lastTime = now; |
64 | } else { | 65 | } else { |
65 | - if (now - lastTime < 10 * 60 * 1000) {//三十分钟内不再发送 | 66 | + if (now - lastTime < 10 * 60 * 1000) {//十分钟内不再发送 |
66 | needVoice = false; | 67 | needVoice = false; |
67 | } | 68 | } |
68 | } | 69 | } |
69 | -// } | 70 | + } |
70 | 71 | ||
71 | if (needVoice) { | 72 | if (needVoice) { |
72 | lastTime = now; | 73 | lastTime = now; |
1 | +package com.monitor.other.test; | ||
2 | + | ||
3 | +import com.model.DBWorkJob; | ||
4 | +import com.monitor.common.service.AlarmMsgService; | ||
5 | +import com.monitor.common.service.VoiceMsgService; | ||
6 | +import com.monitor.model.response.BaseResponse; | ||
7 | +import com.monitor.other.worksystem.service.DBService; | ||
8 | +import org.slf4j.Logger; | ||
9 | +import org.slf4j.LoggerFactory; | ||
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
11 | +import org.springframework.stereotype.Controller; | ||
12 | +import org.springframework.web.bind.annotation.RequestBody; | ||
13 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
15 | + | ||
16 | +/** | ||
17 | + * Created by zhengyouwei on 2016/10/11. | ||
18 | + * | ||
19 | + * 数据库工单 | ||
20 | + * | ||
21 | + */ | ||
22 | + | ||
23 | +@Controller | ||
24 | +@RequestMapping("/testCtrl") | ||
25 | +public class TestCtrl { | ||
26 | + | ||
27 | + Logger logger = LoggerFactory.getLogger(getClass()); | ||
28 | + | ||
29 | + @Autowired | ||
30 | + private AlarmMsgService alarmMsgService; | ||
31 | + | ||
32 | + @Autowired | ||
33 | + private VoiceMsgService voiceMsgService; | ||
34 | + | ||
35 | + | ||
36 | + @RequestMapping("/testSms") | ||
37 | + @ResponseBody | ||
38 | + public BaseResponse testSms() { | ||
39 | + try { | ||
40 | + alarmMsgService.sendSms("test","这是一条测试短信","15905144483"); | ||
41 | + | ||
42 | + }catch (Exception e){ | ||
43 | + logger.error("testSms ~",e); | ||
44 | + return new BaseResponse<>(); | ||
45 | + } | ||
46 | + return new BaseResponse(); | ||
47 | + } | ||
48 | + | ||
49 | + @RequestMapping("/testVoice") | ||
50 | + @ResponseBody | ||
51 | + public BaseResponse testVoice() { | ||
52 | + try { | ||
53 | + voiceMsgService.sendVoiceAlarm("15905144483"); | ||
54 | + }catch (Exception e){ | ||
55 | + logger.error("testSms ~",e); | ||
56 | + return new BaseResponse<>(); | ||
57 | + } | ||
58 | + return new BaseResponse(); | ||
59 | + } | ||
60 | + | ||
61 | +} |
@@ -4,6 +4,10 @@ sendsms.username=yohoyw | @@ -4,6 +4,10 @@ sendsms.username=yohoyw | ||
4 | sendsms.pwd=NCftHmJ9 | 4 | sendsms.pwd=NCftHmJ9 |
5 | sendsms.notice.productid=8 | 5 | sendsms.notice.productid=8 |
6 | 6 | ||
7 | +qcloud_voice_url=https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123 | ||
8 | +qcloud_sms_url=https://yun.tim.qq.com/v3/tlssmssvr/sendmultisms2?sdkappid=1400021400&random=124 | ||
9 | +qcloud_sms_key=6e56f948f6f1c0a1bc359e23f7acc140 | ||
10 | + | ||
7 | base_mobile=18751986615,18652008443,18502542319,15150509659,13515100825,18252034289 | 11 | base_mobile=18751986615,18652008443,18502542319,15150509659,13515100825,18252034289 |
8 | swaith_mobile=15905144483,18751986615 | 12 | swaith_mobile=15905144483,18751986615 |
9 | 13 |
@@ -3,6 +3,10 @@ sendsms.url=http://221.179.180.158:9009/HttpQuickProcess_utf-8/submitMessageAll | @@ -3,6 +3,10 @@ sendsms.url=http://221.179.180.158:9009/HttpQuickProcess_utf-8/submitMessageAll | ||
3 | #sendsms.username=yoho | 3 | #sendsms.username=yoho |
4 | #sendsms.pwd=E | 4 | #sendsms.pwd=E |
5 | 5 | ||
6 | +qcloud_voice_url=https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123 | ||
7 | +qcloud_sms_url=https://yun.tim.qq.com/v3/tlssmssvr/sendmultisms2?sdkappid=1400021400&random=124 | ||
8 | +qcloud_sms_key=6e56f948f6f1 | ||
9 | + | ||
6 | sendsms.username=yohoyw | 10 | sendsms.username=yohoyw |
7 | sendsms.pwd=NCftHmJ9 | 11 | sendsms.pwd=NCftHmJ9 |
8 | 12 |
-
Please register or login to post a comment