Commit 9eb6393b authored by qinxunjia's avatar qinxunjia

规范接口

parent 561456b1
...@@ -79,6 +79,22 @@ ...@@ -79,6 +79,22 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>dmhub-plugin</finalName> <finalName>dmhub-plugin</finalName>
......
...@@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory; ...@@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController @RestController
@RequestMapping("/test") @RequestMapping("/test")
public class BizController { public class BizController {
...@@ -41,9 +39,9 @@ public class BizController { ...@@ -41,9 +39,9 @@ public class BizController {
* @return * @return
*/ */
@PostMapping("/sms/batch") @PostMapping("/sms/batch")
public DmHubBatchSendResponse batch(@RequestBody DmHubBatchSendRequest request) { public DmHubSendResponse batch(@RequestBody DmHubBatchSendRequest request) {
log.info("**********批量发送入参*******:{}", JSONObject.toJSONString(request)); log.info("**********批量发送入参*******:{}", JSONObject.toJSONString(request));
DmHubBatchSendResponse response = messageService.batchSend(request); DmHubSendResponse response = messageService.batchSend(request);
// log.info("**********批量发送入参*******:{}", response); // log.info("**********批量发送入参*******:{}", response);
return response; return response;
} }
......
package com.jz.sms.api; package com.jz.sms.api;
import com.jz.sms.chuanglan.dto.CLBizResponse;
import com.jz.sms.chuanglan.dto.CLNotifyRequest; import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.dto.ReportDto; import com.jz.sms.chuanglan.dto.ReportDto;
import com.jz.sms.chuanglan.service.ChuangLanSmsService; import com.jz.sms.chuanglan.service.ChuangLanSmsService;
...@@ -40,8 +41,7 @@ public class ChuangLanApi { ...@@ -40,8 +41,7 @@ public class ChuangLanApi {
public String report(@RequestParam ReportDto report) { public String report(@RequestParam ReportDto report) {
log.info("回送报告接口入参:{}", report); log.info("回送报告接口入参:{}", report);
chuangLanSmsService.report(report); CLBizResponse responses = chuangLanSmsService.report(report);
String response = "success"; String response = "success";
log.info("创蓝异步通知接口出参:{}", response); log.info("创蓝异步通知接口出参:{}", response);
......
package com.jz.sms.chuanglan.dto; package com.jz.sms.chuanglan.dto;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.config.ResponseCode; import com.jz.sms.config.ResponseCode;
import java.io.Serializable; import java.io.Serializable;
public class CLTemplateResponse implements Serializable { public class CLBizResponse implements Serializable {
private String code; private String code;
...@@ -13,28 +14,40 @@ public class CLTemplateResponse implements Serializable { ...@@ -13,28 +14,40 @@ public class CLTemplateResponse implements Serializable {
private String id; private String id;
public CLTemplateResponse() { private JSONObject data;
public CLBizResponse() {
} }
public CLTemplateResponse(ResponseCode responseCode, String id) { public CLBizResponse(ResponseCode responseCode) {
this.code = responseCode.getCode();
this.msg = responseCode.getMsg();
}
public CLBizResponse(ResponseCode responseCode,JSONObject data) {
this.code = responseCode.getCode();
this.msg = responseCode.getMsg();
this.data = data;
}
public CLBizResponse(ResponseCode responseCode, String id) {
this.code = responseCode.getCode(); this.code = responseCode.getCode();
this.msg = responseCode.getMsg(); this.msg = responseCode.getMsg();
this.id = id; this.id = id;
} }
public CLTemplateResponse(ResponseCode responseCode, String msg,int nullInfo) { public CLBizResponse(ResponseCode responseCode, String msg, int nullInfo) {
this.code = responseCode.getCode(); this.code = responseCode.getCode();
this.msg = responseCode.getMsg()+msg; this.msg = responseCode.getMsg()+msg;
} }
public CLTemplateResponse(String code, String msg) { public CLBizResponse(String code, String msg) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
} }
public CLTemplateResponse(String code, String msg, String id) { public CLBizResponse(String code, String msg, String id) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
this.id = id; this.id = id;
...@@ -61,6 +74,15 @@ public class CLTemplateResponse implements Serializable { ...@@ -61,6 +74,15 @@ public class CLTemplateResponse implements Serializable {
} }
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public JSONObject getData() {
return data;
}
public void setData(JSONObject data) {
this.data = data;
}
} }
...@@ -18,6 +18,10 @@ public class CLSendSMSResponse { ...@@ -18,6 +18,10 @@ public class CLSendSMSResponse {
*/ */
private String code; private String code;
private String failNum;
private String successNum;
public CLSendSMSResponse(){} public CLSendSMSResponse(){}
...@@ -58,6 +62,22 @@ public class CLSendSMSResponse { ...@@ -58,6 +62,22 @@ public class CLSendSMSResponse {
this.code = code; this.code = code;
} }
public String getFailNum() {
return failNum;
}
public void setFailNum(String failNum) {
this.failNum = failNum;
}
public String getSuccessNum() {
return successNum;
}
public void setSuccessNum(String successNum) {
this.successNum = successNum;
}
@Override @Override
public String toString() { public String toString() {
return "SmsSingleResponse [time=" + time + ", msgId=" + msgId + ", errorMsg=" + errorMsg + ", code=" + code return "SmsSingleResponse [time=" + time + ", msgId=" + msgId + ", errorMsg=" + errorMsg + ", code=" + code
......
...@@ -58,6 +58,16 @@ public class CLSendVariableRequest { ...@@ -58,6 +58,16 @@ public class CLSendVariableRequest {
this.report = report; this.report = report;
} }
public CLSendVariableRequest(String account, String password, String msg, String params, String report,String uid) {
super();
this.account = account;
this.password = password;
this.msg = msg;
this.params = params;
this.report = report;
this.uid = uid;
}
// public SmsVarableRequest(String account, String password, String msg, String params, String sendtime) { // public SmsVarableRequest(String account, String password, String msg, String params, String sendtime) {
// super(); // super();
// this.account = account; // this.account = account;
......
...@@ -2,22 +2,21 @@ package com.jz.sms.chuanglan.service; ...@@ -2,22 +2,21 @@ package com.jz.sms.chuanglan.service;
import com.jz.sms.chuanglan.dto.CLNotifyRequest; import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.dto.CLSendSMSResponse; import com.jz.sms.chuanglan.dto.CLSendSMSResponse;
import com.jz.sms.chuanglan.dto.CLTemplateResponse; import com.jz.sms.chuanglan.dto.CLBizResponse;
import com.jz.sms.chuanglan.dto.ReportDto; import com.jz.sms.chuanglan.dto.ReportDto;
import com.jz.sms.dto.*;
public interface ChuangLanSmsService { public interface ChuangLanSmsService {
CLTemplateResponse createTemplate(String content, String type) throws Exception; CLBizResponse createTemplate(String content, String type) throws Exception;
CLSendSMSResponse sendByFixed(String batchId, String content, String sendParams, String type) throws Exception; CLBizResponse sendByFixed(String batchId, String content, String sendParams, String type) throws Exception;
CLSendSMSResponse sendByVariable(String batchId, String content, String sendParams, String type) throws Exception; CLBizResponse sendByVariable(String batchId, String content, String sendParams, String type) throws Exception;
void asyncNotify(CLNotifyRequest notifyInfo); CLBizResponse asyncNotify(CLNotifyRequest notifyInfo);
void report(ReportDto report); CLBizResponse report(ReportDto report);
} }
...@@ -10,7 +10,6 @@ import com.jz.sms.chuanglan.service.ChuangLanSmsService; ...@@ -10,7 +10,6 @@ import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.chuanglan.utils.ChuangLanSmsUtil; import com.jz.sms.chuanglan.utils.ChuangLanSmsUtil;
import com.jz.sms.chuanglan.config.ChuangLanSMSConfig; import com.jz.sms.chuanglan.config.ChuangLanSMSConfig;
import com.jz.sms.config.ResponseCode; import com.jz.sms.config.ResponseCode;
import com.jz.sms.dto.*;
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.sms.util.HttpUtil;
...@@ -22,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -22,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -42,7 +40,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -42,7 +40,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
private SmsTemplateService templateService; private SmsTemplateService templateService;
@Override @Override
public CLTemplateResponse createTemplate(String content, String type) throws Exception { public CLBizResponse createTemplate(String content, String type) throws Exception {
int i = 1 / 0; int i = 1 / 0;
log.info("进入创蓝创建短信接口模板的逻辑:{}", content); log.info("进入创蓝创建短信接口模板的逻辑:{}", content);
Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> requestMap = new HashMap<>();
...@@ -56,7 +54,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -56,7 +54,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
} else { } else {
// TODO 自定义异常,发送警告 // TODO 自定义异常,发送警告
log.error("错误,传入的模板类型未知,类型为:{}", type); log.error("错误,传入的模板类型未知,类型为:{}", type);
return new CLTemplateResponse(ResponseCode.SYSTEM_ERROR, "未知的模板类型:" + type, 0); return new CLBizResponse(ResponseCode.SYSTEM_ERROR, "未知的模板类型:" + type, 0);
} }
content = content.replaceAll("回TD退订", ""); content = content.replaceAll("回TD退订", "");
...@@ -75,16 +73,15 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -75,16 +73,15 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String status = retJson.getString("status"); String status = retJson.getString("status");
if (SUCCESS.equals(status)) { if (SUCCESS.equals(status)) {
JSONObject data = retJson.getJSONObject("data"); JSONObject data = retJson.getJSONObject("data");
String id = data.getString("id"); return new CLBizResponse(ResponseCode.SUCCESS, data);
return new CLTemplateResponse(ResponseCode.SUCCESS, id);
} else { } else {
String msg = retJson.getString("msg"); String msg = retJson.getString("msg");
return new CLTemplateResponse(ResponseCode.UPSTREAM_FAIL.getCode(), msg); return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), msg);
} }
} }
@Override @Override
public CLSendSMSResponse sendByFixed(String batchId, String content, String sendParams, String type) throws Exception { public CLBizResponse sendByFixed(String batchId, String content, String sendParams, String type) throws Exception {
String account; String account;
String password; String password;
if ("notification".equals(type)) { if ("notification".equals(type)) {
...@@ -109,14 +106,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -109,14 +106,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson);
if (StringUtils.isBlank(responseStr)) { if (StringUtils.isBlank(responseStr)) {
return new CLSendSMSResponse("500", "渠道同步响应为空"); return new CLBizResponse(ResponseCode.UPSTREAM_BLANK);
} }
CLSendSMSResponse response = JSON.parseObject(responseStr, CLSendSMSResponse.class); CLSendSMSResponse response = JSON.parseObject(responseStr, CLSendSMSResponse.class);
return response;
String code = response.getCode();
String errorMsg = response.getErrorMsg();
String msgId = response.getMsgId();
if (!"0".equals(code)) {
return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), errorMsg);
} else {
JSONObject data = new JSONObject();
data.put("msgId", msgId);
return new CLBizResponse(ResponseCode.SUCCESS, data);
}
} }
@Override @Override
public CLSendSMSResponse sendByVariable(String batchId, String content, String params, String type) throws Exception { public CLBizResponse sendByVariable(String batchId, String content, String params, String type) throws Exception {
String account; String account;
String password; String password;
if ("notification".equals(type)) { if ("notification".equals(type)) {
...@@ -133,43 +140,58 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -133,43 +140,58 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
} }
content = "【九章数据】" + content; content = "【九章数据】" + content;
CLSendFixedRequest request = new CLSendFixedRequest(account, password, content, params, "true", batchId); CLSendVariableRequest request = new CLSendVariableRequest(account, password, content, params, "true", batchId);
String requestJson = JSONObject.toJSONString(request); String requestJson = JSONObject.toJSONString(request);
log.info("【{}】发送固定内容短信,请求上游数据为:{},\r\n请求地址为:{}", batchId, requestJson,ChuangLanSMSConfig.sendVariable); log.info("【{}】发送固定内容短信,请求上游数据为:{},\r\n请求地址为:{}", batchId, requestJson, ChuangLanSMSConfig.sendVariable);
String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendVariable, requestJson); String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendVariable, requestJson);
log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, responseStr); log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, responseStr);
if (StringUtils.isBlank(responseStr)) { if (StringUtils.isBlank(responseStr)) {
return new CLSendSMSResponse("500", "渠道同步响应为空"); return new CLBizResponse(ResponseCode.UPSTREAM_BLANK);
} }
CLSendSMSResponse response = JSON.parseObject(responseStr, CLSendSMSResponse.class); CLSendSMSResponse response = JSON.parseObject(responseStr, CLSendSMSResponse.class);
return response; String code = response.getCode();
String errorMsg = response.getErrorMsg();
String successNum = response.getSuccessNum();
String failNum = response.getFailNum();
String msgId = response.getMsgId();
if (!"0".equals(code)) {
return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), errorMsg);
} else {
JSONObject data = new JSONObject();
data.put("successNum", successNum);
data.put("failNum", failNum);
data.put("msgId", msgId);
return new CLBizResponse(ResponseCode.SUCCESS, data);
}
} }
@Override @Override
public void asyncNotify(CLNotifyRequest notifyInfo) { public CLBizResponse asyncNotify(CLNotifyRequest notifyInfo) {
String action = notifyInfo.getAction(); String action = notifyInfo.getAction();
if (!"messageModel".equals(action)) { if (!"messageModel".equals(action)) {
return; return new CLBizResponse(ResponseCode.UPSTREAM_UNKNOWN_MODEL);
} }
String id = notifyInfo.getId(); String id = notifyInfo.getId();
String status = notifyInfo.getAuditStatus(); String status = notifyInfo.getAuditStatus();
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);
} }
@Override @Override
public void report(ReportDto report) { public CLBizResponse report(ReportDto report) {
String uid = report.getUid(); String uid = report.getUid();
return null;
} }
......
package com.jz.sms.config;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
@Component
public class OkHttpConfig {
@Bean
public OkHttpClient okHttpClient() {
return new OkHttpClient().newBuilder().retryOnConnectionFailure(false).connectionPool(pool())
.connectTimeout(5, TimeUnit.SECONDS).readTimeout(5, TimeUnit.SECONDS).writeTimeout(5, TimeUnit.SECONDS)
.build();
}
@Bean
public ConnectionPool pool() {
return new ConnectionPool(50, 5, TimeUnit.MINUTES);
}
}
...@@ -2,9 +2,12 @@ package com.jz.sms.config; ...@@ -2,9 +2,12 @@ package com.jz.sms.config;
public enum ResponseCode { public enum ResponseCode {
SUCCESS("200", "处理成功"), SUCCESS("200", "处理成功"),
UPSTREAM_FAIL("UF01", "渠道交易失败"), UPSTREAM_FAIL("US01", "渠道交易失败"),
UPSTREAM_UNKNOWN_MODEL("US01", "未知通知模式"),
UPSTREAM_BLANK("US00", "渠道同步响应为空"),
SYSTEM_ERROR("99", "系统异常:"); SYSTEM_ERROR("99", "系统异常:");
private String code; private String code;
private String msg; private String msg;
...@@ -17,6 +20,7 @@ public enum ResponseCode { ...@@ -17,6 +20,7 @@ public enum ResponseCode {
return code; return code;
} }
public String getMsg() { public String getMsg() {
return msg; return msg;
} }
......
package com.jz.sms.dto;
public class DmHubBatchSendResponse {
private String code;
private String msg;
public DmHubBatchSendResponse() {
}
public DmHubBatchSendResponse(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.jz.sms.dto; package com.jz.sms.dto;
import com.jz.sms.config.ResponseCode;
public class DmHubSendResponse { public class DmHubSendResponse {
private String code;
private String msg;
public DmHubSendResponse() {
}
public DmHubSendResponse(String code, String msg) {
this.code = code;
this.msg = msg;
}
public DmHubSendResponse(ResponseCode responseCode) {
this.code = responseCode.getCode();
this.msg = responseCode.getMsg();
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
} }
...@@ -26,5 +26,5 @@ public interface MessageService { ...@@ -26,5 +26,5 @@ public interface MessageService {
* @param requestDTO * @param requestDTO
* @return * @return
*/ */
DmHubBatchSendResponse batchSend(DmHubBatchSendRequest requestDTO); DmHubSendResponse batchSend(DmHubBatchSendRequest requestDTO);
} }
...@@ -3,8 +3,7 @@ package com.jz.sms.service.impl; ...@@ -3,8 +3,7 @@ package com.jz.sms.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
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.sms.chuanglan.dto.CLSendSMSResponse; import com.jz.sms.chuanglan.dto.CLBizResponse;
import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.chuanglan.service.ChuangLanSmsService; import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.config.ResponseCode; import com.jz.sms.config.ResponseCode;
import com.jz.sms.dto.*; import com.jz.sms.dto.*;
...@@ -87,7 +86,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -87,7 +86,7 @@ public class MessageServiceImpl implements MessageService {
//TODO 发送告警 //TODO 发送告警
} }
String chaunglanCreate = dmHub2ChuangLanCreate(chuanglanSend); String chaunglanCreate = dmHub2ChuangLanCreate(chuanglanSend);
CLTemplateResponse template = chuangLanSmsService.createTemplate(chaunglanCreate, smsType); CLBizResponse template = chuangLanSmsService.createTemplate(chaunglanCreate, smsType);
if (ResponseCode.SUCCESS.getCode().equals(template.getCode())) { if (ResponseCode.SUCCESS.getCode().equals(template.getCode())) {
String id = template.getId(); String id = template.getId();
SmsTemplateInfo updateInfo = new SmsTemplateInfo(); SmsTemplateInfo updateInfo = new SmsTemplateInfo();
...@@ -223,27 +222,39 @@ public class MessageServiceImpl implements MessageService { ...@@ -223,27 +222,39 @@ public class MessageServiceImpl implements MessageService {
sysBatchInfo.setLastUpdated(new Date()); sysBatchInfo.setLastUpdated(new Date());
boolean insert = sysBatchService.insert(sysBatchInfo); boolean insert = sysBatchService.insert(sysBatchInfo);
CLBizResponse response;
// 判断模板是固定短信还是变量短信 // 判断模板是固定短信还是变量短信
if (paramsArr == null || paramsArr.isEmpty()) { if (paramsArr == null || paramsArr.isEmpty()) {
CLSendSMSResponse chuanglanResponse = chuangLanSmsService.sendByFixed(dmHubBatchId, templateInfo.getUpContent(), sendParams.toString(), type); response = chuangLanSmsService.sendByFixed(dmHubBatchId, templateInfo.getUpContent(), sendParams.toString(), type);
String code = response.getCode();
String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装
if (ResponseCode.SUCCESS.getCode().equals(code)) {
return new DmHubSendResponse(code, msg);
} else { } else {
return new DmHubSendResponse(code, msg);
// 4、封裝數據 }
CLSendSMSResponse response = chuangLanSmsService.sendByVariable(dmHubBatchId, templateInfo.getUpContent(), sendParams.toString(), type); } else {
response = chuangLanSmsService.sendByVariable(dmHubBatchId, templateInfo.getUpContent(), sendParams.toString(), type);
String code = response.getCode();
String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装
if (ResponseCode.SUCCESS.getCode().equals(code)) {
return new DmHubSendResponse(code, msg);
} else {
return new DmHubSendResponse(code, msg);
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误:{}", e);
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
return null;
} }
@Override @Override
public DmHubBatchSendResponse batchSend(DmHubBatchSendRequest request) { public DmHubSendResponse batchSend(DmHubBatchSendRequest request) {
String batchId = request.getBatchId(); String batchId = request.getBatchId();
String templateId = request.getTemplateId(); String templateId = request.getTemplateId();
...@@ -252,7 +263,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -252,7 +263,7 @@ public class MessageServiceImpl implements MessageService {
SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId)); SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (null == templateInfo) { if (null == templateInfo) {
return new DmHubBatchSendResponse("500", "模板不存在"); return new DmHubSendResponse("500", "模板不存在");
} }
// 模板参数占位符 // 模板参数占位符
...@@ -310,24 +321,41 @@ public class MessageServiceImpl implements MessageService { ...@@ -310,24 +321,41 @@ public class MessageServiceImpl implements MessageService {
info.setDateCreated(new Date()); info.setDateCreated(new Date());
info.setLastUpdated(new Date()); info.setLastUpdated(new Date());
sysBatchService.insert(info); sysBatchService.insert(info);
CLBizResponse response;
if (paramsArr == null || paramsArr.isEmpty()) { if (paramsArr == null || paramsArr.isEmpty()) {
try { try {
CLSendSMSResponse response = chuangLanSmsService.sendByFixed(batchId, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType()); response = chuangLanSmsService.sendByFixed(batchId, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType());
String code = response.getCode();
String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装
if (ResponseCode.SUCCESS.getCode().equals(code)) {
return new DmHubSendResponse(code, msg);
} else {
return new DmHubSendResponse(code, msg);
}
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误:{}", e); log.error("调用创蓝逻辑错误:{}", e);
return null; // TODO 根据DM hub需要的返回数据封装
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
} else { } else {
try { try {
CLSendSMSResponse response = chuangLanSmsService.sendByVariable(batchId, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType()); response = chuangLanSmsService.sendByVariable(batchId, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType());
String code = response.getCode();
String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装
if (ResponseCode.SUCCESS.getCode().equals(code)) {
return new DmHubSendResponse(code, msg);
} else {
return new DmHubSendResponse(code, msg);
}
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误:{}", e); log.error("调用创蓝逻辑错误:{}", e);
return null; return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
} }
return null;
} }
public String test(Object value, StringBuilder keyBuffer) { public String test(Object value, StringBuilder keyBuffer) {
......
package com.jz.sms.util;
import com.baomidou.mybatisplus.toolkit.MapUtils;
import com.jz.sms.api.BizController;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Iterator;
import java.util.Map;
@Component
public class OkHttpUtil {
private static final Logger log = LoggerFactory.getLogger(OkHttpUtil.class);
private static OkHttpClient okHttpClient;
@Autowired
public OkHttpUtil(OkHttpClient okHttpClient) {
OkHttpUtil.okHttpClient = okHttpClient;
}
/**
* get
*
* @param url 请求的url
* @param queries 请求的参数,在浏览器?后面的数据,没有可以传null
* @return
*/
public static String get(String url, Map<String, String> queries) {
String responseBody = "";
StringBuffer sb = new StringBuffer(url);
if (MapUtils.isNotEmpty(queries)) {
boolean firstFlag = true;
Iterator iterator = queries.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry<String, String>) iterator.next();
if (firstFlag) {
sb.append("?" + entry.getKey() + "=" + entry.getValue());
firstFlag = false;
} else {
sb.append("&" + entry.getKey() + "=" + entry.getValue());
}
}
}
Request request = new Request.Builder().url(sb.toString()).build();
Response response = null;
try {
response = okHttpClient.newCall(request).execute();
//int status = response.code();
if (response.isSuccessful()) {
return response.body().string();
}
} catch (Exception e) {
log.error("okhttp3 put error >> ex = {}", e);
} finally {
if (response != null) {
response.close();
}
}
return responseBody;
}
/**
* Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON
* 参数三:请求回调
*/
public static String postJsonParams(String url, String jsonParams) {
String responseBody = "";
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonParams);
Request request = new Request.Builder().url(url).post(requestBody).build();
Response response = null;
try {
response = okHttpClient.newCall(request).execute();
// int status = response.code();
if (response.isSuccessful()) {
return response.body().string();
}
} catch (Exception e) {
log.error("okhttp3 post error >> ex = {}", e);
} finally {
if (response != null) {
response.close();
}
}
return responseBody;
}
}
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