Authored by zhengyouwei

a

... ... @@ -7,5 +7,8 @@ import java.io.UnsupportedEncodingException;
*/
public interface VoiceMsgService {
void sendVoide(String mobile) throws UnsupportedEncodingException;
void sendVoice(String mobile) throws UnsupportedEncodingException;
void sendVoiceAlarm(String mobile) throws UnsupportedEncodingException;
}
... ...
... ... @@ -14,6 +14,7 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Map;
@Service("httpRestClientService")
... ... @@ -33,7 +34,7 @@ public class HttpRestClientServiceImpl implements HttpRestClientService {
public String doPostStringJson(String url, String args) {
try {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setContentType(new MediaType("application" ,"json", Charset.forName("UTF-8")));
HttpEntity<String> entity = new HttpEntity<String>(args, headers);
String result = restTemplate.postForObject(url, entity,
String.class);
... ...
... ... @@ -7,6 +7,7 @@ import com.monitor.common.util.MD5Util;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.MonitorAlarmMapper;
import com.monitor.model.domain.VoiceSms;
import com.monitor.model.domain.VoiceSmsNotice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -29,7 +30,7 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
public final Logger DEBUG = LoggerFactory.getLogger(getClass());
@Override
public void sendVoide(String mobile) throws UnsupportedEncodingException {
public void sendVoice(String mobile) throws UnsupportedEncodingException {
try {
... ... @@ -54,4 +55,31 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
}
@Override
public void sendVoiceAlarm(String mobile) throws UnsupportedEncodingException {
try {
VoiceSmsNotice voiceSms = new VoiceSmsNotice();
voiceSms.setPromptfile("请及时处理故障:紧急故障");
voiceSms.setExt("nothing");
String[] mobiles = mobile.split(",");
for (String str : mobiles) {
VoiceSmsNotice.Tel tel = new VoiceSmsNotice.Tel();
tel.setNationcode("86");
tel.setPhone(str);
voiceSms.setSig(MD5Util.encryption("6e56f948f6f1c0a1bc359e23f7acc140" + str));
voiceSms.setTel(tel);
DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms));
String result = httpRestClientService.doPostStringJson("https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoiceprompt?sdkappid=1400021400&random=123", JSON.toJSONString(voiceSms));
DEBUG.info("send voice notice msg,result:{}", result);
}
} catch (Exception e) {
DEBUG.error("sendVoide notice error ", e);
}
}
}
... ...
... ... @@ -25,11 +25,14 @@
<property name="readTimeout" value="30000" />
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg ref="clientHttpRequestFactory" />
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
</bean>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
... ...
... ... @@ -39,7 +39,7 @@ public class SmsUpMapperImpl extends InfluxDBQuery implements SmsUpMapper {
@Override
public QueryResult select(int min) {
String command = "SELECT count(SrcMobile) FROM sms_up where time > now() - "+ min+"m and result = '0'";
String command = "SELECT count(nationcode) FROM sms_up where time > now() - "+ min+"m and result = '0'";
return query(InfluxDBContants.AWS, command, InfluxDBContants.YOMO_MONITOR);
... ...
... ... @@ -8,7 +8,7 @@ import lombok.Data;
@Data
public class QcloudSmsUp {
private QcloudSmsUpBody voicecode_callback;
private QcloudSmsUpBody voiceprompt_callback;
}
... ...
package com.monitor.model.domain;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Data
public class VoiceSmsNotice {
private Tel tel;
private String promptfile;
private int prompttype = 2;
private String sig ;
private String ext;
public static class Tel{
private String nationcode;
private String phone;
public String getNationcode() {
return nationcode;
}
public void setNationcode(String nationcode) {
this.nationcode = nationcode;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
}
... ...
... ... @@ -33,7 +33,7 @@ public class SmsUpctrl {
public BaseResponse smsup(@RequestBody QcloudSmsUp qcloudSmsUp) {
logger.info("smsup req :{}", JSON.toJSONString(qcloudSmsUp));
try {
smsUpMapper.insert(qcloudSmsUp.getVoicecode_callback());
smsUpMapper.insert(qcloudSmsUp.getVoiceprompt_callback());
}catch (Exception e){
logger.error("smsup",e);
}
... ...
... ... @@ -70,7 +70,7 @@ public class AlarmSendVoiceTask {
if (needVoice) {
lastTime = now;
voiceMsgService.sendVoide(snsMobileConfig.getBaseMobile());
voiceMsgService.sendVoiceAlarm(snsMobileConfig.getBaseMobile());
}
}
... ...