Authored by qinchao

语音报警升级

@@ -155,6 +155,12 @@ @@ -155,6 +155,12 @@
155 </dependency> 155 </dependency>
156 156
157 157
  158 + <dependency>
  159 + <groupId>com.github.qcloudsms</groupId>
  160 + <artifactId>qcloudsms</artifactId>
  161 + <version>1.0.5</version>
  162 + </dependency>
  163 +
158 </dependencies> 164 </dependencies>
159 165
160 </project> 166 </project>
1 package com.monitor.common.config; 1 package com.monitor.common.config;
2 2
  3 +import lombok.Data;
3 import org.springframework.beans.factory.annotation.Value; 4 import org.springframework.beans.factory.annotation.Value;
4 import org.springframework.stereotype.Component; 5 import org.springframework.stereotype.Component;
5 6
6 @Component("sendsmsConfig") 7 @Component("sendsmsConfig")
  8 +@Data
7 public class SendsmsConfig { 9 public class SendsmsConfig {
8 10
9 @Value("${sendsms.url}") 11 @Value("${sendsms.url}")
@@ -18,40 +20,17 @@ public class SendsmsConfig { @@ -18,40 +20,17 @@ public class SendsmsConfig {
18 @Value("${sendsms.notice.productid}") 20 @Value("${sendsms.notice.productid}")
19 private String noticeProductid;// 产品id 21 private String noticeProductid;// 产品id
20 22
  23 +
  24 + @Value("${qcloud_sms_sdkappid}")
  25 + private int qcloudSmsSdkAppId;
  26 +
21 @Value("${qcloud_sms_key}") 27 @Value("${qcloud_sms_key}")
22 private String qcloudSmsKey; 28 private String qcloudSmsKey;
23 29
24 @Value("${qcloud_sms_url}") 30 @Value("${qcloud_sms_url}")
25 private String qcloudSmsUrl; 31 private String qcloudSmsUrl;
26 32
27 - @Value("${qcloud_voice_url}")  
28 - private String qcloudVoiceUrl;  
29 -  
30 - public String getSendsmsUrl() {  
31 - return sendsmsUrl;  
32 - }  
33 -  
34 - public String getUserName() {  
35 - return userName;  
36 - }  
37 -  
38 - public String getPwd() {  
39 - return pwd;  
40 - }  
41 -  
42 - public String getNoticeProductid() {  
43 - return noticeProductid;  
44 - }  
45 -  
46 - public String getQcloudSmsUrl() {  
47 - return qcloudSmsUrl;  
48 - }  
49 -  
50 - public String getQcloudSmsKey() {  
51 - return qcloudSmsKey;  
52 - } 33 + //@Value("${qcloud_voice_url}")
  34 + //private String qcloudVoiceUrl;
53 35
54 - public String getQcloudVoiceUrl() {  
55 - return qcloudVoiceUrl;  
56 - }  
57 } 36 }
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.alibaba.fastjson.JSONObject;
  5 +import com.github.qcloudsms.SmsVoicePromptSender;
  6 +import com.github.qcloudsms.SmsVoicePromptSenderResult;
4 import com.monitor.common.config.SendsmsConfig; 7 import com.monitor.common.config.SendsmsConfig;
5 import com.monitor.common.contants.AlarmSystemConstant; 8 import com.monitor.common.contants.AlarmSystemConstant;
6 import com.monitor.common.service.DingDingService; 9 import com.monitor.common.service.DingDingService;
@@ -20,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
21 24
22 import java.io.UnsupportedEncodingException; 25 import java.io.UnsupportedEncodingException;
  26 +import java.util.Date;
23 27
24 /** 28 /**
25 * Created by zhengyouwei on 2016/12/16. 29 * Created by zhengyouwei on 2016/12/16.
@@ -70,27 +74,55 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { @@ -70,27 +74,55 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
70 } 74 }
71 75
72 try { 76 try {
73 - VoiceSmsNotice voiceSms = new VoiceSmsNotice(); 77 + String[] mobiles = mobile.split(",");
  78 + for (String str : mobiles) {
  79 + if(StringUtils.isBlank(str)){
  80 + continue;
  81 + }
  82 + DEBUG.info("send voice notice msg phone {} ,content:{}",str, promptfile );
  83 + SmsVoicePromptSender vpSender = new SmsVoicePromptSender(sendsmsConfig.getQcloudSmsSdkAppId(), sendsmsConfig.getQcloudSmsKey());
  84 + SmsVoicePromptSenderResult result = vpSender.send("86", str,
  85 + 2, 2, promptfile, "");
  86 + DEBUG.info("send voice notice msg,result:{}", result);
  87 +
  88 + //发送结果:result为0标识成功
  89 + boolean sendStatus = false;
  90 + if (result !=null ) {
  91 + try{
  92 + if(result.result==0){
  93 + sendStatus = true;
  94 + }
  95 + }catch (Exception e){
  96 +
  97 + }
  98 + }
  99 +
  100 + monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.Q_CLOUD, "voice", promptfile, "null", sendStatus ? "successed" : "faild", JSON.toJSONString(result),mobile, AlarmSystemConstant.SYSTEM_IDC);
  101 + }
74 102
  103 + /*VoiceSmsNotice voiceSms = new VoiceSmsNotice();
  104 + long time = new Date().getTime()/1000;
75 voiceSms.setPromptfile(promptfile); 105 voiceSms.setPromptfile(promptfile);
76 - voiceSms.setExt("nothing");  
77 - String[] mobiles = mobile.split(","); 106 + voiceSms.setTime(time);
  107 +
78 for (String str : mobiles) { 108 for (String str : mobiles) {
79 VoiceSmsNotice.Tel tel = new VoiceSmsNotice.Tel(); 109 VoiceSmsNotice.Tel tel = new VoiceSmsNotice.Tel();
80 tel.setPhone(str); 110 tel.setPhone(str);
  111 + tel.setMobile(str);
81 voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str)); 112 voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str));
82 voiceSms.setTel(tel); 113 voiceSms.setTel(tel);
83 DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms)); 114 DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms));
84 String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms)); 115 String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms));
85 DEBUG.info("send voice notice msg,result:{}", result); 116 DEBUG.info("send voice notice msg,result:{}", result);
86 monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.Q_CLOUD, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile, AlarmSystemConstant.SYSTEM_IDC); 117 monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.Q_CLOUD, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile, AlarmSystemConstant.SYSTEM_IDC);
87 - }  
88 -  
89 - dingDingService.insertMsg("yhops语音告警:"+promptfile); 118 + }*/
90 } catch (Exception e) { 119 } catch (Exception e) {
91 DEBUG.error("sendVoide notice error ", e); 120 DEBUG.error("sendVoide notice error ", e);
92 } 121 }
93 122
  123 + dingDingService.insertMsg("yhops语音告警:"+promptfile);
  124 +
  125 +
94 126
95 } 127 }
96 } 128 }
@@ -16,28 +16,18 @@ public class VoiceSmsNotice { @@ -16,28 +16,18 @@ public class VoiceSmsNotice {
16 16
17 private String sig ; 17 private String sig ;
18 18
19 - private String ext; 19 + //private String ext;
20 20
  21 + private long time;
  22 +
  23 + @Data
21 public static class Tel{ 24 public static class Tel{
22 private String nationcode="86"; 25 private String nationcode="86";
23 26
24 private String phone; 27 private String phone;
25 28
26 - public String getNationcode() {  
27 - return nationcode;  
28 - }  
29 -  
30 - public void setNationcode(String nationcode) {  
31 - this.nationcode = nationcode;  
32 - }  
33 -  
34 - public String getPhone() {  
35 - return phone;  
36 - } 29 + private String mobile;
37 30
38 - public void setPhone(String phone) {  
39 - this.phone = phone;  
40 - }  
41 } 31 }
42 32
43 33
@@ -3,6 +3,7 @@ package com.monitor.other.test; @@ -3,6 +3,7 @@ package com.monitor.other.test;
3 import com.monitor.common.service.AlarmMsgService; 3 import com.monitor.common.service.AlarmMsgService;
4 import com.monitor.common.service.VoiceMsgService; 4 import com.monitor.common.service.VoiceMsgService;
5 import com.monitor.model.response.BaseResponse; 5 import com.monitor.model.response.BaseResponse;
  6 +import org.apache.commons.lang.StringUtils;
6 import org.slf4j.Logger; 7 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,7 +35,7 @@ public class TestCtrl { @@ -34,7 +35,7 @@ public class TestCtrl {
34 @ResponseBody 35 @ResponseBody
35 public BaseResponse testSms() { 36 public BaseResponse testSms() {
36 try { 37 try {
37 - alarmMsgService.sendSms("test","这是一条测试短信","15905144483"); 38 + alarmMsgService.sendSms("test","这是一条测试短信","17314953523");
38 39
39 }catch (Exception e){ 40 }catch (Exception e){
40 logger.error("testSms ~",e); 41 logger.error("testSms ~",e);
@@ -45,9 +46,12 @@ public class TestCtrl { @@ -45,9 +46,12 @@ public class TestCtrl {
45 46
46 @RequestMapping("/testVoice") 47 @RequestMapping("/testVoice")
47 @ResponseBody 48 @ResponseBody
48 - public BaseResponse testVoice() { 49 + public BaseResponse testVoice(String mm) {
49 try { 50 try {
50 - voiceMsgService.sendVoiceAlarm("15905144483",""); 51 + if(StringUtils.isBlank(mm)){
  52 + mm = "17314953523";
  53 + }
  54 + voiceMsgService.sendVoiceAlarm(mm,"测试voice");
51 }catch (Exception e){ 55 }catch (Exception e){
52 logger.error("testSms ~",e); 56 logger.error("testSms ~",e);
53 return new BaseResponse<>(); 57 return new BaseResponse<>();
@@ -4,8 +4,9 @@ sendsms.username=yohoyw @@ -4,8 +4,9 @@ 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 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 8 qcloud_sms_url=https://yun.tim.qq.com/v3/tlssmssvr/sendmultisms2?sdkappid=1400021400&random=124
  9 +qcloud_sms_sdkappid=1400021400
9 qcloud_sms_key=6e56f948f6f1c0a1bc359e23f7acc140 10 qcloud_sms_key=6e56f948f6f1c0a1bc359e23f7acc140
10 11
11 java_service_alarm_flag=true 12 java_service_alarm_flag=true
@@ -4,9 +4,10 @@ sendsms.username=yohoyw @@ -4,9 +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 7 +# qcloud_voice_url=https://yun.tim.qq.com/v5/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123
8 qcloud_sms_url=https://yun.tim.qq.com/v3/tlssmssvr/sendmultisms2?sdkappid=1400021400&random=124 8 qcloud_sms_url=https://yun.tim.qq.com/v3/tlssmssvr/sendmultisms2?sdkappid=1400021400&random=124
9 -qcloud_sms_key=6e56f948f6f1 9 +qcloud_sms_sdkappid=1400021400
  10 +qcloud_sms_key=6e56f948
10 11
11 java_service_alarm_flag=true 12 java_service_alarm_flag=true
12 java_service_alarm_cost_threshold=150 13 java_service_alarm_cost_threshold=150