Commit 81fdd480 authored by qinxunjia's avatar qinxunjia

异常捕获,日志打印

parent db54dd3b
package com.jz.exception;
import com.jz.sms.config.ResponseCode;
public class ServiceException extends RuntimeException {
private static final long serialVersionUID = 1L;
private String msg;
private String code = "500";
public ServiceException(String msg) {
super(msg);
this.msg = msg;
}
public ServiceException(String msg, Throwable e) {
super(msg, e);
this.msg = msg;
}
public ServiceException(String msg, String code) {
super(msg);
this.msg = msg;
this.code = code;
}
public ServiceException(String msg, String code, Throwable e) {
super(msg, e);
this.msg = msg;
this.code = code;
}
public ServiceException(ResponseCode responseCode) {
super(responseCode.getMsg());
this.msg = responseCode.getMsg();
this.code = responseCode.getCode();
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
...@@ -27,6 +27,7 @@ public class ChuangLanApi { ...@@ -27,6 +27,7 @@ public class ChuangLanApi {
try { try {
chuangLanSmsService.asyncNotify(notifyInfo); chuangLanSmsService.asyncNotify(notifyInfo);
} catch (Exception e) { } catch (Exception e) {
log.error("处理创建模板异步通知异常:", e);
response = "fail"; response = "fail";
} }
log.info("创蓝异步通知接口出参:{}", response); log.info("创蓝异步通知接口出参:{}", response);
...@@ -40,6 +41,7 @@ public class ChuangLanApi { ...@@ -40,6 +41,7 @@ public class ChuangLanApi {
try { try {
CLBizResponse responses = chuangLanSmsService.report(report); CLBizResponse responses = chuangLanSmsService.report(report);
} catch (Exception e) { } catch (Exception e) {
log.error("处理回执逻辑异常:", e);
response = "fail"; response = "fail";
} }
log.info("创蓝异步通知接口出参:{}", response); log.info("创蓝异步通知接口出参:{}", response);
......
...@@ -32,6 +32,7 @@ public class DmHubApi { ...@@ -32,6 +32,7 @@ public class DmHubApi {
try { try {
template = messageService.createTemplate(params); template = messageService.createTemplate(params);
} catch (Exception e) { } catch (Exception e) {
log.error("创建模板短信异常", e);
template = new DmHubTemplateResponse(ResponseCode.SYSTEM_ERROR); template = new DmHubTemplateResponse(ResponseCode.SYSTEM_ERROR);
} }
log.info("**********创建模板接口出参*******:{}", JSONObject.toJSONString(template)); log.info("**********创建模板接口出参*******:{}", JSONObject.toJSONString(template));
...@@ -51,13 +52,13 @@ public class DmHubApi { ...@@ -51,13 +52,13 @@ public class DmHubApi {
try { try {
response = messageService.batchSend(request); response = messageService.batchSend(request);
} catch (Exception e) { } catch (Exception e) {
log.error("发送批量短信异常", e);
response = new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); response = new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
log.info("**********批量发送出参*******:{}", response); log.info("**********批量发送出参*******:{}", response);
return response; return response;
} }
/** /**
* 发送单条(通知或营销类) * 发送单条(通知或营销类)
* *
...@@ -69,8 +70,8 @@ public class DmHubApi { ...@@ -69,8 +70,8 @@ public class DmHubApi {
DmHubSendResponse response; DmHubSendResponse response;
try { try {
response = messageService.send(request); response = messageService.send(request);
} catch (Exception e) { } catch (Exception e) {
log.error("发送单条短信异常", e);
response = new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); response = new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
log.info("**********单条发送出参*******:{}", JSONObject.toJSONString(response)); log.info("**********单条发送出参*******:{}", JSONObject.toJSONString(response));
......
...@@ -113,4 +113,21 @@ public class ReportDto { ...@@ -113,4 +113,21 @@ public class ReportDto {
public void setStatusDesc(String statusDesc) { public void setStatusDesc(String statusDesc) {
this.statusDesc = statusDesc; this.statusDesc = statusDesc;
} }
@Override
public String toString() {
return "ReportDto{" +
"receiver='" + receiver + '\'' +
", pswd='" + pswd + '\'' +
", msgid='" + msgid + '\'' +
", reportTime='" + reportTime + '\'' +
", mobile='" + mobile + '\'' +
", notifyTime='" + notifyTime + '\'' +
", uid='" + uid + '\'' +
", length='" + length + '\'' +
", status='" + status + '\'' +
", statusDesc='" + statusDesc + '\'' +
'}';
}
} }
...@@ -4,6 +4,7 @@ package com.jz.sms.channel.chuanglan.service.impl; ...@@ -4,6 +4,7 @@ package com.jz.sms.channel.chuanglan.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jz.util.HttpUtil;
import com.jz.sms.channel.chuanglan.dto.*; import com.jz.sms.channel.chuanglan.dto.*;
import com.jz.sms.channel.chuanglan.service.ChuangLanSmsService; import com.jz.sms.channel.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.channel.chuanglan.utils.ChuangLanSmsUtil; import com.jz.sms.channel.chuanglan.utils.ChuangLanSmsUtil;
...@@ -12,8 +13,7 @@ import com.jz.sms.config.ResponseCode; ...@@ -12,8 +13,7 @@ import com.jz.sms.config.ResponseCode;
import com.jz.sms.channel.dmHub.service.DmHubService; import com.jz.sms.channel.dmHub.service.DmHubService;
import com.jz.sms.repository.domain.SmsTemplateInfo; import com.jz.sms.repository.domain.SmsTemplateInfo;
import com.jz.sms.service.SmsTemplateService; import com.jz.sms.service.SmsTemplateService;
import com.jz.sms.util.HttpUtil; import com.jz.util.Md5Util;
import com.jz.sms.util.Md5Util;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -22,8 +22,6 @@ import org.springframework.stereotype.Service; ...@@ -22,8 +22,6 @@ import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")
...@@ -54,7 +52,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -54,7 +52,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
appId = "52"; appId = "52";
content = content.replaceAll("回TD退订", ""); content = content.replaceAll("回TD退订", "");
} else { } else {
// TODO 自定义异常,发送警告 // TODO 发送警告
log.error("错误,传入的模板类型未知,类型为:{}", type); log.error("错误,传入的模板类型未知,类型为:{}", type);
return new CLBizResponse(ResponseCode.SYSTEM_ERROR, "未知的模板类型:" + type, 0); return new CLBizResponse(ResponseCode.SYSTEM_ERROR, "未知的模板类型:" + type, 0);
} }
...@@ -176,7 +174,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -176,7 +174,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
if (!"1".equals(status)) { if (!"1".equals(status)) {
String msg = notifyInfo.getAuditReason(); String msg = notifyInfo.getAuditReason();
boolean update = templateService.updateForSet("status = abnormal,up_reject_msg = " + msg, new EntityWrapper<SmsTemplateInfo>().eq("up_template_id", id)); boolean update = templateService.updateForSet("status = abnormal,up_reject_msg = " + msg, new EntityWrapper<SmsTemplateInfo>().eq("up_template_id", id));
// TODO 发送钉钉告警 // TODO 发送告警
log.error("短信模板审核不通过,原因:{}", msg); log.error("短信模板审核不通过,原因:{}", msg);
} }
return new CLBizResponse(ResponseCode.SUCCESS); return new CLBizResponse(ResponseCode.SUCCESS);
...@@ -184,10 +182,9 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -184,10 +182,9 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
@Override @Override
public CLBizResponse report(ReportDto report) throws Exception{ public CLBizResponse report(ReportDto report) throws Exception {
// TODO 状态报告要特殊处理,一个个接受,批量发送 // TODO 状态报告要特殊处理,一个个接受,批量发送(处理方式待定)
String uid = report.getUid(); dmHubService.smsReport(report);
Map<String, Object> ret = dmHubService.smsReport(report);
return new CLBizResponse(ResponseCode.SUCCESS); return new CLBizResponse(ResponseCode.SUCCESS);
} }
......
...@@ -11,7 +11,7 @@ public interface DmHubService { ...@@ -11,7 +11,7 @@ public interface DmHubService {
* *
* @return token信息 * @return token信息
*/ */
String getToken() throws Exception; String getToken() ;
/** /**
......
...@@ -6,8 +6,8 @@ import com.jz.sms.channel.dmHub.config.DmHubConfig; ...@@ -6,8 +6,8 @@ import com.jz.sms.channel.dmHub.config.DmHubConfig;
import com.jz.sms.channel.dmHub.service.DmHubService; import com.jz.sms.channel.dmHub.service.DmHubService;
import com.jz.sms.channel.dto.DmhubReport; import com.jz.sms.channel.dto.DmhubReport;
import com.jz.sms.channel.dto.ReportDetail; import com.jz.sms.channel.dto.ReportDetail;
import com.jz.sms.util.HttpUtil; import com.jz.util.HttpUtil;
import com.jz.sms.util.OkHttpUtil; import com.jz.util.OkHttpUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -34,7 +34,8 @@ public class DmHubServiceImpl implements DmHubService { ...@@ -34,7 +34,8 @@ public class DmHubServiceImpl implements DmHubService {
@Override @Override
public String getToken() throws Exception { public String getToken() {
try {
String token = redisTemplate.opsForValue().get(TOKEN_KEY).toString(); String token = redisTemplate.opsForValue().get(TOKEN_KEY).toString();
Long expire = redisTemplate.opsForValue().getOperations().getExpire(TOKEN_KEY); Long expire = redisTemplate.opsForValue().getOperations().getExpire(TOKEN_KEY);
if (expire != null && expire > 0L) { if (expire != null && expire > 0L) {
...@@ -55,18 +56,25 @@ public class DmHubServiceImpl implements DmHubService { ...@@ -55,18 +56,25 @@ public class DmHubServiceImpl implements DmHubService {
if ("0".equals(errorCode)) { if ("0".equals(errorCode)) {
String accessToken = retJson.getString("access_token"); String accessToken = retJson.getString("access_token");
String expires = retJson.getString("expires_in"); String expires = retJson.getString("expires_in");
redisTemplate.opsForValue().set("DM_HUB_TOKEN", accessToken, Long.parseLong(expires) - 600L, TimeUnit.SECONDS); long exTime = Long.parseLong(expires) - 60 * 10L;
redisTemplate.opsForValue().set(TOKEN_KEY, accessToken, exTime, TimeUnit.SECONDS);
return accessToken; return accessToken;
} else { } else {
// TODO 系统告警,获取API接口TOKEN失败。 // TODO 系统告警,获取API接口TOKEN失败。
return null; return null;
} }
} }
} catch (Exception e) {
log.error("获取API接口TOKEN业务逻辑异常,异常信息:\r\n", e);
return null;
}
} }
@Override @Override
public Map<String, Object> smsReport(ReportDto dto) throws Exception { public Map<String, Object> smsReport(ReportDto dto) throws Exception {
try {
String token = getToken(); String token = getToken();
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {
return null; return null;
...@@ -92,6 +100,12 @@ public class DmHubServiceImpl implements DmHubService { ...@@ -92,6 +100,12 @@ public class DmHubServiceImpl implements DmHubService {
String retStr = HttpUtil.sendPost(DmHubConfig.report, JSONObject.toJSONString(report)); String retStr = HttpUtil.sendPost(DmHubConfig.report, JSONObject.toJSONString(report));
log.info("短信状态回执响应:{}", retStr); log.info("短信状态回执响应:{}", retStr);
//TODO 目前没有测试环境的请求地址 //TODO 目前没有测试环境的请求地址
} catch (Exception e) {
log.info("发送短信回执到DMHub异常\r\n短信信息:{},\r\n,异常:", dto, e);
}
return null; return null;
} }
} }
...@@ -14,7 +14,7 @@ import com.jz.sms.service.DmBatchService; ...@@ -14,7 +14,7 @@ import com.jz.sms.service.DmBatchService;
import com.jz.sms.service.MessageService; import com.jz.sms.service.MessageService;
import com.jz.sms.service.SmsTemplateService; import com.jz.sms.service.SmsTemplateService;
import com.jz.sms.service.bean.TemplateChangeBean; import com.jz.sms.service.bean.TemplateChangeBean;
import com.jz.sms.util.id.IdHandler; import com.jz.util.id.IdHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -96,11 +96,10 @@ public class MessageServiceImpl implements MessageService { ...@@ -96,11 +96,10 @@ public class MessageServiceImpl implements MessageService {
return responseDTO; return responseDTO;
} else { } else {
//TODO 发送告警,模板添加失败。 //TODO 发送告警,模板添加失败。
return new DmHubTemplateResponse(template.getCode(), template.getMsg()); return new DmHubTemplateResponse(template.getCode(), template.getMsg());
} }
} catch (Exception exception) { } catch (Exception exception) {
log.error("错误信息", exception); log.error("创建模板业务逻辑异常,错误信息", exception);
responseDTO = new DmHubTemplateResponse("500", "系统异常"); responseDTO = new DmHubTemplateResponse("500", "系统异常");
} }
return responseDTO; return responseDTO;
...@@ -115,7 +114,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -115,7 +114,7 @@ public class MessageServiceImpl implements MessageService {
* @return * @return
*/ */
public TemplateChangeBean dmHub2ChuangLanSend(String content) { public TemplateChangeBean dmHub2ChuangLanSend(String content) {
// String regex = "\\$\\{[^}]+\\}"; //正则获取${***} 和 ${surl***'}格式的内容,其中:((?:\$\{surl.*'\}))獲取${surl***'}格式,\$\{[^}]+\} 获取${***}格式,顺序不能变,否则不能完成匹配格式一
String regex = "((?:\\$\\{surl.*'\\}))|\\$\\{[^}]+\\}"; String regex = "((?:\\$\\{surl.*'\\}))|\\$\\{[^}]+\\}";
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(content); Matcher matcher = pattern.matcher(content);
......
package com.jz.sms.util;
public class DateUtil {
}
package com.jz.sms.util; package com.jz.util;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.CloseableHttpClient; ...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HTTP;
import sun.net.www.http.HttpClient;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
......
package com.jz.sms.util; package com.jz.util;
import java.security.MessageDigest; import java.security.MessageDigest;
......
package com.jz.sms.util; package com.jz.util;
import com.baomidou.mybatisplus.toolkit.MapUtils; import com.baomidou.mybatisplus.toolkit.MapUtils;
import okhttp3.*; import okhttp3.*;
......
package com.jz.sms.util.id; package com.jz.util.id;
import java.text.ParseException; import java.text.ParseException;
......
package com.jz.sms.util.id; package com.jz.util.id;
public class IdHandler { public class IdHandler {
......
package com.jz.sms.util.id; package com.jz.util.id;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment