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
7b5c8a80
Commit
7b5c8a80
authored
Jun 19, 2020
by
qinxunjia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
签名校验,模板名称格式限制
parent
c97c7204
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
78 additions
and
145 deletions
+78
-145
DmHubApi.java
src/main/java/com/bgy/sms/channel/api/DmHubApi.java
+37
-8
BgySmsService.java
...n/java/com/bgy/sms/channel/bgy/service/BgySmsService.java
+1
-2
BgySmsServiceImpl.java
...m/bgy/sms/channel/bgy/service/impl/BgySmsServiceImpl.java
+2
-2
DmHubConfig.java
...in/java/com/bgy/sms/channel/dmHub/config/DmHubConfig.java
+13
-3
DmHubServiceImpl.java
.../bgy/sms/channel/dmHub/service/impl/DmHubServiceImpl.java
+0
-1
MessageService.java
src/main/java/com/bgy/sms/service/MessageService.java
+0
-8
MessageServiceImpl.java
...ain/java/com/bgy/sms/service/impl/MessageServiceImpl.java
+19
-121
application-dev.yml
src/main/resources/application-dev.yml
+2
-0
application-prod.yml
src/main/resources/application-prod.yml
+2
-0
application-test.yml
src/main/resources/application-test.yml
+2
-0
No files found.
src/main/java/com/bgy/sms/channel/api/DmHubApi.java
View file @
7b5c8a80
package
com
.
bgy
.
sms
.
channel
.
api
;
package
com
.
bgy
.
sms
.
channel
.
api
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.bgy.sms.channel.dmHub.config.DmHubConfig
;
import
com.bgy.sms.channel.dto.*
;
import
com.bgy.sms.channel.dto.*
;
import
com.bgy.sms.config.ResponseCode
;
import
com.bgy.sms.config.ResponseCode
;
import
com.bgy.sms.service.MessageService
;
import
com.bgy.sms.service.MessageService
;
import
com.bgy.util.Md5Util
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
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
javax.servlet.http.HttpServletRequest
;
@SuppressWarnings
(
"Duplicates"
)
@SuppressWarnings
(
"Duplicates"
)
@RestController
@RestController
@RequestMapping
()
@RequestMapping
()
...
@@ -25,10 +29,14 @@ public class DmHubApi {
...
@@ -25,10 +29,14 @@ public class DmHubApi {
* @return
* @return
*/
*/
@PostMapping
(
"/sms/template"
)
@PostMapping
(
"/sms/template"
)
public
DmHubResponse
template
(
@RequestBody
DmHubTemplateRequest
params
)
{
public
DmHubResponse
template
(
@RequestBody
DmHubTemplateRequest
params
,
String
appId
,
String
timestamp
,
String
signature
)
{
log
.
info
(
"**********创建模板接口入参*******:{}
"
,
JSONObject
.
toJSONString
(
params
)
);
log
.
info
(
"**********创建模板接口入参*******:{}
,\r\n appId:{},timestamp:{},signature:{}"
,
JSONObject
.
toJSONString
(
params
),
appId
,
timestamp
,
signature
);
DmHubResponse
response
;
DmHubResponse
response
;
try
{
try
{
boolean
checkResult
=
this
.
checkSignature
(
timestamp
,
signature
);
if
(!
checkResult
)
{
return
new
DmHubResponse
(
"555"
,
"签名校验不通过"
);
}
response
=
messageService
.
createTemplate
(
params
);
response
=
messageService
.
createTemplate
(
params
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"创建模板短信异常"
,
e
);
log
.
error
(
"创建模板短信异常"
,
e
);
...
@@ -44,10 +52,14 @@ public class DmHubApi {
...
@@ -44,10 +52,14 @@ public class DmHubApi {
* @return
* @return
*/
*/
@PostMapping
(
"/sms/verifyCode"
)
@PostMapping
(
"/sms/verifyCode"
)
public
DmHubResponse
verifyCode
(
@RequestBody
DmHubCodeRequest
params
)
{
public
DmHubResponse
verifyCode
(
@RequestBody
DmHubCodeRequest
params
,
String
appId
,
String
timestamp
,
String
signature
)
{
log
.
info
(
"**********发送短信验证码*******:{}
"
,
JSONObject
.
toJSONString
(
params
)
);
log
.
info
(
"**********发送短信验证码*******:{}
,\r\n appId:{},timestamp:{},signature:{}"
,
JSONObject
.
toJSONString
(
params
),
appId
,
timestamp
,
signature
);
DmHubResponse
response
;
DmHubResponse
response
;
try
{
try
{
boolean
checkResult
=
this
.
checkSignature
(
timestamp
,
signature
);
if
(!
checkResult
)
{
return
new
DmHubResponse
(
"555"
,
"签名校验不通过"
);
}
response
=
messageService
.
sendCode
(
params
);
response
=
messageService
.
sendCode
(
params
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"发送验证码短信异常"
,
e
);
log
.
error
(
"发送验证码短信异常"
,
e
);
...
@@ -64,10 +76,14 @@ public class DmHubApi {
...
@@ -64,10 +76,14 @@ public class DmHubApi {
* @return
* @return
*/
*/
@PostMapping
(
"/sms/batch"
)
@PostMapping
(
"/sms/batch"
)
public
DmHubResponse
batch
(
@RequestBody
DmHubBatchSendRequest
request
)
{
public
DmHubResponse
batch
(
@RequestBody
DmHubBatchSendRequest
request
,
String
appId
,
String
timestamp
,
String
signature
)
{
log
.
info
(
"**********批量发送入参*******:{}
"
,
JSONObject
.
toJSONString
(
request
)
);
log
.
info
(
"**********批量发送入参*******:{}
,\r\n appId:{},timestamp:{},signature:{}"
,
JSONObject
.
toJSONString
(
request
),
appId
,
timestamp
,
signature
);
DmHubResponse
response
;
DmHubResponse
response
;
try
{
try
{
boolean
checkResult
=
this
.
checkSignature
(
timestamp
,
signature
);
if
(!
checkResult
)
{
return
new
DmHubResponse
(
"555"
,
"签名校验不通过"
);
}
response
=
messageService
.
batchSendOneByOne
(
request
);
response
=
messageService
.
batchSendOneByOne
(
request
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"发送批量短信异常"
,
e
);
log
.
error
(
"发送批量短信异常"
,
e
);
...
@@ -77,16 +93,29 @@ public class DmHubApi {
...
@@ -77,16 +93,29 @@ public class DmHubApi {
return
response
;
return
response
;
}
}
public
boolean
checkSignature
(
String
timestamp
,
String
signature
)
{
String
encrypt
=
Md5Util
.
encrypt
(
DmHubConfig
.
appId
+
DmHubConfig
.
appSecret
+
timestamp
);
if
(!
encrypt
.
equals
(
signature
))
{
return
false
;
}
return
true
;
}
/**
/**
* 发送单条(通知或营销类)
* 发送单条(通知或营销类)
*
*
* @return
* @return
*/
*/
@RequestMapping
(
"/sms/send"
)
@RequestMapping
(
"/sms/send"
)
public
DmHubResponse
send
(
@RequestBody
DmHubSendRequest
request
)
{
public
DmHubResponse
send
(
@RequestBody
DmHubSendRequest
request
,
String
appId
,
String
timestamp
,
String
signature
)
{
log
.
info
(
"**********单条发送入参*******:{}
"
,
JSONObject
.
toJSONString
(
request
)
);
log
.
info
(
"**********单条发送入参*******:{}
,\r\n appId:{},timestamp:{},signature:{}"
,
JSONObject
.
toJSONString
(
request
),
appId
,
timestamp
,
signature
);
DmHubResponse
response
;
DmHubResponse
response
;
try
{
try
{
boolean
checkResult
=
this
.
checkSignature
(
timestamp
,
signature
);
if
(!
checkResult
)
{
return
new
DmHubResponse
(
"555"
,
"签名校验不通过"
);
}
response
=
messageService
.
send
(
request
);
response
=
messageService
.
send
(
request
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"发送单条短信异常"
,
e
);
log
.
error
(
"发送单条短信异常"
,
e
);
...
...
src/main/java/com/bgy/sms/channel/bgy/service/BgySmsService.java
View file @
7b5c8a80
...
@@ -5,8 +5,7 @@ import com.bgy.sms.channel.bgy.dto.CLBizResponse;
...
@@ -5,8 +5,7 @@ import com.bgy.sms.channel.bgy.dto.CLBizResponse;
public
interface
BgySmsService
{
public
interface
BgySmsService
{
CLBizResponse
sendSms
(
String
mobile
,
String
content
,
String
areaId
)
throws
Exception
;
CLBizResponse
sendSms
(
String
mobile
,
String
content
)
throws
Exception
;
}
}
src/main/java/com/bgy/sms/channel/bgy/service/impl/BgySmsServiceImpl.java
View file @
7b5c8a80
...
@@ -39,10 +39,10 @@ public class BgySmsServiceImpl implements BgySmsService {
...
@@ -39,10 +39,10 @@ public class BgySmsServiceImpl implements BgySmsService {
private
DmHubService
dmHubService
;
private
DmHubService
dmHubService
;
@Override
@Override
public
CLBizResponse
sendSms
(
String
mobile
,
String
content
)
throws
Exception
{
public
CLBizResponse
sendSms
(
String
mobile
,
String
content
,
String
areaId
)
throws
Exception
{
log
.
info
(
"进入碧桂园短信发送接口"
);
log
.
info
(
"进入碧桂园短信发送接口"
);
String
appId
=
BgySMSConfig
.
appId
;
String
appId
=
BgySMSConfig
.
appId
;
String
areaId
=
BgySMSConfig
.
areaId
;
//
String areaId = BgySMSConfig.areaId;
String
securityCode
=
BgySMSConfig
.
securityCode
;
String
securityCode
=
BgySMSConfig
.
securityCode
;
String
url
=
BgySMSConfig
.
url
;
String
url
=
BgySMSConfig
.
url
;
String
api
=
BgySMSConfig
.
api
;
String
api
=
BgySMSConfig
.
api
;
...
...
src/main/java/com/bgy/sms/channel/dmHub/config/DmHubConfig.java
View file @
7b5c8a80
...
@@ -13,14 +13,14 @@ public class DmHubConfig {
...
@@ -13,14 +13,14 @@ public class DmHubConfig {
public
static
String
applicationKey
;
public
static
String
applicationKey
;
public
static
String
tokenUrl
;
public
static
String
tokenUrl
;
public
static
String
report
;
public
static
String
report
;
public
static
String
appId
;
public
static
String
appSecret
;
@Value
(
"${system.config.dmHub.applicationId}"
)
@Value
(
"${system.config.dmHub.applicationId}"
)
public
void
setApplicationId
(
String
applicationId
)
{
public
void
setApplicationId
(
String
applicationId
)
{
DmHubConfig
.
applicationId
=
applicationId
;
DmHubConfig
.
applicationId
=
applicationId
;
}
}
@Value
(
"{system.config.dmHub.applicationKey}"
)
@Value
(
"{system.config.dmHub.applicationKey}"
)
public
void
setApplicationKey
(
String
applicationKey
)
{
public
void
setApplicationKey
(
String
applicationKey
)
{
DmHubConfig
.
applicationKey
=
applicationKey
;
DmHubConfig
.
applicationKey
=
applicationKey
;
...
@@ -36,5 +36,15 @@ public class DmHubConfig {
...
@@ -36,5 +36,15 @@ public class DmHubConfig {
DmHubConfig
.
report
=
report
;
DmHubConfig
.
report
=
report
;
}
}
@Value
(
"{system.config.dmHub.appId}"
)
public
void
setAppId
(
String
appId
)
{
DmHubConfig
.
appId
=
appId
;
}
@Value
(
"{system.config.dmHub.appSecret}"
)
public
void
setAppSecret
(
String
appSecret
)
{
DmHubConfig
.
appSecret
=
appSecret
;
}
}
}
src/main/java/com/bgy/sms/channel/dmHub/service/impl/DmHubServiceImpl.java
View file @
7b5c8a80
...
@@ -63,7 +63,6 @@ public class DmHubServiceImpl implements DmHubService {
...
@@ -63,7 +63,6 @@ public class DmHubServiceImpl implements DmHubService {
redisTemplate
.
opsForValue
().
set
(
TOKEN_KEY
,
accessToken
,
exTime
,
TimeUnit
.
SECONDS
);
redisTemplate
.
opsForValue
().
set
(
TOKEN_KEY
,
accessToken
,
exTime
,
TimeUnit
.
SECONDS
);
return
accessToken
;
return
accessToken
;
}
else
{
}
else
{
// TODO 系统告警,获取API接口TOKEN失败。
return
null
;
return
null
;
}
}
}
}
...
...
src/main/java/com/bgy/sms/service/MessageService.java
View file @
7b5c8a80
...
@@ -20,14 +20,6 @@ public interface MessageService {
...
@@ -20,14 +20,6 @@ public interface MessageService {
*/
*/
DmHubResponse
send
(
DmHubSendRequest
requestDTO
);
DmHubResponse
send
(
DmHubSendRequest
requestDTO
);
/**
* DM hub批量发送短信接口
*
* @param requestDTO
* @return
*/
DmHubResponse
batchSend
(
DmHubBatchSendRequest
requestDTO
);
/**
/**
* DM hub批量发送短信接口
* DM hub批量发送短信接口
*
*
...
...
src/main/java/com/bgy/sms/service/impl/MessageServiceImpl.java
View file @
7b5c8a80
This diff is collapsed.
Click to expand it.
src/main/resources/application-dev.yml
View file @
7b5c8a80
...
@@ -40,6 +40,8 @@ system:
...
@@ -40,6 +40,8 @@ system:
applicationKey
:
4017078e9dfd593b2d9a0ede58eff589644fbe50
applicationKey
:
4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl
:
https://api.convertlab.com/security/accesstoken
tokenUrl
:
https://api.convertlab.com/security/accesstoken
report
:
https://api.convertlab.com/v1/sms/report
report
:
https://api.convertlab.com/v1/sms/report
appId
:
1smsdemo
appSecret
:
ac031765c3a8c9acc4747808e4fe5918
logging
:
logging
:
level
:
debug
level
:
debug
...
...
src/main/resources/application-prod.yml
View file @
7b5c8a80
...
@@ -41,6 +41,8 @@ system:
...
@@ -41,6 +41,8 @@ system:
applicationKey
:
4017078e9dfd593b2d9a0ede58eff589644fbe50
applicationKey
:
4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl
:
https://api.convertlab.com/security/accesstoken
tokenUrl
:
https://api.convertlab.com/security/accesstoken
report
:
https://api.convertlab.com/v1/sms/report
report
:
https://api.convertlab.com/v1/sms/report
appId
:
1smsdemo
appSecret
:
ac031765c3a8c9acc4747808e4fe5918
logging
:
logging
:
level
:
error
level
:
error
...
...
src/main/resources/application-test.yml
View file @
7b5c8a80
...
@@ -40,6 +40,8 @@ system:
...
@@ -40,6 +40,8 @@ system:
applicationKey
:
4017078e9dfd593b2d9a0ede58eff589644fbe50
applicationKey
:
4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl
:
https://api.convertlab.com/security/accesstoken
tokenUrl
:
https://api.convertlab.com/security/accesstoken
report
:
https://api.convertlab.com/v1/sms/report
report
:
https://api.convertlab.com/v1/sms/report
appId
:
1smsdemo
appSecret
:
ac031765c3a8c9acc4747808e4fe5918
logging
:
logging
:
level
:
debug
level
:
debug
...
...
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