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
99c7201b
Commit
99c7201b
authored
Apr 28, 2020
by
qinxunjia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理模板变量长度
parent
405e88c0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
25 deletions
+69
-25
ChuangLanSmsServiceImpl.java
...annel/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
+1
-1
ResponseCode.java
src/main/java/com/jz/sms/config/ResponseCode.java
+6
-2
TemplateChangeBean.java
...main/java/com/jz/sms/service/bean/TemplateChangeBean.java
+20
-9
MessageServiceImpl.java
...main/java/com/jz/sms/service/impl/MessageServiceImpl.java
+42
-13
No files found.
src/main/java/com/jz/sms/channel/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
View file @
99c7201b
...
@@ -46,7 +46,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
...
@@ -46,7 +46,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
@Override
@Override
public
CLBizResponse
createTemplate
(
String
content
,
String
type
)
throws
Exception
{
public
CLBizResponse
createTemplate
(
String
content
,
String
type
)
throws
Exception
{
log
.
info
(
"进入创蓝创建短信接口模板的逻辑
:{}"
,
content
);
log
.
info
(
"进入创蓝创建短信接口模板的逻辑
,模板内容:{},模板类型:{}"
,
content
,
type
);
Map
<
String
,
Object
>
requestMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
requestMap
=
new
HashMap
<>();
String
appId
;
String
appId
;
String
username
=
ChuangLanSMSConfig
.
interfaceUser
;
String
username
=
ChuangLanSMSConfig
.
interfaceUser
;
...
...
src/main/java/com/jz/sms/config/ResponseCode.java
View file @
99c7201b
package
com
.
jz
.
sms
.
config
;
package
com
.
jz
.
sms
.
config
;
public
enum
ResponseCode
{
public
enum
ResponseCode
{
// 系统判断错误
SUCCESS
(
"200"
,
"处理成功"
),
SUCCESS
(
"200"
,
"处理成功"
),
UNKNOWN_TEMPLATE_TYPE
(
"500"
,
"未知模板类型"
),
UNKNOWN_TEMPLATE_TYPE
(
"500"
,
"未知模板类型"
),
TEMPLATE_ALREADY_EXISTED
(
"500"
,
"DM Hub模板ID冲突"
),
SYSTEM_ERROR
(
"99"
,
"系统异常:"
),
// 渠道异常错误
UPSTREAM_FAIL
(
"US01"
,
"渠道交易失败"
),
UPSTREAM_FAIL
(
"US01"
,
"渠道交易失败"
),
UPSTREAM_UNKNOWN_MODEL
(
"US01"
,
"未知通知模式"
),
UPSTREAM_UNKNOWN_MODEL
(
"US01"
,
"未知通知模式"
),
UPSTREAM_BLANK
(
"US00"
,
"渠道同步响应为空"
),
UPSTREAM_BLANK
(
"US00"
,
"渠道同步响应为空"
);
SYSTEM_ERROR
(
"99"
,
"系统异常:"
);
private
String
code
;
private
String
code
;
...
...
src/main/java/com/jz/sms/service/bean/TemplateChangeBean.java
View file @
99c7201b
...
@@ -2,12 +2,14 @@ package com.jz.sms.service.bean;
...
@@ -2,12 +2,14 @@ package com.jz.sms.service.bean;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
java.util.List
;
public
class
TemplateChangeBean
{
public
class
TemplateChangeBean
{
private
String
newStr
;
// 创蓝发送短信时需要用的模板内容
private
String
upSendStr
;
// 创蓝创建短信模板需要的模板内容
private
String
upCreateStr
;
private
JSONArray
params
;
private
JSONArray
params
;
...
@@ -16,17 +18,26 @@ public class TemplateChangeBean {
...
@@ -16,17 +18,26 @@ public class TemplateChangeBean {
}
}
public
TemplateChangeBean
(
String
newStr
,
JSONArray
params
)
{
public
TemplateChangeBean
(
String
upSendStr
,
JSONArray
params
,
String
upCreateStr
)
{
this
.
newStr
=
new
Str
;
this
.
upSendStr
=
upSend
Str
;
this
.
params
=
params
;
this
.
params
=
params
;
this
.
upCreateStr
=
upCreateStr
;
}
public
String
getUpSendStr
()
{
return
upSendStr
;
}
public
void
setUpSendStr
(
String
upSendStr
)
{
this
.
upSendStr
=
upSendStr
;
}
}
public
String
get
New
Str
()
{
public
String
get
UpCreate
Str
()
{
return
new
Str
;
return
upCreate
Str
;
}
}
public
void
set
NewStr
(
String
new
Str
)
{
public
void
set
UpCreateStr
(
String
upCreate
Str
)
{
this
.
newStr
=
new
Str
;
this
.
upCreateStr
=
upCreate
Str
;
}
}
public
JSONArray
getParams
()
{
public
JSONArray
getParams
()
{
...
...
src/main/java/com/jz/sms/service/impl/MessageServiceImpl.java
View file @
99c7201b
...
@@ -65,9 +65,13 @@ public class MessageServiceImpl implements MessageService {
...
@@ -65,9 +65,13 @@ public class MessageServiceImpl implements MessageService {
// 替换模板格式,保存适合创蓝发送短信的模板,避免发送时修改模板格式
// 替换模板格式,保存适合创蓝发送短信的模板,避免发送时修改模板格式
TemplateChangeBean
bean
=
dmHub2ChuangLanSend
(
templateContent
);
TemplateChangeBean
bean
=
dmHub2ChuangLanSend
(
templateContent
);
String
chuanglanSend
=
bean
.
get
New
Str
();
String
chuanglanSend
=
bean
.
get
UpSend
Str
();
String
params
=
bean
.
getParams
().
toString
();
String
params
=
bean
.
getParams
().
toString
();
SmsTemplateInfo
dbInfo
=
smsTemplateService
.
selectOne
(
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"dm_template_id"
,
templateId
));
if
(
dbInfo
!=
null
)
{
log
.
error
(
"Dm Hub请求创建模板,模板id已存在,模板id:【{}】"
,
templateId
);
return
new
DmHubTemplateResponse
(
ResponseCode
.
TEMPLATE_ALREADY_EXISTED
);
}
SmsTemplateInfo
info
=
new
SmsTemplateInfo
();
SmsTemplateInfo
info
=
new
SmsTemplateInfo
();
info
.
setContent
(
templateContent
);
info
.
setContent
(
templateContent
);
info
.
setType
(
smsType
);
info
.
setType
(
smsType
);
...
@@ -84,10 +88,10 @@ public class MessageServiceImpl implements MessageService {
...
@@ -84,10 +88,10 @@ public class MessageServiceImpl implements MessageService {
boolean
insert
=
smsTemplateService
.
insert
(
info
);
boolean
insert
=
smsTemplateService
.
insert
(
info
);
if
(!
insert
)
{
if
(!
insert
)
{
//TODO 发送告警
//TODO 发送告警
log
.
error
(
"模板插入DB异常:【{}】"
,
JSONObject
.
toJSONString
(
info
));
return
new
DmHubTemplateResponse
(
ResponseCode
.
SYSTEM_ERROR
);
return
new
DmHubTemplateResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
}
String
chaunglanCreate
=
dmHub2ChuangLanCreate
(
chuanglanSend
);
CLBizResponse
template
=
chuangLanSmsService
.
createTemplate
(
bean
.
getUpCreateStr
(),
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
();
...
@@ -127,25 +131,50 @@ public class MessageServiceImpl implements MessageService {
...
@@ -127,25 +131,50 @@ public class MessageServiceImpl implements MessageService {
}
}
JSONArray
arr
=
new
JSONArray
();
JSONArray
arr
=
new
JSONArray
();
if
(
groups
.
isEmpty
())
{
if
(
groups
.
isEmpty
())
{
return
new
TemplateChangeBean
(
content
,
arr
);
return
new
TemplateChangeBean
(
content
,
arr
,
content
);
}
}
String
upCreateStr
=
content
;
String
upSendStr
=
content
;
for
(
String
g
:
groups
)
{
for
(
String
g
:
groups
)
{
String
t
=
g
;
String
t
=
g
;
g
=
Matcher
.
quoteReplacement
(
g
);
g
=
Matcher
.
quoteReplacement
(
g
);
g
=
escapeRegex
(
g
);
g
=
escapeRegex
(
g
);
content
=
content
.
replaceAll
(
g
,
"\\{\\$var\\}"
);
upSendStr
=
upSendStr
.
replaceAll
(
g
,
"\\{\\$var\\}"
);
if
(
t
.
contains
(
"${surl!"
))
{
// 短链没传长度,固定长度20
upCreateStr
=
upCreateStr
.
replaceAll
(
g
,
"\\{s20\\}"
);
}
else
{
int
i
=
t
.
indexOf
(
"@"
);
int
i1
=
t
.
indexOf
(
"!"
);
String
str
=
t
.
substring
(
i
+
1
,
i1
);
if
(
isNumeric
(
str
))
{
Integer
integer
=
Integer
.
valueOf
(
str
);
if
(
integer
==
0
)
{
upCreateStr
=
upCreateStr
.
replaceAll
(
g
,
"\\{s20\\}"
);
}
else
{
upCreateStr
=
upCreateStr
.
replaceAll
(
g
,
"\\{s"
+
integer
+
"\\}"
);
}
}
else
{
upCreateStr
=
upCreateStr
.
replaceAll
(
g
,
"\\{s20\\}"
);
}
}
}
}
arr
.
addAll
(
groups
);
arr
.
addAll
(
groups
);
return
new
TemplateChangeBean
(
content
,
ar
r
);
return
new
TemplateChangeBean
(
upSendStr
,
arr
,
upCreateSt
r
);
}
}
private
boolean
isNumeric
(
String
str
)
{
public
String
dmHub2ChuangLanCreate
(
String
content
)
{
if
(
StringUtils
.
isBlank
(
str
))
{
// TODO 简单处理,没有处理长度
return
false
;
content
=
content
.
replaceAll
(
"\\{\\$var\\}"
,
"\\{s20\\}"
);
}
return
content
;
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++)
{
System
.
out
.
println
(
str
.
charAt
(
i
));
if
(!
Character
.
isDigit
(
str
.
charAt
(
i
)))
{
return
false
;
}
}
return
true
;
}
}
public
static
String
escapeRegex
(
String
s
)
{
public
static
String
escapeRegex
(
String
s
)
{
...
...
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