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
81fdd480
Commit
81fdd480
authored
Apr 27, 2020
by
qinxunjia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常捕获,日志打印
parent
db54dd3b
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
159 additions
and
80 deletions
+159
-80
ServiceException.java
src/main/java/com/jz/exception/ServiceException.java
+55
-0
ChuangLanApi.java
src/main/java/com/jz/sms/channel/api/ChuangLanApi.java
+2
-0
DmHubApi.java
src/main/java/com/jz/sms/channel/api/DmHubApi.java
+3
-2
ReportDto.java
...main/java/com/jz/sms/channel/chuanglan/dto/ReportDto.java
+17
-0
ChuangLanSmsServiceImpl.java
...annel/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
+7
-10
DmHubService.java
...n/java/com/jz/sms/channel/dmHub/service/DmHubService.java
+1
-1
DmHubServiceImpl.java
...m/jz/sms/channel/dmHub/service/impl/DmHubServiceImpl.java
+65
-51
MessageServiceImpl.java
...main/java/com/jz/sms/service/impl/MessageServiceImpl.java
+3
-4
DateUtil.java
src/main/java/com/jz/sms/util/DateUtil.java
+0
-4
HttpUtil.java
src/main/java/com/jz/util/HttpUtil.java
+1
-2
Md5Util.java
src/main/java/com/jz/util/Md5Util.java
+1
-1
OkHttpUtil.java
src/main/java/com/jz/util/OkHttpUtil.java
+1
-2
Id.java
src/main/java/com/jz/util/id/Id.java
+1
-1
IdHandler.java
src/main/java/com/jz/util/id/IdHandler.java
+1
-1
SystemClock.java
src/main/java/com/jz/util/id/SystemClock.java
+1
-1
No files found.
src/main/java/com/jz/exception/ServiceException.java
0 → 100644
View file @
81fdd480
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
;
}
}
src/main/java/com/jz/sms/channel/api/ChuangLanApi.java
View file @
81fdd480
...
...
@@ -27,6 +27,7 @@ public class ChuangLanApi {
try
{
chuangLanSmsService
.
asyncNotify
(
notifyInfo
);
}
catch
(
Exception
e
)
{
log
.
error
(
"处理创建模板异步通知异常:"
,
e
);
response
=
"fail"
;
}
log
.
info
(
"创蓝异步通知接口出参:{}"
,
response
);
...
...
@@ -40,6 +41,7 @@ public class ChuangLanApi {
try
{
CLBizResponse
responses
=
chuangLanSmsService
.
report
(
report
);
}
catch
(
Exception
e
)
{
log
.
error
(
"处理回执逻辑异常:"
,
e
);
response
=
"fail"
;
}
log
.
info
(
"创蓝异步通知接口出参:{}"
,
response
);
...
...
src/main/java/com/jz/sms/channel/api/DmHubApi.java
View file @
81fdd480
...
...
@@ -32,6 +32,7 @@ public class DmHubApi {
try
{
template
=
messageService
.
createTemplate
(
params
);
}
catch
(
Exception
e
)
{
log
.
error
(
"创建模板短信异常"
,
e
);
template
=
new
DmHubTemplateResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
log
.
info
(
"**********创建模板接口出参*******:{}"
,
JSONObject
.
toJSONString
(
template
));
...
...
@@ -51,13 +52,13 @@ public class DmHubApi {
try
{
response
=
messageService
.
batchSend
(
request
);
}
catch
(
Exception
e
)
{
log
.
error
(
"发送批量短信异常"
,
e
);
response
=
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
log
.
info
(
"**********批量发送出参*******:{}"
,
response
);
return
response
;
}
/**
* 发送单条(通知或营销类)
*
...
...
@@ -69,8 +70,8 @@ public class DmHubApi {
DmHubSendResponse
response
;
try
{
response
=
messageService
.
send
(
request
);
}
catch
(
Exception
e
)
{
log
.
error
(
"发送单条短信异常"
,
e
);
response
=
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
log
.
info
(
"**********单条发送出参*******:{}"
,
JSONObject
.
toJSONString
(
response
));
...
...
src/main/java/com/jz/sms/channel/chuanglan/dto/ReportDto.java
View file @
81fdd480
...
...
@@ -113,4 +113,21 @@ public class ReportDto {
public
void
setStatusDesc
(
String
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
+
'\''
+
'}'
;
}
}
src/main/java/com/jz/sms/channel/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
View file @
81fdd480
...
...
@@ -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.util.HttpUtil
;
import
com.jz.sms.channel.chuanglan.dto.*
;
import
com.jz.sms.channel.chuanglan.service.ChuangLanSmsService
;
import
com.jz.sms.channel.chuanglan.utils.ChuangLanSmsUtil
;
...
...
@@ -12,8 +13,7 @@ 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
;
import
com.jz.sms.util.Md5Util
;
import
com.jz.util.Md5Util
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -22,8 +22,6 @@ import org.springframework.stereotype.Service;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
@SuppressWarnings
(
"DuplicatedCode"
)
...
...
@@ -54,7 +52,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
appId
=
"52"
;
content
=
content
.
replaceAll
(
"回TD退订"
,
""
);
}
else
{
// TODO
自定义异常,
发送警告
// TODO 发送警告
log
.
error
(
"错误,传入的模板类型未知,类型为:{}"
,
type
);
return
new
CLBizResponse
(
ResponseCode
.
SYSTEM_ERROR
,
"未知的模板类型:"
+
type
,
0
);
}
...
...
@@ -176,7 +174,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
);
...
...
@@ -184,10 +182,9 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
@Override
public
CLBizResponse
report
(
ReportDto
report
)
throws
Exception
{
// TODO 状态报告要特殊处理,一个个接受,批量发送
String
uid
=
report
.
getUid
();
Map
<
String
,
Object
>
ret
=
dmHubService
.
smsReport
(
report
);
public
CLBizResponse
report
(
ReportDto
report
)
throws
Exception
{
// TODO 状态报告要特殊处理,一个个接受,批量发送(处理方式待定)
dmHubService
.
smsReport
(
report
);
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
);
}
...
...
src/main/java/com/jz/sms/channel/dmHub/service/DmHubService.java
View file @
81fdd480
...
...
@@ -11,7 +11,7 @@ public interface DmHubService {
*
* @return token信息
*/
String
getToken
()
throws
Exception
;
String
getToken
()
;
/**
...
...
src/main/java/com/jz/sms/channel/dmHub/service/impl/DmHubServiceImpl.java
View file @
81fdd480
...
...
@@ -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.dto.DmhubReport
;
import
com.jz.sms.channel.dto.ReportDetail
;
import
com.jz.
sms.
util.HttpUtil
;
import
com.jz.
sms.
util.OkHttpUtil
;
import
com.jz.util.HttpUtil
;
import
com.jz.util.OkHttpUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -34,64 +34,78 @@ public class DmHubServiceImpl implements DmHubService {
@Override
public
String
getToken
()
throws
Exception
{
String
token
=
redisTemplate
.
opsForValue
().
get
(
TOKEN_KEY
).
toString
();
Long
expire
=
redisTemplate
.
opsForValue
().
getOperations
().
getExpire
(
TOKEN_KEY
);
if
(
expire
!=
null
&&
expire
>
0L
)
{
return
token
;
}
else
{
String
appid
=
DmHubConfig
.
applicationId
;
String
secret
=
DmHubConfig
.
applicationKey
;
String
tokenUrl
=
DmHubConfig
.
tokenUrl
;
String
grantType
=
"client_credentials"
;
Map
<
String
,
String
>
requestMap
=
new
HashMap
<>();
requestMap
.
put
(
"appid"
,
appid
);
requestMap
.
put
(
"secret"
,
secret
);
requestMap
.
put
(
"grant_type"
,
grantType
);
String
retStr
=
OkHttpUtil
.
get
(
tokenUrl
,
requestMap
);
JSONObject
retJson
=
JSONObject
.
parseObject
(
retStr
);
String
errorCode
=
retJson
.
getString
(
"error_code"
);
if
(
"0"
.
equals
(
errorCode
))
{
String
accessToken
=
retJson
.
getString
(
"access_token"
);
String
expires
=
retJson
.
getString
(
"expires_in"
);
redisTemplate
.
opsForValue
().
set
(
"DM_HUB_TOKEN"
,
accessToken
,
Long
.
parseLong
(
expires
)
-
600L
,
TimeUnit
.
SECONDS
);
return
accessToken
;
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
;
}
else
{
// TODO 系统告警,获取API接口TOKEN失败。
return
null
;
String
appid
=
DmHubConfig
.
applicationId
;
String
secret
=
DmHubConfig
.
applicationKey
;
String
tokenUrl
=
DmHubConfig
.
tokenUrl
;
String
grantType
=
"client_credentials"
;
Map
<
String
,
String
>
requestMap
=
new
HashMap
<>();
requestMap
.
put
(
"appid"
,
appid
);
requestMap
.
put
(
"secret"
,
secret
);
requestMap
.
put
(
"grant_type"
,
grantType
);
String
retStr
=
OkHttpUtil
.
get
(
tokenUrl
,
requestMap
);
JSONObject
retJson
=
JSONObject
.
parseObject
(
retStr
);
String
errorCode
=
retJson
.
getString
(
"error_code"
);
if
(
"0"
.
equals
(
errorCode
))
{
String
accessToken
=
retJson
.
getString
(
"access_token"
);
String
expires
=
retJson
.
getString
(
"expires_in"
);
long
exTime
=
Long
.
parseLong
(
expires
)
-
60
*
10L
;
redisTemplate
.
opsForValue
().
set
(
TOKEN_KEY
,
accessToken
,
exTime
,
TimeUnit
.
SECONDS
);
return
accessToken
;
}
else
{
// TODO 系统告警,获取API接口TOKEN失败。
return
null
;
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"获取API接口TOKEN业务逻辑异常,异常信息:\r\n"
,
e
);
return
null
;
}
}
@Override
public
Map
<
String
,
Object
>
smsReport
(
ReportDto
dto
)
throws
Exception
{
String
token
=
getToken
();
if
(
StringUtils
.
isBlank
(
token
))
{
return
null
;
}
DmhubReport
report
=
new
DmhubReport
();
report
.
setAccess_token
(
token
);
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
);
try
{
String
token
=
getToken
();
if
(
StringUtils
.
isBlank
(
token
))
{
return
null
;
}
DmhubReport
report
=
new
DmhubReport
();
report
.
setAccess_token
(
token
);
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
);
//TODO 目前没有测试环境的请求地址
}
catch
(
Exception
e
)
{
log
.
info
(
"发送短信回执到DMHub异常\r\n短信信息:{},\r\n,异常:"
,
dto
,
e
);
}
detail
.
setErrMessage
(
dto
.
getStatusDesc
());
report
.
setReports
(
detail
);
log
.
info
(
"短信状态回执参数:{}"
,
JSONObject
.
toJSONString
(
report
));
String
retStr
=
HttpUtil
.
sendPost
(
DmHubConfig
.
report
,
JSONObject
.
toJSONString
(
report
));
log
.
info
(
"短信状态回执响应:{}"
,
retStr
);
//TODO 目前没有测试环境的请求地址
return
null
;
}
}
src/main/java/com/jz/sms/service/impl/MessageServiceImpl.java
View file @
81fdd480
...
...
@@ -14,7 +14,7 @@ import com.jz.sms.service.DmBatchService;
import
com.jz.sms.service.MessageService
;
import
com.jz.sms.service.SmsTemplateService
;
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.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -96,11 +96,10 @@ public class MessageServiceImpl implements MessageService {
return
responseDTO
;
}
else
{
//TODO 发送告警,模板添加失败。
return
new
DmHubTemplateResponse
(
template
.
getCode
(),
template
.
getMsg
());
}
}
catch
(
Exception
exception
)
{
log
.
error
(
"错误信息"
,
exception
);
log
.
error
(
"
创建模板业务逻辑异常,
错误信息"
,
exception
);
responseDTO
=
new
DmHubTemplateResponse
(
"500"
,
"系统异常"
);
}
return
responseDTO
;
...
...
@@ -115,7 +114,7 @@ public class MessageServiceImpl implements MessageService {
* @return
*/
public
TemplateChangeBean
dmHub2ChuangLanSend
(
String
content
)
{
// String regex = "\\$\\{[^}]+\\}";
//正则获取${***} 和 ${surl***'}格式的内容,其中:((?:\$\{surl.*'\}))獲取${surl***'}格式,\$\{[^}]+\} 获取${***}格式,顺序不能变,否则不能完成匹配格式一
String
regex
=
"((?:\\$\\{surl.*'\\}))|\\$\\{[^}]+\\}"
;
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Matcher
matcher
=
pattern
.
matcher
(
content
);
...
...
src/main/java/com/jz/sms/util/DateUtil.java
deleted
100644 → 0
View file @
db54dd3b
package
com
.
jz
.
sms
.
util
;
public
class
DateUtil
{
}
src/main/java/com/jz/
sms/
util/HttpUtil.java
→
src/main/java/com/jz/util/HttpUtil.java
View file @
81fdd480
package
com
.
jz
.
sms
.
util
;
package
com
.
jz
.
util
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
...
...
@@ -8,7 +8,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.protocol.HTTP
;
import
sun.net.www.http.HttpClient
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
...
...
src/main/java/com/jz/
sms/
util/Md5Util.java
→
src/main/java/com/jz/util/Md5Util.java
View file @
81fdd480
package
com
.
jz
.
sms
.
util
;
package
com
.
jz
.
util
;
import
java.security.MessageDigest
;
...
...
src/main/java/com/jz/
sms/
util/OkHttpUtil.java
→
src/main/java/com/jz/util/OkHttpUtil.java
View file @
81fdd480
package
com
.
jz
.
sms
.
util
;
package
com
.
jz
.
util
;
import
com.baomidou.mybatisplus.toolkit.MapUtils
;
import
okhttp3.*
;
...
...
src/main/java/com/jz/
sms/
util/id/Id.java
→
src/main/java/com/jz/util/id/Id.java
View file @
81fdd480
package
com
.
jz
.
sms
.
util
.
id
;
package
com
.
jz
.
util
.
id
;
import
java.text.ParseException
;
...
...
src/main/java/com/jz/
sms/
util/id/IdHandler.java
→
src/main/java/com/jz/util/id/IdHandler.java
View file @
81fdd480
package
com
.
jz
.
sms
.
util
.
id
;
package
com
.
jz
.
util
.
id
;
public
class
IdHandler
{
...
...
src/main/java/com/jz/
sms/
util/id/SystemClock.java
→
src/main/java/com/jz/util/id/SystemClock.java
View file @
81fdd480
package
com
.
jz
.
sms
.
util
.
id
;
package
com
.
jz
.
util
.
id
;
import
java.sql.Timestamp
;
import
java.util.concurrent.Executors
;
...
...
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