Authored by zhengyouwei

add

... ... @@ -144,27 +144,6 @@
<artifactId>fastjson</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>com.xuanwu</groupId>-->
<!--<artifactId>postmsg-ump</artifactId>-->
<!--<version>2.4.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.google.protobuf</groupId>-->
<!--<artifactId>protobuf-java</artifactId>-->
<!--<version>2.4.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>xpp3</groupId>-->
<!--<artifactId>xpp3_min</artifactId>-->
<!--<version>1.1.4c</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.thoughtworks.xstream</groupId>-->
<!--<artifactId>xstream</artifactId>-->
<!--<version>1.3.1</version>-->
<!--</dependency>-->
</dependencies>
</project>
\ No newline at end of file
... ...
package com.monitor.common.service.impl;
//import com.esms.MessageData;
//import com.esms.PostMsg;
//import com.esms.common.entity.Account;
//import com.esms.common.entity.GsmsResponse;
//import com.esms.common.entity.MTPack;
import com.alibaba.fastjson.JSON;
import com.monitor.common.service.HttpRestClientService;
import com.monitor.common.service.VoiceMsgService;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.UUID;
/**
* Created by zhengyouwei on 2016/12/16.
... ... @@ -37,40 +32,21 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
public void sendVoide(String mobile) throws UnsupportedEncodingException {
try {
// Account account = new Account("yoho@yoho", "yoho@9646");//
// PostMsg pm = new PostMsg();
// pm.getCmHost().setHost("211.147.239.62", 9050);//设置网关的IP和port,用于发送信息
// MTPack pack = new MTPack();
// pack.setBatchID(UUID.randomUUID());
// pack.setBatchName("语音短信");
// pack.setMsgType(MTPack.MsgType.VOICE_CODE);//设置语音发送类型
// pack.setBizType(0);//设置UMP配置的语音专用业务类型
// pack.setDistinctFlag(false);
// ArrayList<MessageData> msgs = new ArrayList<MessageData>();
//
// /** 群发,多号码一内容 */
// pack.setSendType(MTPack.SendType.MASS);
// String content = "ABCDEFG";//设置语音验证码内容
// msgs.add(MessageData.getInstance("15905144483", content));
//
// GsmsResponse resp = pm.post(account, pack);
VoiceSms voiceSms = new VoiceSms();
voiceSms.setMsg("YOHO");
voiceSms.setExt("nothing");
String[] mobiles = mobile.split(",");
for (String str : mobiles) {
VoiceSms.Tel tel = new VoiceSms.Tel();
tel.setNationcode("86");
tel.setPhone(str);
voiceSms.setSig(MD5Util.encryption("6e56f948f6f1c0a1bc359e23f7acc140"+str));
voiceSms.setTel(tel);
DEBUG.info("send voice msg,content:{}",JSON.toJSONString(voiceSms));
String result = httpRestClientService.doPostStringJson("https://yun.tim.qq.com/v3/tlsvoicesvr/sendvoice?sdkappid=1400021400&random=123", JSON.toJSONString(voiceSms));
}
// StringBuilder smsUrl = new StringBuilder();
// smsUrl.append("http://211.147.239.62:20510/cgi-bin/sendsms");
// smsUrl.append("?username=yoho@yoho");
// smsUrl.append("&password=yoho@9646");
// smsUrl.append("&to=");
// String[] mobiles = mobile.split(",");
// for (String str : mobiles) {
// smsUrl.append(str + " ");
// }
// smsUrl.append("&text=" + URLEncoder.encode("yoho", "GBK"));
// smsUrl.append("&subid=");
// smsUrl.append("&msgtype=9"); //msgtype:1 短信
// String result = httpRestClientService.doGet(smsUrl.toString(), null);
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", "yh", null, "");
} catch (Exception e) {
DEBUG.error("sendVoide error ", e);
... ...
package com.monitor.influxdb.mapper;
import com.monitor.model.domain.QcloudSmsUpBody;
import com.monitor.model.request.SmsUp;
import org.influxdb.dto.QueryResult;
... ... @@ -8,7 +9,7 @@ import org.influxdb.dto.QueryResult;
*/
public interface SmsUpMapper {
void insert(SmsUp smsUp);
void insert(QcloudSmsUpBody qcloudSmsUpBody);
QueryResult select(int min);
}
... ...
... ... @@ -100,8 +100,8 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar
@Override
public QueryResult selectVoiceAlarm(String influxDBName, int min) {
// String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m and type != 'work_system'";
String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m";
String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m and type != 'work_system'";
// String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m";
return query(influxDBName, command, InfluxDBContants.YOMO_MONITOR);
}
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper.impl;
import com.monitor.influxdb.InfluxDBQuery;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.SmsUpMapper;
import com.monitor.model.domain.QcloudSmsUpBody;
import com.monitor.model.request.SmsUp;
import org.apache.commons.lang.StringUtils;
import org.influxdb.dto.BatchPoints;
... ... @@ -17,18 +18,19 @@ import org.springframework.stereotype.Component;
public class SmsUpMapperImpl extends InfluxDBQuery implements SmsUpMapper {
@Override
public void insert(SmsUp smsUp) {
public void insert(QcloudSmsUpBody qcloudSmsUpBody) {
BatchPoints batchPoints = BatchPoints
.database(InfluxDBContants.YOMO_MONITOR).retentionPolicy("default")
.build();
Point point = Point.measurement("sms_up")
.addField("SmsType", smsUp.getSmsType())
.addField("SrcMobile", StringUtils.isBlank(smsUp.getSrcMobile())?" ":smsUp.getSrcMobile())
.addField("AppendID", StringUtils.isBlank(smsUp.getAppendID())?" ":smsUp.getAppendID())
.addField("Content", StringUtils.isBlank(smsUp.getContent())?" ":smsUp.getContent())
.addField("RecvTime", StringUtils.isBlank(smsUp.getRecvTime())?" ":smsUp.getRecvTime())
.addField("SendTime", StringUtils.isBlank(smsUp.getSendTime())?" ":smsUp.getSendTime())
.addField("Status", StringUtils.isBlank(smsUp.getStatus()) ? " " : smsUp.getStatus()).build();
.addField("result", qcloudSmsUpBody.getResult())
.addField("callid", StringUtils.isBlank(qcloudSmsUpBody.getCallid()) ? " " : qcloudSmsUpBody.getCallid())
.addField("mobile", StringUtils.isBlank(qcloudSmsUpBody.getMobile())?" ":qcloudSmsUpBody.getMobile())
.addField("nationcode", StringUtils.isBlank(qcloudSmsUpBody.getNationcode())?" ":qcloudSmsUpBody.getNationcode())
.addField("call_from", StringUtils.isBlank(qcloudSmsUpBody.getCall_from())?" ":qcloudSmsUpBody.getCall_from())
.addField("start_calltime", StringUtils.isBlank(qcloudSmsUpBody.getStart_calltime())?" ":qcloudSmsUpBody.getStart_calltime())
.addField("accept_time", StringUtils.isBlank(qcloudSmsUpBody.getAccept_time()) ? " " : qcloudSmsUpBody.getAccept_time())
.addField("fee", StringUtils.isBlank(qcloudSmsUpBody.getFee()) ? " " : qcloudSmsUpBody.getFee()).build();
batchPoints.point(point);
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
.write(batchPoints);
... ... @@ -37,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";
String command = "SELECT count(SrcMobile) FROM sms_up where time > now() - "+ min+"m and result = '0'";
return query(InfluxDBContants.AWS, command, InfluxDBContants.YOMO_MONITOR);
... ...
package com.monitor.model.domain;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Data
public class QcloudSmsUp {
private QcloudSmsUpBody voicecode_callback;
}
... ...
package com.monitor.model.domain;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/12/16.
*/
@Data
public class QcloudSmsUpBody {
private String result;
private String callid;
private String mobile;
private String nationcode;
private String call_from;
private String start_calltime;
private String end_calltime;
private String accept_time;
private String fee;
}
... ...
... ... @@ -10,15 +10,13 @@ public class VoiceSms {
private Tel tel;
private int prompttype;
private String promptfile;
private String msg;
private String sig ;
private String ext;
static class Tel{
public static class Tel{
private String nationcode;
private String phone;
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.other.smsUp;
import com.alibaba.fastjson.JSON;
import com.monitor.influxdb.mapper.SmsUpMapper;
import com.monitor.model.domain.QcloudSmsUp;
import com.monitor.model.request.SmsUp;
import com.monitor.model.response.BaseResponse;
import org.slf4j.Logger;
... ... @@ -29,10 +30,10 @@ public class SmsUpctrl {
*/
@RequestMapping("/smsup")
@ResponseBody
public BaseResponse smsup(@RequestBody SmsUp smsUp) {
logger.info("smsup req :{}", JSON.toJSONString(smsUp));
public BaseResponse smsup(@RequestBody QcloudSmsUp qcloudSmsUp) {
logger.info("smsup req :{}", JSON.toJSONString(qcloudSmsUp));
try {
smsUpMapper.insert(smsUp);
smsUpMapper.insert(qcloudSmsUp.getVoicecode_callback());
}catch (Exception e){
logger.error("smsup",e);
}
... ...
... ... @@ -37,7 +37,7 @@ public class AlarmSendVoiceTask {
try {
long now = System.currentTimeMillis();
QueryResult queryResult = monitorAlarmMapper.selectVoiceAlarm(InfluxDBContants.AWS, 120);
QueryResult queryResult = monitorAlarmMapper.selectVoiceAlarm(InfluxDBContants.AWS, 30);
int count = QueryResultUtil.getCount(queryResult);
if (count > 5){//大于无
//todo 查询是否需要语音通知
... ...