Commit daf1bf26 authored by qinxunjia's avatar qinxunjia

结构变化,回执基本流程

parent f1a19ceb
......@@ -95,6 +95,10 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
</dependencies>
<build>
<finalName>dmhub-plugin</finalName>
......
package com.jz.sms.api;
package com.jz.sms.channel.api;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.chuanglan.dto.CLBizResponse;
import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.dto.ReportDto;
import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.channel.chuanglan.dto.CLBizResponse;
import com.jz.sms.channel.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.channel.chuanglan.dto.ReportDto;
import com.jz.sms.channel.chuanglan.service.ChuangLanSmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......
package com.jz.sms.api;
package com.jz.sms.channel.api;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.dto.*;
import com.jz.sms.channel.dto.*;
import com.jz.sms.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
package com.jz.sms.chuanglan.config;
package com.jz.sms.channel.chuanglan.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.config.ResponseCode;
......@@ -7,6 +7,7 @@ import java.io.Serializable;
public class CLBizResponse implements Serializable {
private static final long serialVersionUID = 8100192126279967648L;
private String code;
......
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
public class CLNotifyRequest {
......
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
public class CLSendFixedRequest {
......
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
public class CLSendSMSResponse {
/**
......
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
public class CLSendVariableRequest {
......
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
public class CLSendVariableResponse {
/**
......
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
public class CLTemplateRequest {
}
package com.jz.sms.chuanglan.dto;
package com.jz.sms.channel.chuanglan.dto;
public class ReportDto {
......
package com.jz.sms.chuanglan.service;
package com.jz.sms.channel.chuanglan.service;
import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.dto.CLSendSMSResponse;
import com.jz.sms.chuanglan.dto.CLBizResponse;
import com.jz.sms.chuanglan.dto.ReportDto;
import com.jz.sms.channel.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.channel.chuanglan.dto.CLBizResponse;
import com.jz.sms.channel.chuanglan.dto.ReportDto;
public interface ChuangLanSmsService {
......
package com.jz.sms.chuanglan.service.impl;
package com.jz.sms.channel.chuanglan.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jz.sms.api.DmHubApi;
import com.jz.sms.chuanglan.dto.*;
import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.chuanglan.utils.ChuangLanSmsUtil;
import com.jz.sms.chuanglan.config.ChuangLanSMSConfig;
import com.jz.sms.channel.api.DmHubApi;
import com.jz.sms.channel.chuanglan.dto.*;
import com.jz.sms.channel.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.channel.chuanglan.utils.ChuangLanSmsUtil;
import com.jz.sms.channel.chuanglan.config.ChuangLanSMSConfig;
import com.jz.sms.config.ResponseCode;
import com.jz.sms.channel.dmHub.service.DmHubService;
import com.jz.sms.repository.domain.SmsTemplateInfo;
import com.jz.sms.service.SmsTemplateService;
import com.jz.sms.util.HttpUtil;
......@@ -38,6 +39,8 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
@Autowired
private SmsTemplateService templateService;
@Autowired
private DmHubService dmHubService;
@Override
public CLBizResponse createTemplate(String content, String type) throws Exception {
......@@ -189,9 +192,8 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
public CLBizResponse report(ReportDto report) {
// TODO 状态报告要特殊处理,一个个接受,批量发送
String uid = report.getUid();
return null;
Map<String, Object> ret = dmHubService.smsReport(report);
return new CLBizResponse(ResponseCode.SUCCESS);
}
......
package com.jz.sms.chuanglan.utils;
package com.jz.sms.channel.chuanglan.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
......
package com.jz.sms.dmHub.config;
package com.jz.sms.channel.dmHub.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -12,6 +12,7 @@ public class DmHubConfig {
// 应用key
public static String applicationKey;
public static String tokenUrl;
public static String report;
@Value("${system.config.dmHub.applicationId}")
......@@ -29,4 +30,12 @@ public class DmHubConfig {
public void setTokenUrl(String tokenUrl) {
DmHubConfig.tokenUrl = tokenUrl;
}
@Value("{system.config.dmHub.report}")
public void setReport(String report) {
DmHubConfig.report = report;
}
}
package com.jz.sms.dmHub.service;
package com.jz.sms.channel.dmHub.service;
import com.jz.sms.channel.chuanglan.dto.ReportDto;
import java.util.Map;
......@@ -15,8 +17,8 @@ public interface DmHubService {
/**
* 回执报告给DM hub
*
* @param reportInfo
* @param dto
* @return
*/
Map<String, Object> smsReport(Map<String, Object> reportInfo);
Map<String, Object> smsReport(ReportDto dto);
}
package com.jz.sms.dmHub.service.impl;
package com.jz.sms.channel.dmHub.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.dmHub.config.DmHubConfig;
import com.jz.sms.dmHub.service.DmHubService;
import com.jz.sms.channel.api.DmHubApi;
import com.jz.sms.channel.chuanglan.dto.ReportDto;
import com.jz.sms.channel.dmHub.config.DmHubConfig;
import com.jz.sms.channel.dmHub.service.DmHubService;
import com.jz.sms.channel.dto.DmhubReport;
import com.jz.sms.channel.dto.ReportDetail;
import com.jz.sms.util.HttpUtil;
import com.jz.sms.util.OkHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* Dm hub系统交互业务层
......@@ -15,6 +25,11 @@ import java.util.Map;
@Service
public class DmHubServiceImpl implements DmHubService {
private static final Logger log = LoggerFactory.getLogger(DmHubServiceImpl.class);
@Autowired
RedisTemplate redisTemplate;
@Override
public String getToken() {
......@@ -33,17 +48,38 @@ public class DmHubServiceImpl implements DmHubService {
if ("0".equals(errorCode)) {
String accessToken = retJson.getString("access_token");
String expires = retJson.getString("expires_in");
// TODO 存redis,过期时间=expires-600(秒)
redisTemplate.opsForValue().set("DM_HUB_TOKEN", accessToken, Long.parseLong(expires) - 600L, TimeUnit.SECONDS);
return accessToken;
} else {
return null;
}
// TODO 存redis,过期时间=expires-600(秒)
}
@Override
public Map<String, Object> smsReport(Map<String, Object> accInfo) {
public Map<String, Object> smsReport(ReportDto dto) {
DmhubReport report = new DmhubReport();
report.setType("sms");
ReportDetail detail = new ReportDetail();
detail.setAudienceId(dto.getMobile());
detail.setBatchId(dto.getUid());
detail.setReportDate(dto.getReportTime());
detail.setMobile(dto.getMobile());
detail.setChargeNum(Integer.valueOf(dto.getLength()));
detail.setSendDate(dto.getReportTime());
if ("DELIVRD".equals(dto.getStatus())) {
detail.setIsReceive(true);
} else {
detail.setIsReceive(false);
}
detail.setErrMessage(dto.getStatusDesc());
report.setReports(detail);
log.info("短信状态回执参数:{}", JSONObject.toJSONString(report));
String retStr = HttpUtil.sendPost(DmHubConfig.report, JSONObject.toJSONString(report));
log.info("短信状态回执响应:{}", retStr);
return null;
}
}
package com.jz.sms.dto;
package com.jz.sms.channel.dto;
import com.alibaba.fastjson.JSONObject;
......
package com.jz.sms.dto;
package com.jz.sms.channel.dto;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
public class DmHubSendRequest {
......
package com.jz.sms.dto;
package com.jz.sms.channel.dto;
import com.jz.sms.config.ResponseCode;
......
package com.jz.sms.dto;
package com.jz.sms.channel.dto;
public class DmHubTemplateRequest {
......
package com.jz.sms.dto;
package com.jz.sms.channel.dto;
public class DmHubTemplateResponse {
private String code;
......
package com.jz.sms.channel.dto;
import java.io.Serializable;
public class DmhubReport implements Serializable {
private static final long serialVersionUID = 810019212627996764L;
private String type;
private ReportDetail reports;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public ReportDetail getReports() {
return reports;
}
public void setReports(ReportDetail reports) {
this.reports = reports;
}
}
package com.jz.sms.channel.dto;
import java.io.Serializable;
public class ReportDetail implements Serializable {
private static final long serialVersionUID = 810019212627996764L;
private String audienceId;
private String batchId;
private String reportDate;
private Boolean isReceive;
private String mobile;
private Integer chargeNum;
private String sendDate;
private String errMessage;
private String content;
private String msgCode;
private String campaign;
public String getAudienceId() {
return audienceId;
}
public void setAudienceId(String audienceId) {
this.audienceId = audienceId;
}
public String getBatchId() {
return batchId;
}
public void setBatchId(String batchId) {
this.batchId = batchId;
}
public String getReportDate() {
return reportDate;
}
public void setReportDate(String reportDate) {
this.reportDate = reportDate;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getSendDate() {
return sendDate;
}
public void setSendDate(String sendDate) {
this.sendDate = sendDate;
}
public String getErrMessage() {
return errMessage;
}
public void setErrMessage(String errMessage) {
this.errMessage = errMessage;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getMsgCode() {
return msgCode;
}
public void setMsgCode(String msgCode) {
this.msgCode = msgCode;
}
public String getCampaign() {
return campaign;
}
public void setCampaign(String campaign) {
this.campaign = campaign;
}
public Boolean getIsReceive() {
return isReceive;
}
public void setIsReceive(Boolean receive) {
isReceive = receive;
}
public Integer getChargeNum() {
return chargeNum;
}
public void setChargeNum(Integer chargeNum) {
this.chargeNum = chargeNum;
}
}
package com.jz.sms.config;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig<K, V> {
@Bean
public RedisTemplate<K, V> getRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<K, V> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
//全局开启
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
//key序列化
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//value序列化
redisTemplate.setValueSerializer(new FastJsonRedisSerializer<>(Object.class));
redisTemplate.setHashValueSerializer(new FastJsonRedisSerializer<>(Object.class));
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
package com.jz.sms.service;
import com.jz.sms.dto.*;
import com.jz.sms.channel.dto.*;
public interface MessageService {
......
......@@ -3,10 +3,10 @@ package com.jz.sms.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jz.sms.chuanglan.dto.CLBizResponse;
import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.channel.chuanglan.dto.CLBizResponse;
import com.jz.sms.channel.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.config.ResponseCode;
import com.jz.sms.dto.*;
import com.jz.sms.channel.dto.*;
import com.jz.sms.repository.domain.DmBatchInfo;
import com.jz.sms.repository.domain.SmsTemplateInfo;
import com.jz.sms.repository.domain.SysBatchInfo;
......@@ -196,7 +196,7 @@ public class MessageServiceImpl implements MessageService {
Object value = data.get(key);
if (value instanceof JSONObject || value instanceof Map) {
StringBuilder keyBuffer = new StringBuilder(key);
value = test(value, keyBuffer);
value = getKeyValue(value, keyBuffer);
newKey = keyBuffer.toString();
}
if (s.contains(newKey)) {
......@@ -287,7 +287,7 @@ public class MessageServiceImpl implements MessageService {
Object value = json.get(key);
if (value instanceof JSONObject || value instanceof Map) {
StringBuilder keyBuffer = new StringBuilder(key);
value = test(value, keyBuffer);
value = getKeyValue(value, keyBuffer);
newKey = keyBuffer.toString();
}
if (s.contains(newKey)) {
......@@ -361,7 +361,7 @@ public class MessageServiceImpl implements MessageService {
}
}
public String test(Object value, StringBuilder keyBuffer) {
public String getKeyValue(Object value, StringBuilder keyBuffer) {
String s = JSONObject.toJSONString(value);
JSONObject valueJson = JSONObject.parseObject(s);
Set<String> set = valueJson.keySet();
......@@ -372,7 +372,7 @@ public class MessageServiceImpl implements MessageService {
keyBuffer.append(".").append(str);
Object info = valueJson.get(str);
if (info instanceof JSONObject || info instanceof Map) {
String test = test(info, keyBuffer);
String test = getKeyValue(info, keyBuffer);
return test;
} else {
return info.toString();
......
package com.jz.sms.wrapper.maintenance;
import com.jz.sms.dto.DmHubTemplateRequest;
import com.jz.sms.dto.DmHubTemplateResponse;
import com.jz.sms.channel.dto.DmHubTemplateRequest;
import com.jz.sms.channel.dto.DmHubTemplateResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......
package com.jz.sms.wrapper.maintenance;
import com.jz.sms.dto.DmHubTemplateRequest;
import com.jz.sms.dto.DmHubTemplateResponse;
import com.jz.sms.channel.dto.DmHubTemplateRequest;
import com.jz.sms.channel.dto.DmHubTemplateResponse;
import com.jz.sms.service.impl.MessageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......
server:
tomcat:
max-threads: 50
port: 9010
#contextPath: /resource
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://127.0.0.1:3306/plugin?characterEncoding=utf8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
hikari:
......@@ -14,6 +17,13 @@ spring:
maximumPoolSize: 20
connectionTimeout: 30000
idleTimeout: 600000
pool-name: dmhub-plug-pool
redis:
database: 0
host: 127.0.0.1
port: 6379
timeout: 5000
system:
config:
......@@ -32,4 +42,5 @@ system:
dmHub:
applicationId: cl0300171a6012c21
applicationKey: 4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl: https://api.convertlab.com/security/accesstoken
\ No newline at end of file
tokenUrl: https://api.convertlab.com/security/accesstoken
report: https://api.convertlab.com/v1/sms/report
\ No newline at end of file
# 测试环境配置
server:
tomcat:
max-threads: 50
port: 19010
#contextPath: /resource
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://119.23.32.151:3306/dmhub_plugin?characterEncoding=utf8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
driver-class-name: com.mysql.cj.jdbc.Driver
username: dmp
password: Ioubuy@2019@!
hikari:
......@@ -15,7 +19,14 @@ spring:
maximumPoolSize: 20
connectionTimeout: 30000
idleTimeout: 600000
pool-name: dmhub-plug-pool
redis:
database: 0
host: 127.0.0.1
port: 6379
timeout: 5000
system:
config:
chuanglan:
......@@ -34,4 +45,5 @@ system:
applicationId: cl0300171a6012c21
applicationKey: 4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl: https://api.convertlab.com/security/accesstoken
report: https://api.convertlab.com/v1/sms/report
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