Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dmhub-plugin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinxunjia
dmhub-plugin
Commits
405e88c0
Commit
405e88c0
authored
Apr 28, 2020
by
qinxunjia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
一些优化
parent
81fdd480
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
174 additions
and
78 deletions
+174
-78
ContentEnum.java
...java/com/jz/sms/channel/chuanglan/config/ContentEnum.java
+38
-0
CLNotifyRequest.java
...ava/com/jz/sms/channel/chuanglan/dto/CLNotifyRequest.java
+5
-1
CLSendFixedRequest.java
.../com/jz/sms/channel/chuanglan/dto/CLSendFixedRequest.java
+6
-1
CLSendSMSResponse.java
...a/com/jz/sms/channel/chuanglan/dto/CLSendSMSResponse.java
+8
-3
CLSendVariableRequest.java
...m/jz/sms/channel/chuanglan/dto/CLSendVariableRequest.java
+5
-1
CLSendVariableResponse.java
.../jz/sms/channel/chuanglan/dto/CLSendVariableResponse.java
+5
-1
ReportDto.java
...main/java/com/jz/sms/channel/chuanglan/dto/ReportDto.java
+6
-12
ChuangLanSmsService.java
...jz/sms/channel/chuanglan/service/ChuangLanSmsService.java
+3
-2
ChuangLanSmsServiceImpl.java
...annel/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
+32
-24
DmHubServiceImpl.java
...m/jz/sms/channel/dmHub/service/impl/DmHubServiceImpl.java
+13
-8
DmHubBatchSendRequest.java
...in/java/com/jz/sms/channel/dto/DmHubBatchSendRequest.java
+5
-2
DmHubSendRequest.java
src/main/java/com/jz/sms/channel/dto/DmHubSendRequest.java
+5
-1
DmHubSendResponse.java
src/main/java/com/jz/sms/channel/dto/DmHubSendResponse.java
+5
-1
DmHubTemplateRequest.java
...ain/java/com/jz/sms/channel/dto/DmHubTemplateRequest.java
+5
-1
DmHubTemplateResponse.java
...in/java/com/jz/sms/channel/dto/DmHubTemplateResponse.java
+7
-1
RedisConfig.java
src/main/java/com/jz/sms/config/RedisConfig.java
+3
-3
ResponseCode.java
src/main/java/com/jz/sms/config/ResponseCode.java
+1
-0
MessageServiceImpl.java
...main/java/com/jz/sms/service/impl/MessageServiceImpl.java
+22
-16
No files found.
src/main/java/com/jz/sms/channel/chuanglan/config/ContentEnum.java
0 → 100644
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
config
;
/**
* 内容枚举类
*/
public
enum
ContentEnum
{
SMS_TYPE_NOTIFICATION
(
"notification"
,
"通知类短信标识"
),
SMS_TYPE_MARKETING
(
"marketing"
,
"营销类短信标识"
),
SMS_STATUS_SUCCESS
(
"DELIVRD"
,
"创蓝短信发送状态--成功"
),
SMS_STATUS_UNKNOWN
(
"UNKNOWN"
,
"创蓝短信发送状态--未知"
),
SMS_STATUS_REFUSE
(
"REJECTD"
,
"创蓝短信发送状态--短信中心拒绝"
),
SMS_STATUS_MBBLACK
(
"MBBLACK"
,
"创蓝短信发送状态--黑名单号码"
),
SMS_STATUS_REJECT
(
"REJECT"
,
"创蓝短信发送状态--驳回"
);
private
final
String
value
;
private
final
String
desc
;
ContentEnum
(
String
value
,
String
desc
)
{
this
.
value
=
value
;
this
.
desc
=
desc
;
}
public
String
getValue
()
{
return
value
;
}
public
String
getDesc
()
{
return
desc
;
}
}
src/main/java/com/jz/sms/channel/chuanglan/dto/CLNotifyRequest.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
dto
;
public
class
CLNotifyRequest
{
import
java.io.Serializable
;
public
class
CLNotifyRequest
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
// 接口用户名
private
String
username
;
// 十位时间戳
...
...
src/main/java/com/jz/sms/channel/chuanglan/dto/CLSendFixedRequest.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
dto
;
public
class
CLSendFixedRequest
{
import
java.io.Serializable
;
public
class
CLSendFixedRequest
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 创蓝API账号,必填
...
...
src/main/java/com/jz/sms/channel/chuanglan/dto/CLSendSMSResponse.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
dto
;
public
class
CLSendSMSResponse
{
import
java.io.Serializable
;
public
class
CLSendSMSResponse
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 响应时间
*/
...
...
@@ -23,9 +27,10 @@ public class CLSendSMSResponse {
private
String
successNum
;
public
CLSendSMSResponse
(){}
public
CLSendSMSResponse
()
{
}
public
CLSendSMSResponse
(
String
code
,
String
errorMsg
){
public
CLSendSMSResponse
(
String
code
,
String
errorMsg
)
{
this
.
code
=
code
;
this
.
errorMsg
=
errorMsg
;
}
...
...
src/main/java/com/jz/sms/channel/chuanglan/dto/CLSendVariableRequest.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
dto
;
public
class
CLSendVariableRequest
{
import
java.io.Serializable
;
public
class
CLSendVariableRequest
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
...
...
src/main/java/com/jz/sms/channel/chuanglan/dto/CLSendVariableResponse.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
dto
;
public
class
CLSendVariableResponse
{
import
java.io.Serializable
;
public
class
CLSendVariableResponse
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 响应时间
*/
...
...
src/main/java/com/jz/sms/channel/chuanglan/dto/ReportDto.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
dto
;
public
class
ReportDto
{
//receiver=admin
//&pswd=12345
//&msgid=17041010383624511
//&reportTime=1704101038
//&mobile=15700000004
//¬ifyTime=170410103838
//&uid=17041010383624511
//&length=1
//&status=DELIVRD
//&statusDesc=短信发送成功
import
java.io.Serializable
;
public
class
ReportDto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
receiver
;
...
...
src/main/java/com/jz/sms/channel/chuanglan/service/ChuangLanSmsService.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
chuanglan
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.sms.channel.chuanglan.dto.CLNotifyRequest
;
import
com.jz.sms.channel.chuanglan.dto.CLBizResponse
;
import
com.jz.sms.channel.chuanglan.dto.ReportDto
;
...
...
@@ -10,10 +11,10 @@ public interface ChuangLanSmsService {
CLBizResponse
createTemplate
(
String
content
,
String
type
)
throws
Exception
;
CLBizResponse
sendByFixed
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
CLBizResponse
sendByFixed
(
JSONObject
uidJson
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
CLBizResponse
sendByVariable
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
CLBizResponse
sendByVariable
(
JSONObject
uidJson
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
CLBizResponse
asyncNotify
(
CLNotifyRequest
notifyInfo
)
throws
Exception
;
...
...
src/main/java/com/jz/sms/channel/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
View file @
405e88c0
...
...
@@ -4,6 +4,7 @@ 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.channel.chuanglan.config.ContentEnum
;
import
com.jz.util.HttpUtil
;
import
com.jz.sms.channel.chuanglan.dto.*
;
import
com.jz.sms.channel.chuanglan.service.ChuangLanSmsService
;
...
...
@@ -30,9 +31,13 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ChuangLanSmsServiceImpl
.
class
);
private
static
final
String
SUCCESS
=
"success"
;
private
static
final
String
ERROR
=
"error"
;
private
static
final
String
CODE
=
"code"
;
private
static
final
String
DATA
=
"data"
;
private
static
final
String
sendSuccessCode
=
"0"
;
// 发送响应成功字段
private
static
final
String
createTemplateStatus
=
"status"
;
// 响应状态字段
private
static
final
String
retMsg
=
"msg"
;
// 响应描述
private
static
final
String
createTemplateData
=
"data"
;
// 创建模板响应数据
private
static
final
String
notificationId
=
"49"
;
// 创蓝通知类短信ID
private
static
final
String
marketingId
=
"52"
;
// 创蓝营销类短信ID
@Autowired
private
SmsTemplateService
templateService
;
...
...
@@ -46,10 +51,11 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String
appId
;
String
username
=
ChuangLanSMSConfig
.
interfaceUser
;
String
password
=
ChuangLanSMSConfig
.
interfacePassword
;
if
(
"notification"
.
equals
(
type
))
{
appId
=
"49"
;
}
else
if
(
"marketing"
.
equals
(
type
))
{
appId
=
"52"
;
if
(
ContentEnum
.
SMS_TYPE_NOTIFICATION
.
getValue
().
equals
(
type
))
{
appId
=
notificationId
;
}
else
if
(
ContentEnum
.
SMS_TYPE_MARKETING
.
getValue
().
equals
(
type
))
{
appId
=
marketingId
;
// 两个系统模式不同,DMHUB会带上回TD退订,但是创蓝回自动追加回TD退订。只是营销类
content
=
content
.
replaceAll
(
"回TD退订"
,
""
);
}
else
{
// TODO 发送警告
...
...
@@ -69,36 +75,37 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String
retStr
=
HttpUtil
.
doPost
(
ChuangLanSMSConfig
.
addTemplate
,
requestMap
);
log
.
info
(
"请求创蓝创建短信模板的返回数据为:{}"
,
retStr
);
JSONObject
retJson
=
JSONObject
.
parseObject
(
retStr
);
String
status
=
retJson
.
getString
(
"status"
);
String
status
=
retJson
.
getString
(
createTemplateStatus
);
if
(
SUCCESS
.
equals
(
status
))
{
JSONObject
data
=
retJson
.
getJSONObject
(
"data"
);
JSONObject
data
=
retJson
.
getJSONObject
(
createTemplateData
);
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
,
data
);
}
else
{
String
msg
=
retJson
.
getString
(
"msg"
);
String
msg
=
retJson
.
getString
(
retMsg
);
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_FAIL
.
getCode
(),
msg
);
}
}
@Override
public
CLBizResponse
sendByFixed
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
{
public
CLBizResponse
sendByFixed
(
JSONObject
uidJson
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
{
String
account
;
String
password
;
if
(
"notification"
.
equals
(
type
))
{
if
(
ContentEnum
.
SMS_TYPE_NOTIFICATION
.
getValue
()
.
equals
(
type
))
{
account
=
ChuangLanSMSConfig
.
notificationAccount
;
password
=
ChuangLanSMSConfig
.
notificationPassword
;
log
.
info
(
"发送短信的模式为:{通知类}"
);
}
else
if
(
"marketing"
.
equals
(
type
))
{
}
else
if
(
ContentEnum
.
SMS_TYPE_MARKETING
.
getValue
()
.
equals
(
type
))
{
account
=
ChuangLanSMSConfig
.
marketingAccount
;
password
=
ChuangLanSMSConfig
.
marketingPassword
;
log
.
info
(
"发送短信的模式为:{营销类}"
);
}
else
{
log
.
info
(
"发送短信的模式为:{未知类型}"
);
throw
new
Exception
(
"123"
);
log
.
error
(
"发送短信的模式为:{未知类型}"
);
return
new
CLBizResponse
(
ResponseCode
.
UNKNOWN_TEMPLATE_TYPE
);
}
CLSendFixedRequest
request
=
new
CLSendFixedRequest
(
account
,
password
,
content
,
sendParams
,
"true"
,
batchId
);
CLSendFixedRequest
request
=
new
CLSendFixedRequest
(
account
,
password
,
content
,
sendParams
,
"true"
,
uidJson
.
toJSONString
()
);
String
requestJson
=
JSONObject
.
toJSONString
(
request
);
String
batchId
=
uidJson
.
getString
(
"dmHubId"
);
log
.
info
(
"【{}】发送固定内容短信,请求上游数据为:{}"
,
batchId
,
requestJson
);
String
responseStr
=
ChuangLanSmsUtil
.
sendSmsByPost
(
ChuangLanSMSConfig
.
sendFixed
,
requestJson
);
log
.
info
(
"【{}】发送固定内容短信,上游返回数据为:{}"
,
batchId
,
requestJson
);
...
...
@@ -111,7 +118,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String
code
=
response
.
getCode
();
String
errorMsg
=
response
.
getErrorMsg
();
String
msgId
=
response
.
getMsgId
();
if
(!
"0"
.
equals
(
code
))
{
if
(!
sendSuccessCode
.
equals
(
code
))
{
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_FAIL
.
getCode
(),
errorMsg
);
}
else
{
JSONObject
data
=
new
JSONObject
();
...
...
@@ -121,23 +128,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
}
@Override
public
CLBizResponse
sendByVariable
(
String
batchId
,
String
content
,
String
params
,
String
type
)
throws
Exception
{
public
CLBizResponse
sendByVariable
(
JSONObject
uidJson
,
String
content
,
String
params
,
String
type
)
throws
Exception
{
String
account
;
String
password
;
if
(
"notification"
.
equals
(
type
))
{
if
(
ContentEnum
.
SMS_TYPE_NOTIFICATION
.
getValue
()
.
equals
(
type
))
{
account
=
ChuangLanSMSConfig
.
notificationAccount
;
password
=
ChuangLanSMSConfig
.
notificationPassword
;
log
.
info
(
"发送短信的模式为:{通知类}"
);
}
else
if
(
"marketing"
.
equals
(
type
))
{
}
else
if
(
ContentEnum
.
SMS_TYPE_MARKETING
.
getValue
()
.
equals
(
type
))
{
account
=
ChuangLanSMSConfig
.
marketingAccount
;
password
=
ChuangLanSMSConfig
.
marketingPassword
;
log
.
info
(
"发送短信的模式为:{营销类}"
);
}
else
{
log
.
info
(
"发送短信的模式为:{未知类型},type:{}"
,
type
);
throw
new
Exception
(
"123"
);
return
new
CLBizResponse
(
ResponseCode
.
UNKNOWN_TEMPLATE_TYPE
);
}
CLSendVariableRequest
request
=
new
CLSendVariableRequest
(
account
,
password
,
content
,
params
,
"true"
,
batchId
);
CLSendVariableRequest
request
=
new
CLSendVariableRequest
(
account
,
password
,
content
,
params
,
"true"
,
uidJson
.
toJSONString
()
);
String
requestJson
=
JSONObject
.
toJSONString
(
request
);
String
batchId
=
uidJson
.
getString
(
"dmHubId"
);
log
.
info
(
"【{}】发送变量内容短信,请求上游数据为:{},\r\n请求地址为:{}"
,
batchId
,
requestJson
,
ChuangLanSMSConfig
.
sendVariable
);
String
responseStr
=
ChuangLanSmsUtil
.
sendSmsByPost
(
ChuangLanSMSConfig
.
sendVariable
,
requestJson
);
log
.
info
(
"【{}】发送变量内容短信,上游返回数据为:{}"
,
batchId
,
responseStr
);
...
...
@@ -151,7 +159,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String
successNum
=
response
.
getSuccessNum
();
String
failNum
=
response
.
getFailNum
();
String
msgId
=
response
.
getMsgId
();
if
(!
"0"
.
equals
(
code
))
{
if
(!
sendSuccessCode
.
equals
(
code
))
{
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_FAIL
.
getCode
(),
errorMsg
);
}
else
{
JSONObject
data
=
new
JSONObject
();
...
...
@@ -174,7 +182,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
if
(!
"1"
.
equals
(
status
))
{
String
msg
=
notifyInfo
.
getAuditReason
();
boolean
update
=
templateService
.
updateForSet
(
"status = abnormal,up_reject_msg = "
+
msg
,
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"up_template_id"
,
id
));
// TODO 发送告警
// TODO 发送告警
,模板审核未通过
log
.
error
(
"短信模板审核不通过,原因:{}"
,
msg
);
}
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
);
...
...
src/main/java/com/jz/sms/channel/dmHub/service/impl/DmHubServiceImpl.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
dmHub
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.sms.channel.chuanglan.config.ContentEnum
;
import
com.jz.sms.channel.chuanglan.dto.ReportDto
;
import
com.jz.sms.channel.dmHub.config.DmHubConfig
;
import
com.jz.sms.channel.dmHub.service.DmHubService
;
...
...
@@ -30,16 +31,17 @@ public class DmHubServiceImpl implements DmHubService {
private
static
final
String
TOKEN_KEY
=
"DM_HUB_API_TOKEN"
;
@Autowired
RedisTemplate
redisTemplate
;
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
@Override
public
String
getToken
()
{
try
{
String
token
=
redisTemplate
.
opsForValue
().
get
(
TOKEN_KEY
).
toString
();
Long
expire
=
redisTemplate
.
opsForValue
().
getOperations
().
getExpire
(
TOKEN_KEY
);
if
(
expire
!=
null
&&
expire
>
0L
)
{
return
token
;
Long
expire
=
redisTemplate
.
getExpire
(
TOKEN_KEY
,
TimeUnit
.
SECONDS
);
Object
token
=
redisTemplate
.
opsForValue
().
get
(
TOKEN_KEY
);
if
(
expire
!=
null
&&
expire
>
0L
&&
token
!=
null
)
{
return
token
.
toString
();
}
else
{
String
appid
=
DmHubConfig
.
applicationId
;
String
secret
=
DmHubConfig
.
applicationKey
;
...
...
@@ -79,17 +81,21 @@ public class DmHubServiceImpl implements DmHubService {
if
(
StringUtils
.
isBlank
(
token
))
{
return
null
;
}
String
uidStr
=
dto
.
getUid
();
JSONObject
uidJson
=
JSONObject
.
parseObject
(
uidStr
);
String
dmHubBatchId
=
uidJson
.
getString
(
"dmHubId"
);
String
sysBatchId
=
uidJson
.
getString
(
"sysBatchId"
);
DmhubReport
report
=
new
DmhubReport
();
report
.
setAccess_token
(
token
);
report
.
setType
(
"sms"
);
ReportDetail
detail
=
new
ReportDetail
();
detail
.
setAudienceId
(
dto
.
getMobile
());
detail
.
setBatchId
(
d
to
.
getUid
()
);
detail
.
setBatchId
(
d
mHubBatchId
);
detail
.
setReportDate
(
dto
.
getReportTime
());
detail
.
setMobile
(
dto
.
getMobile
());
detail
.
setChargeNum
(
Integer
.
valueOf
(
dto
.
getLength
()));
detail
.
setSendDate
(
dto
.
getReportTime
());
if
(
"DELIVRD"
.
equals
(
dto
.
getStatus
()))
{
if
(
ContentEnum
.
SMS_STATUS_SUCCESS
.
getValue
()
.
equals
(
dto
.
getStatus
()))
{
detail
.
setIsReceive
(
true
);
}
else
{
detail
.
setIsReceive
(
false
);
...
...
@@ -100,7 +106,6 @@ public class DmHubServiceImpl implements DmHubService {
String
retStr
=
HttpUtil
.
sendPost
(
DmHubConfig
.
report
,
JSONObject
.
toJSONString
(
report
));
log
.
info
(
"短信状态回执响应:{}"
,
retStr
);
//TODO 目前没有测试环境的请求地址
}
catch
(
Exception
e
)
{
log
.
info
(
"发送短信回执到DMHub异常\r\n短信信息:{},\r\n,异常:"
,
dto
,
e
);
}
...
...
src/main/java/com/jz/sms/channel/dto/DmHubBatchSendRequest.java
View file @
405e88c0
...
...
@@ -2,9 +2,12 @@ package com.jz.sms.channel.dto;
import
com.alibaba.fastjson.JSONObject
;
import
java.io.Serializable
;
import
java.util.List
;
public
class
DmHubBatchSendRequest
{
public
class
DmHubBatchSendRequest
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
// 批量发送短信的模板id
...
...
@@ -13,7 +16,7 @@ public class DmHubBatchSendRequest {
// 批次号
private
String
batchId
;
//
批次号
//
账号类型(mobile就传手机号)
private
String
audienceIdType
;
// 短信数据
...
...
src/main/java/com/jz/sms/channel/dto/DmHubSendRequest.java
View file @
405e88c0
...
...
@@ -2,7 +2,11 @@ package com.jz.sms.channel.dto;
import
com.alibaba.fastjson.JSONObject
;
public
class
DmHubSendRequest
{
import
java.io.Serializable
;
public
class
DmHubSendRequest
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
// 发送短信的模板ID
...
...
src/main/java/com/jz/sms/channel/dto/DmHubSendResponse.java
View file @
405e88c0
...
...
@@ -2,7 +2,11 @@ package com.jz.sms.channel.dto;
import
com.jz.sms.config.ResponseCode
;
public
class
DmHubSendResponse
{
import
java.io.Serializable
;
public
class
DmHubSendResponse
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
code
;
private
String
msg
;
...
...
src/main/java/com/jz/sms/channel/dto/DmHubTemplateRequest.java
View file @
405e88c0
package
com
.
jz
.
sms
.
channel
.
dto
;
public
class
DmHubTemplateRequest
{
import
java.io.Serializable
;
public
class
DmHubTemplateRequest
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
tenantId
;
...
...
src/main/java/com/jz/sms/channel/dto/DmHubTemplateResponse.java
View file @
405e88c0
...
...
@@ -2,7 +2,13 @@ package com.jz.sms.channel.dto;
import
com.jz.sms.config.ResponseCode
;
public
class
DmHubTemplateResponse
{
import
java.io.Serializable
;
public
class
DmHubTemplateResponse
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
code
;
private
String
msg
;
...
...
src/main/java/com/jz/sms/config/RedisConfig.java
View file @
405e88c0
...
...
@@ -9,10 +9,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@Configuration
public
class
RedisConfig
<
K
,
V
>
{
public
class
RedisConfig
{
@Bean
public
RedisTemplate
<
K
,
V
>
getRedisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
RedisTemplate
<
K
,
V
>
redisTemplate
=
new
RedisTemplate
<>();
public
RedisTemplate
<
String
,
Object
>
getRedisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
RedisTemplate
<
String
,
Object
>
redisTemplate
=
new
RedisTemplate
<>();
redisTemplate
.
setConnectionFactory
(
redisConnectionFactory
);
//全局开启
...
...
src/main/java/com/jz/sms/config/ResponseCode.java
View file @
405e88c0
...
...
@@ -2,6 +2,7 @@ package com.jz.sms.config;
public
enum
ResponseCode
{
SUCCESS
(
"200"
,
"处理成功"
),
UNKNOWN_TEMPLATE_TYPE
(
"500"
,
"未知模板类型"
),
UPSTREAM_FAIL
(
"US01"
,
"渠道交易失败"
),
UPSTREAM_UNKNOWN_MODEL
(
"US01"
,
"未知通知模式"
),
UPSTREAM_BLANK
(
"US00"
,
"渠道同步响应为空"
),
...
...
src/main/java/com/jz/sms/service/impl/MessageServiceImpl.java
View file @
405e88c0
...
...
@@ -15,6 +15,7 @@ import com.jz.sms.service.MessageService;
import
com.jz.sms.service.SmsTemplateService
;
import
com.jz.sms.service.bean.TemplateChangeBean
;
import
com.jz.util.id.IdHandler
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -53,7 +54,7 @@ public class MessageServiceImpl implements MessageService {
public
DmHubTemplateResponse
createTemplate
(
DmHubTemplateRequest
requestDTO
)
{
log
.
info
(
"进入创建短信模板业务逻辑,入参:{}"
,
requestDTO
);
DmHubTemplateResponse
responseDTO
=
new
DmHubTemplateResponse
(
"200"
,
"成功"
);
DmHubTemplateResponse
responseDTO
=
new
DmHubTemplateResponse
(
ResponseCode
.
SUCCESS
);
try
{
String
templateContent
=
requestDTO
.
getTemplateContent
();
String
signature
=
requestDTO
.
getSignature
();
...
...
@@ -82,8 +83,8 @@ public class MessageServiceImpl implements MessageService {
info
.
setParams
(
params
);
boolean
insert
=
smsTemplateService
.
insert
(
info
);
if
(!
insert
)
{
return
new
DmHubTemplateResponse
(
"500"
,
"系统异常"
);
//TODO 发送告警
return
new
DmHubTemplateResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
String
chaunglanCreate
=
dmHub2ChuangLanCreate
(
chuanglanSend
);
CLBizResponse
template
=
chuangLanSmsService
.
createTemplate
(
chaunglanCreate
,
smsType
);
...
...
@@ -100,7 +101,7 @@ public class MessageServiceImpl implements MessageService {
}
}
catch
(
Exception
exception
)
{
log
.
error
(
"创建模板业务逻辑异常,错误信息"
,
exception
);
responseDTO
=
new
DmHubTemplateResponse
(
"500"
,
"系统异常"
);
responseDTO
=
new
DmHubTemplateResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
return
responseDTO
;
...
...
@@ -209,7 +210,8 @@ public class MessageServiceImpl implements MessageService {
// 3、记录批次信息
SysBatchInfo
sysBatchInfo
=
new
SysBatchInfo
();
sysBatchInfo
.
setBatchId
(
IdHandler
.
nextId
());
long
sysBatchId
=
IdHandler
.
nextId
();
sysBatchInfo
.
setBatchId
(
sysBatchId
);
sysBatchInfo
.
setDmBatchId
(
dmHubBatchId
);
sysBatchInfo
.
setId
(
IdHandler
.
nextId
());
sysBatchInfo
.
setDmTemplateId
(
templateId
);
...
...
@@ -221,8 +223,11 @@ public class MessageServiceImpl implements MessageService {
CLBizResponse
response
;
// 判断模板是固定短信还是变量短信
JSONObject
uidJson
=
new
JSONObject
();
uidJson
.
put
(
"sysBatchId"
,
String
.
valueOf
(
sysBatchId
));
uidJson
.
put
(
"dmHubId"
,
dmHubBatchId
);
if
(
paramsArr
==
null
||
paramsArr
.
isEmpty
())
{
response
=
chuangLanSmsService
.
sendByFixed
(
dmHubBatchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
response
=
chuangLanSmsService
.
sendByFixed
(
uidJson
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
...
...
@@ -232,7 +237,7 @@ public class MessageServiceImpl implements MessageService {
return
new
DmHubSendResponse
(
code
,
msg
);
}
}
else
{
response
=
chuangLanSmsService
.
sendByVariable
(
dmHubBatchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
response
=
chuangLanSmsService
.
sendByVariable
(
uidJson
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
...
...
@@ -244,8 +249,7 @@ public class MessageServiceImpl implements MessageService {
}
}
catch
(
Exception
e
)
{
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
log
.
error
(
"调用创蓝逻辑错误"
,
e
);
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
}
...
...
@@ -253,16 +257,15 @@ public class MessageServiceImpl implements MessageService {
@Override
public
DmHubSendResponse
batchSend
(
DmHubBatchSendRequest
request
)
{
String
batchId
=
request
.
getBatchId
();
String
templateId
=
request
.
getTemplateId
();
String
batchId
=
request
.
getBatchId
();
// DM hub 批次号
String
templateId
=
request
.
getTemplateId
();
// 此次短信对应的模板id
String
audienceIdType
=
request
.
getAudienceIdType
();
List
<
JSONObject
>
data
=
request
.
getData
();
SmsTemplateInfo
templateInfo
=
smsTemplateService
.
selectOne
(
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"dm_template_id"
,
templateId
));
if
(
null
==
templateInfo
)
{
return
new
DmHubSendResponse
(
"500"
,
"模板不存在"
);
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
// 模板参数占位符
String
params
=
templateInfo
.
getParams
();
JSONArray
paramsArr
=
JSONArray
.
parseArray
(
params
);
...
...
@@ -325,9 +328,12 @@ public class MessageServiceImpl implements MessageService {
sysBatchService
.
insert
(
info
);
CLBizResponse
response
;
JSONObject
uidJson
=
new
JSONObject
();
uidJson
.
put
(
"sysBatchId"
,
String
.
valueOf
(
sysBatchId
));
uidJson
.
put
(
"dmHubId"
,
batchId
);
if
(
paramsArr
==
null
||
paramsArr
.
isEmpty
())
{
try
{
response
=
chuangLanSmsService
.
sendByFixed
(
batchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
response
=
chuangLanSmsService
.
sendByFixed
(
uidJson
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
...
...
@@ -337,14 +343,14 @@ public class MessageServiceImpl implements MessageService {
return
new
DmHubSendResponse
(
code
,
msg
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"调用创蓝逻辑错误
:{}
"
,
e
);
log
.
error
(
"调用创蓝逻辑错误"
,
e
);
// TODO 根据DM hub需要的返回数据封装
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
}
else
{
try
{
response
=
chuangLanSmsService
.
sendByVariable
(
batchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
response
=
chuangLanSmsService
.
sendByVariable
(
uidJson
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
...
...
@@ -354,7 +360,7 @@ public class MessageServiceImpl implements MessageService {
return
new
DmHubSendResponse
(
code
,
msg
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"调用创蓝逻辑错误
:{}
"
,
e
);
log
.
error
(
"调用创蓝逻辑错误
:
"
,
e
);
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment