Authored by qinchao

语音报警升级

... ... @@ -155,6 +155,12 @@
</dependency>
<dependency>
<groupId>com.github.qcloudsms</groupId>
<artifactId>qcloudsms</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.monitor.common.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component("sendsmsConfig")
@Data
public class SendsmsConfig {
@Value("${sendsms.url}")
... ... @@ -18,40 +20,17 @@ public class SendsmsConfig {
@Value("${sendsms.notice.productid}")
private String noticeProductid;// 产品id
@Value("${qcloud_sms_sdkappid}")
private int qcloudSmsSdkAppId;
@Value("${qcloud_sms_key}")
private String qcloudSmsKey;
@Value("${qcloud_sms_url}")
private String qcloudSmsUrl;
@Value("${qcloud_voice_url}")
private String qcloudVoiceUrl;
public String getSendsmsUrl() {
return sendsmsUrl;
}
public String getUserName() {
return userName;
}
public String getPwd() {
return pwd;
}
public String getNoticeProductid() {
return noticeProductid;
}
public String getQcloudSmsUrl() {
return qcloudSmsUrl;
}
public String getQcloudSmsKey() {
return qcloudSmsKey;
}
//@Value("${qcloud_voice_url}")
//private String qcloudVoiceUrl;
public String getQcloudVoiceUrl() {
return qcloudVoiceUrl;
}
}
... ...
package com.monitor.common.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.qcloudsms.SmsVoicePromptSender;
import com.github.qcloudsms.SmsVoicePromptSenderResult;
import com.monitor.common.config.SendsmsConfig;
import com.monitor.common.contants.AlarmSystemConstant;
import com.monitor.common.service.DingDingService;
... ... @@ -20,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.Date;
/**
* Created by zhengyouwei on 2016/12/16.
... ... @@ -70,27 +74,55 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
}
try {
VoiceSmsNotice voiceSms = new VoiceSmsNotice();
String[] mobiles = mobile.split(",");
for (String str : mobiles) {
if(StringUtils.isBlank(str)){
continue;
}
DEBUG.info("send voice notice msg phone {} ,content:{}",str, promptfile );
SmsVoicePromptSender vpSender = new SmsVoicePromptSender(sendsmsConfig.getQcloudSmsSdkAppId(), sendsmsConfig.getQcloudSmsKey());
SmsVoicePromptSenderResult result = vpSender.send("86", str,
2, 2, promptfile, "");
DEBUG.info("send voice notice msg,result:{}", result);
//发送结果:result为0标识成功
boolean sendStatus = false;
if (result !=null ) {
try{
if(result.result==0){
sendStatus = true;
}
}catch (Exception e){
}
}
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.Q_CLOUD, "voice", promptfile, "null", sendStatus ? "successed" : "faild", JSON.toJSONString(result),mobile, AlarmSystemConstant.SYSTEM_IDC);
}
/*VoiceSmsNotice voiceSms = new VoiceSmsNotice();
long time = new Date().getTime()/1000;
voiceSms.setPromptfile(promptfile);
voiceSms.setExt("nothing");
String[] mobiles = mobile.split(",");
voiceSms.setTime(time);
for (String str : mobiles) {
VoiceSmsNotice.Tel tel = new VoiceSmsNotice.Tel();
tel.setPhone(str);
tel.setMobile(str);
voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str));
voiceSms.setTel(tel);
DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms));
String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms));
DEBUG.info("send voice notice msg,result:{}", result);
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.Q_CLOUD, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile, AlarmSystemConstant.SYSTEM_IDC);
}
dingDingService.insertMsg("yhops语音告警:"+promptfile);
}*/
} catch (Exception e) {
DEBUG.error("sendVoide notice error ", e);
}
dingDingService.insertMsg("yhops语音告警:"+promptfile);
}
}
... ...
... ... @@ -16,28 +16,18 @@ public class VoiceSmsNotice {
private String sig ;
private String ext;
//private String ext;
private long time;
@Data
public static class Tel{
private String nationcode="86";
private String phone;
public String getNationcode() {
return nationcode;
}
public void setNationcode(String nationcode) {
this.nationcode = nationcode;
}
public String getPhone() {
return phone;
}
private String mobile;
public void setPhone(String phone) {
this.phone = phone;
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.other.test;
import com.monitor.common.service.AlarmMsgService;
import com.monitor.common.service.VoiceMsgService;
import com.monitor.model.response.BaseResponse;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -34,7 +35,7 @@ public class TestCtrl {
@ResponseBody
public BaseResponse testSms() {
try {
alarmMsgService.sendSms("test","这是一条测试短信","15905144483");
alarmMsgService.sendSms("test","这是一条测试短信","17314953523");
}catch (Exception e){
logger.error("testSms ~",e);
... ... @@ -45,9 +46,12 @@ public class TestCtrl {
@RequestMapping("/testVoice")
@ResponseBody
public BaseResponse testVoice() {
public BaseResponse testVoice(String mm) {
try {
voiceMsgService.sendVoiceAlarm("15905144483","");
if(StringUtils.isBlank(mm)){
mm = "17314953523";
}
voiceMsgService.sendVoiceAlarm(mm,"测试voice");
}catch (Exception e){
logger.error("testSms ~",e);
return new BaseResponse<>();
... ...
... ... @@ -4,8 +4,9 @@ sendsms.username=yohoyw
sendsms.pwd=NCftHmJ9
sendsms.notice.productid=8
qcloud_voice_url=https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123
# qcloud_voice_url=https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123
qcloud_sms_url=https://yun.tim.qq.com/v3/tlssmssvr/sendmultisms2?sdkappid=1400021400&random=124
qcloud_sms_sdkappid=1400021400
qcloud_sms_key=6e56f948f6f1c0a1bc359e23f7acc140
java_service_alarm_flag=true
... ...
... ... @@ -4,9 +4,10 @@ sendsms.username=yohoyw
sendsms.pwd=NCftHmJ9
sendsms.notice.productid=8
qcloud_voice_url=https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123
# qcloud_voice_url=https://yun.tim.qq.com/v5/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123
qcloud_sms_url=https://yun.tim.qq.com/v3/tlssmssvr/sendmultisms2?sdkappid=1400021400&random=124
qcloud_sms_key=6e56f948f6f1
qcloud_sms_sdkappid=1400021400
qcloud_sms_key=6e56f948
java_service_alarm_flag=true
java_service_alarm_cost_threshold=150
... ...