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
9eb6393b
Commit
9eb6393b
authored
Apr 24, 2020
by
qinxunjia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
规范接口
parent
561456b1
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
333 additions
and
91 deletions
+333
-91
pom.xml
pom.xml
+16
-0
BizController.java
src/main/java/com/jz/sms/api/BizController.java
+2
-4
ChuangLanApi.java
src/main/java/com/jz/sms/api/ChuangLanApi.java
+2
-2
CLBizResponse.java
src/main/java/com/jz/sms/chuanglan/dto/CLBizResponse.java
+28
-6
CLSendSMSResponse.java
...main/java/com/jz/sms/chuanglan/dto/CLSendSMSResponse.java
+20
-0
CLSendVariableRequest.java
.../java/com/jz/sms/chuanglan/dto/CLSendVariableRequest.java
+10
-0
ChuangLanSmsService.java
...ava/com/jz/sms/chuanglan/service/ChuangLanSmsService.java
+6
-7
ChuangLanSmsServiceImpl.java
...z/sms/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
+41
-19
OkHttpConfig.java
src/main/java/com/jz/sms/config/OkHttpConfig.java
+26
-0
ResponseCode.java
src/main/java/com/jz/sms/config/ResponseCode.java
+5
-1
DmHubBatchSendResponse.java
src/main/java/com/jz/sms/dto/DmHubBatchSendResponse.java
+0
-32
DmHubSendResponse.java
src/main/java/com/jz/sms/dto/DmHubSendResponse.java
+35
-0
MessageService.java
src/main/java/com/jz/sms/service/MessageService.java
+1
-1
MessageServiceImpl.java
...main/java/com/jz/sms/service/impl/MessageServiceImpl.java
+47
-19
OkHttpUtil.java
src/main/java/com/jz/sms/util/OkHttpUtil.java
+94
-0
No files found.
pom.xml
View file @
9eb6393b
...
@@ -79,6 +79,22 @@
...
@@ -79,6 +79,22 @@
<groupId>
org.apache.httpcomponents
</groupId>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<artifactId>
httpclient
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<finalName>
dmhub-plugin
</finalName>
<finalName>
dmhub-plugin
</finalName>
...
...
src/main/java/com/jz/sms/api/BizController.java
View file @
9eb6393b
...
@@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
...
@@ -8,8 +8,6 @@ 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
java.util.Map
;
@RestController
@RestController
@RequestMapping
(
"/test"
)
@RequestMapping
(
"/test"
)
public
class
BizController
{
public
class
BizController
{
...
@@ -41,9 +39,9 @@ public class BizController {
...
@@ -41,9 +39,9 @@ public class BizController {
* @return
* @return
*/
*/
@PostMapping
(
"/sms/batch"
)
@PostMapping
(
"/sms/batch"
)
public
DmHub
Batch
SendResponse
batch
(
@RequestBody
DmHubBatchSendRequest
request
)
{
public
DmHubSendResponse
batch
(
@RequestBody
DmHubBatchSendRequest
request
)
{
log
.
info
(
"**********批量发送入参*******:{}"
,
JSONObject
.
toJSONString
(
request
));
log
.
info
(
"**********批量发送入参*******:{}"
,
JSONObject
.
toJSONString
(
request
));
DmHub
Batch
SendResponse
response
=
messageService
.
batchSend
(
request
);
DmHubSendResponse
response
=
messageService
.
batchSend
(
request
);
// log.info("**********批量发送入参*******:{}", response);
// log.info("**********批量发送入参*******:{}", response);
return
response
;
return
response
;
}
}
...
...
src/main/java/com/jz/sms/api/ChuangLanApi.java
View file @
9eb6393b
package
com
.
jz
.
sms
.
api
;
package
com
.
jz
.
sms
.
api
;
import
com.jz.sms.chuanglan.dto.CLBizResponse
;
import
com.jz.sms.chuanglan.dto.CLNotifyRequest
;
import
com.jz.sms.chuanglan.dto.CLNotifyRequest
;
import
com.jz.sms.chuanglan.dto.ReportDto
;
import
com.jz.sms.chuanglan.dto.ReportDto
;
import
com.jz.sms.chuanglan.service.ChuangLanSmsService
;
import
com.jz.sms.chuanglan.service.ChuangLanSmsService
;
...
@@ -40,8 +41,7 @@ public class ChuangLanApi {
...
@@ -40,8 +41,7 @@ public class ChuangLanApi {
public
String
report
(
@RequestParam
ReportDto
report
)
{
public
String
report
(
@RequestParam
ReportDto
report
)
{
log
.
info
(
"回送报告接口入参:{}"
,
report
);
log
.
info
(
"回送报告接口入参:{}"
,
report
);
chuangLanSmsService
.
report
(
report
);
CLBizResponse
responses
=
chuangLanSmsService
.
report
(
report
);
String
response
=
"success"
;
String
response
=
"success"
;
log
.
info
(
"创蓝异步通知接口出参:{}"
,
response
);
log
.
info
(
"创蓝异步通知接口出参:{}"
,
response
);
...
...
src/main/java/com/jz/sms/chuanglan/dto/CL
Template
Response.java
→
src/main/java/com/jz/sms/chuanglan/dto/CL
Biz
Response.java
View file @
9eb6393b
package
com
.
jz
.
sms
.
chuanglan
.
dto
;
package
com
.
jz
.
sms
.
chuanglan
.
dto
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.sms.config.ResponseCode
;
import
com.jz.sms.config.ResponseCode
;
import
java.io.Serializable
;
import
java.io.Serializable
;
public
class
CL
Template
Response
implements
Serializable
{
public
class
CL
Biz
Response
implements
Serializable
{
private
String
code
;
private
String
code
;
...
@@ -13,28 +14,40 @@ public class CLTemplateResponse implements Serializable {
...
@@ -13,28 +14,40 @@ public class CLTemplateResponse implements Serializable {
private
String
id
;
private
String
id
;
public
CLTemplateResponse
()
{
private
JSONObject
data
;
public
CLBizResponse
()
{
}
}
public
CLTemplateResponse
(
ResponseCode
responseCode
,
String
id
)
{
public
CLBizResponse
(
ResponseCode
responseCode
)
{
this
.
code
=
responseCode
.
getCode
();
this
.
msg
=
responseCode
.
getMsg
();
}
public
CLBizResponse
(
ResponseCode
responseCode
,
JSONObject
data
)
{
this
.
code
=
responseCode
.
getCode
();
this
.
msg
=
responseCode
.
getMsg
();
this
.
data
=
data
;
}
public
CLBizResponse
(
ResponseCode
responseCode
,
String
id
)
{
this
.
code
=
responseCode
.
getCode
();
this
.
code
=
responseCode
.
getCode
();
this
.
msg
=
responseCode
.
getMsg
();
this
.
msg
=
responseCode
.
getMsg
();
this
.
id
=
id
;
this
.
id
=
id
;
}
}
public
CL
TemplateResponse
(
ResponseCode
responseCode
,
String
msg
,
int
nullInfo
)
{
public
CL
BizResponse
(
ResponseCode
responseCode
,
String
msg
,
int
nullInfo
)
{
this
.
code
=
responseCode
.
getCode
();
this
.
code
=
responseCode
.
getCode
();
this
.
msg
=
responseCode
.
getMsg
()+
msg
;
this
.
msg
=
responseCode
.
getMsg
()+
msg
;
}
}
public
CL
Template
Response
(
String
code
,
String
msg
)
{
public
CL
Biz
Response
(
String
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
code
=
code
;
this
.
msg
=
msg
;
this
.
msg
=
msg
;
}
}
public
CL
Template
Response
(
String
code
,
String
msg
,
String
id
)
{
public
CL
Biz
Response
(
String
code
,
String
msg
,
String
id
)
{
this
.
code
=
code
;
this
.
code
=
code
;
this
.
msg
=
msg
;
this
.
msg
=
msg
;
this
.
id
=
id
;
this
.
id
=
id
;
...
@@ -61,6 +74,15 @@ public class CLTemplateResponse implements Serializable {
...
@@ -61,6 +74,15 @@ public class CLTemplateResponse implements Serializable {
}
}
public
void
setId
(
String
id
)
{
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
this
.
id
=
id
;
}
}
public
JSONObject
getData
()
{
return
data
;
}
public
void
setData
(
JSONObject
data
)
{
this
.
data
=
data
;
}
}
}
src/main/java/com/jz/sms/chuanglan/dto/CLSendSMSResponse.java
View file @
9eb6393b
...
@@ -18,6 +18,10 @@ public class CLSendSMSResponse {
...
@@ -18,6 +18,10 @@ public class CLSendSMSResponse {
*/
*/
private
String
code
;
private
String
code
;
private
String
failNum
;
private
String
successNum
;
public
CLSendSMSResponse
(){}
public
CLSendSMSResponse
(){}
...
@@ -58,6 +62,22 @@ public class CLSendSMSResponse {
...
@@ -58,6 +62,22 @@ public class CLSendSMSResponse {
this
.
code
=
code
;
this
.
code
=
code
;
}
}
public
String
getFailNum
()
{
return
failNum
;
}
public
void
setFailNum
(
String
failNum
)
{
this
.
failNum
=
failNum
;
}
public
String
getSuccessNum
()
{
return
successNum
;
}
public
void
setSuccessNum
(
String
successNum
)
{
this
.
successNum
=
successNum
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"SmsSingleResponse [time="
+
time
+
", msgId="
+
msgId
+
", errorMsg="
+
errorMsg
+
", code="
+
code
return
"SmsSingleResponse [time="
+
time
+
", msgId="
+
msgId
+
", errorMsg="
+
errorMsg
+
", code="
+
code
...
...
src/main/java/com/jz/sms/chuanglan/dto/CLSendVariableRequest.java
View file @
9eb6393b
...
@@ -58,6 +58,16 @@ public class CLSendVariableRequest {
...
@@ -58,6 +58,16 @@ public class CLSendVariableRequest {
this
.
report
=
report
;
this
.
report
=
report
;
}
}
public
CLSendVariableRequest
(
String
account
,
String
password
,
String
msg
,
String
params
,
String
report
,
String
uid
)
{
super
();
this
.
account
=
account
;
this
.
password
=
password
;
this
.
msg
=
msg
;
this
.
params
=
params
;
this
.
report
=
report
;
this
.
uid
=
uid
;
}
// public SmsVarableRequest(String account, String password, String msg, String params, String sendtime) {
// public SmsVarableRequest(String account, String password, String msg, String params, String sendtime) {
// super();
// super();
// this.account = account;
// this.account = account;
...
...
src/main/java/com/jz/sms/chuanglan/service/ChuangLanSmsService.java
View file @
9eb6393b
...
@@ -2,22 +2,21 @@ package com.jz.sms.chuanglan.service;
...
@@ -2,22 +2,21 @@ package com.jz.sms.chuanglan.service;
import
com.jz.sms.chuanglan.dto.CLNotifyRequest
;
import
com.jz.sms.chuanglan.dto.CLNotifyRequest
;
import
com.jz.sms.chuanglan.dto.CLSendSMSResponse
;
import
com.jz.sms.chuanglan.dto.CLSendSMSResponse
;
import
com.jz.sms.chuanglan.dto.CL
Template
Response
;
import
com.jz.sms.chuanglan.dto.CL
Biz
Response
;
import
com.jz.sms.chuanglan.dto.ReportDto
;
import
com.jz.sms.chuanglan.dto.ReportDto
;
import
com.jz.sms.dto.*
;
public
interface
ChuangLanSmsService
{
public
interface
ChuangLanSmsService
{
CL
Template
Response
createTemplate
(
String
content
,
String
type
)
throws
Exception
;
CL
Biz
Response
createTemplate
(
String
content
,
String
type
)
throws
Exception
;
CL
SendSMS
Response
sendByFixed
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
CL
Biz
Response
sendByFixed
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
CL
SendSMS
Response
sendByVariable
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
CL
Biz
Response
sendByVariable
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
;
void
asyncNotify
(
CLNotifyRequest
notifyInfo
);
CLBizResponse
asyncNotify
(
CLNotifyRequest
notifyInfo
);
void
report
(
ReportDto
report
);
CLBizResponse
report
(
ReportDto
report
);
}
}
src/main/java/com/jz/sms/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
View file @
9eb6393b
...
@@ -10,7 +10,6 @@ import com.jz.sms.chuanglan.service.ChuangLanSmsService;
...
@@ -10,7 +10,6 @@ import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import
com.jz.sms.chuanglan.utils.ChuangLanSmsUtil
;
import
com.jz.sms.chuanglan.utils.ChuangLanSmsUtil
;
import
com.jz.sms.chuanglan.config.ChuangLanSMSConfig
;
import
com.jz.sms.chuanglan.config.ChuangLanSMSConfig
;
import
com.jz.sms.config.ResponseCode
;
import
com.jz.sms.config.ResponseCode
;
import
com.jz.sms.dto.*
;
import
com.jz.sms.repository.domain.SmsTemplateInfo
;
import
com.jz.sms.repository.domain.SmsTemplateInfo
;
import
com.jz.sms.service.SmsTemplateService
;
import
com.jz.sms.service.SmsTemplateService
;
import
com.jz.sms.util.HttpUtil
;
import
com.jz.sms.util.HttpUtil
;
...
@@ -22,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -22,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
...
@@ -42,7 +40,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
...
@@ -42,7 +40,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
private
SmsTemplateService
templateService
;
private
SmsTemplateService
templateService
;
@Override
@Override
public
CL
Template
Response
createTemplate
(
String
content
,
String
type
)
throws
Exception
{
public
CL
Biz
Response
createTemplate
(
String
content
,
String
type
)
throws
Exception
{
int
i
=
1
/
0
;
int
i
=
1
/
0
;
log
.
info
(
"进入创蓝创建短信接口模板的逻辑:{}"
,
content
);
log
.
info
(
"进入创蓝创建短信接口模板的逻辑:{}"
,
content
);
Map
<
String
,
Object
>
requestMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
requestMap
=
new
HashMap
<>();
...
@@ -56,7 +54,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
...
@@ -56,7 +54,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
}
else
{
}
else
{
// TODO 自定义异常,发送警告
// TODO 自定义异常,发送警告
log
.
error
(
"错误,传入的模板类型未知,类型为:{}"
,
type
);
log
.
error
(
"错误,传入的模板类型未知,类型为:{}"
,
type
);
return
new
CL
Template
Response
(
ResponseCode
.
SYSTEM_ERROR
,
"未知的模板类型:"
+
type
,
0
);
return
new
CL
Biz
Response
(
ResponseCode
.
SYSTEM_ERROR
,
"未知的模板类型:"
+
type
,
0
);
}
}
content
=
content
.
replaceAll
(
"回TD退订"
,
""
);
content
=
content
.
replaceAll
(
"回TD退订"
,
""
);
...
@@ -75,16 +73,15 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
...
@@ -75,16 +73,15 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String
status
=
retJson
.
getString
(
"status"
);
String
status
=
retJson
.
getString
(
"status"
);
if
(
SUCCESS
.
equals
(
status
))
{
if
(
SUCCESS
.
equals
(
status
))
{
JSONObject
data
=
retJson
.
getJSONObject
(
"data"
);
JSONObject
data
=
retJson
.
getJSONObject
(
"data"
);
String
id
=
data
.
getString
(
"id"
);
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
,
data
);
return
new
CLTemplateResponse
(
ResponseCode
.
SUCCESS
,
id
);
}
else
{
}
else
{
String
msg
=
retJson
.
getString
(
"msg"
);
String
msg
=
retJson
.
getString
(
"msg"
);
return
new
CL
Template
Response
(
ResponseCode
.
UPSTREAM_FAIL
.
getCode
(),
msg
);
return
new
CL
Biz
Response
(
ResponseCode
.
UPSTREAM_FAIL
.
getCode
(),
msg
);
}
}
}
}
@Override
@Override
public
CL
SendSMS
Response
sendByFixed
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
{
public
CL
Biz
Response
sendByFixed
(
String
batchId
,
String
content
,
String
sendParams
,
String
type
)
throws
Exception
{
String
account
;
String
account
;
String
password
;
String
password
;
if
(
"notification"
.
equals
(
type
))
{
if
(
"notification"
.
equals
(
type
))
{
...
@@ -109,14 +106,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
...
@@ -109,14 +106,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
log
.
info
(
"【{}】发送固定内容短信,上游返回数据为:{}"
,
batchId
,
requestJson
);
log
.
info
(
"【{}】发送固定内容短信,上游返回数据为:{}"
,
batchId
,
requestJson
);
if
(
StringUtils
.
isBlank
(
responseStr
))
{
if
(
StringUtils
.
isBlank
(
responseStr
))
{
return
new
CL
SendSMSResponse
(
"500"
,
"渠道同步响应为空"
);
return
new
CL
BizResponse
(
ResponseCode
.
UPSTREAM_BLANK
);
}
}
CLSendSMSResponse
response
=
JSON
.
parseObject
(
responseStr
,
CLSendSMSResponse
.
class
);
CLSendSMSResponse
response
=
JSON
.
parseObject
(
responseStr
,
CLSendSMSResponse
.
class
);
return
response
;
String
code
=
response
.
getCode
();
String
errorMsg
=
response
.
getErrorMsg
();
String
msgId
=
response
.
getMsgId
();
if
(!
"0"
.
equals
(
code
))
{
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_FAIL
.
getCode
(),
errorMsg
);
}
else
{
JSONObject
data
=
new
JSONObject
();
data
.
put
(
"msgId"
,
msgId
);
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
,
data
);
}
}
}
@Override
@Override
public
CL
SendSMS
Response
sendByVariable
(
String
batchId
,
String
content
,
String
params
,
String
type
)
throws
Exception
{
public
CL
Biz
Response
sendByVariable
(
String
batchId
,
String
content
,
String
params
,
String
type
)
throws
Exception
{
String
account
;
String
account
;
String
password
;
String
password
;
if
(
"notification"
.
equals
(
type
))
{
if
(
"notification"
.
equals
(
type
))
{
...
@@ -133,43 +140,58 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
...
@@ -133,43 +140,58 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
}
}
content
=
"【九章数据】"
+
content
;
content
=
"【九章数据】"
+
content
;
CLSend
FixedRequest
request
=
new
CLSendFixed
Request
(
account
,
password
,
content
,
params
,
"true"
,
batchId
);
CLSend
VariableRequest
request
=
new
CLSendVariable
Request
(
account
,
password
,
content
,
params
,
"true"
,
batchId
);
String
requestJson
=
JSONObject
.
toJSONString
(
request
);
String
requestJson
=
JSONObject
.
toJSONString
(
request
);
log
.
info
(
"【{}】发送固定内容短信,请求上游数据为:{},\r\n请求地址为:{}"
,
batchId
,
requestJson
,
ChuangLanSMSConfig
.
sendVariable
);
log
.
info
(
"【{}】发送固定内容短信,请求上游数据为:{},\r\n请求地址为:{}"
,
batchId
,
requestJson
,
ChuangLanSMSConfig
.
sendVariable
);
String
responseStr
=
ChuangLanSmsUtil
.
sendSmsByPost
(
ChuangLanSMSConfig
.
sendVariable
,
requestJson
);
String
responseStr
=
ChuangLanSmsUtil
.
sendSmsByPost
(
ChuangLanSMSConfig
.
sendVariable
,
requestJson
);
log
.
info
(
"【{}】发送固定内容短信,上游返回数据为:{}"
,
batchId
,
responseStr
);
log
.
info
(
"【{}】发送固定内容短信,上游返回数据为:{}"
,
batchId
,
responseStr
);
if
(
StringUtils
.
isBlank
(
responseStr
))
{
if
(
StringUtils
.
isBlank
(
responseStr
))
{
return
new
CL
SendSMSResponse
(
"500"
,
"渠道同步响应为空"
);
return
new
CL
BizResponse
(
ResponseCode
.
UPSTREAM_BLANK
);
}
}
CLSendSMSResponse
response
=
JSON
.
parseObject
(
responseStr
,
CLSendSMSResponse
.
class
);
CLSendSMSResponse
response
=
JSON
.
parseObject
(
responseStr
,
CLSendSMSResponse
.
class
);
return
response
;
String
code
=
response
.
getCode
();
String
errorMsg
=
response
.
getErrorMsg
();
String
successNum
=
response
.
getSuccessNum
();
String
failNum
=
response
.
getFailNum
();
String
msgId
=
response
.
getMsgId
();
if
(!
"0"
.
equals
(
code
))
{
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_FAIL
.
getCode
(),
errorMsg
);
}
else
{
JSONObject
data
=
new
JSONObject
();
data
.
put
(
"successNum"
,
successNum
);
data
.
put
(
"failNum"
,
failNum
);
data
.
put
(
"msgId"
,
msgId
);
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
,
data
);
}
}
}
@Override
@Override
public
void
asyncNotify
(
CLNotifyRequest
notifyInfo
)
{
public
CLBizResponse
asyncNotify
(
CLNotifyRequest
notifyInfo
)
{
String
action
=
notifyInfo
.
getAction
();
String
action
=
notifyInfo
.
getAction
();
if
(!
"messageModel"
.
equals
(
action
))
{
if
(!
"messageModel"
.
equals
(
action
))
{
return
;
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_UNKNOWN_MODEL
)
;
}
}
String
id
=
notifyInfo
.
getId
();
String
id
=
notifyInfo
.
getId
();
String
status
=
notifyInfo
.
getAuditStatus
();
String
status
=
notifyInfo
.
getAuditStatus
();
if
(!
"1"
.
equals
(
status
))
{
if
(!
"1"
.
equals
(
status
))
{
String
msg
=
notifyInfo
.
getAuditReason
();
String
msg
=
notifyInfo
.
getAuditReason
();
boolean
update
=
templateService
.
updateForSet
(
"status = abnormal,up_reject_msg = "
+
msg
,
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"up_template_id"
,
id
));
boolean
update
=
templateService
.
updateForSet
(
"status = abnormal,up_reject_msg = "
+
msg
,
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"up_template_id"
,
id
));
// TODO 发送钉钉告警
// TODO 发送钉钉告警
log
.
error
(
"短信模板审核不通过,原因:{}"
,
msg
);
log
.
error
(
"短信模板审核不通过,原因:{}"
,
msg
);
}
}
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
);
}
}
@Override
@Override
public
void
report
(
ReportDto
report
)
{
public
CLBizResponse
report
(
ReportDto
report
)
{
String
uid
=
report
.
getUid
();
String
uid
=
report
.
getUid
();
return
null
;
}
}
...
...
src/main/java/com/jz/sms/config/OkHttpConfig.java
0 → 100644
View file @
9eb6393b
package
com
.
jz
.
sms
.
config
;
import
okhttp3.ConnectionPool
;
import
okhttp3.OkHttpClient
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
@Component
public
class
OkHttpConfig
{
@Bean
public
OkHttpClient
okHttpClient
()
{
return
new
OkHttpClient
().
newBuilder
().
retryOnConnectionFailure
(
false
).
connectionPool
(
pool
())
.
connectTimeout
(
5
,
TimeUnit
.
SECONDS
).
readTimeout
(
5
,
TimeUnit
.
SECONDS
).
writeTimeout
(
5
,
TimeUnit
.
SECONDS
)
.
build
();
}
@Bean
public
ConnectionPool
pool
()
{
return
new
ConnectionPool
(
50
,
5
,
TimeUnit
.
MINUTES
);
}
}
src/main/java/com/jz/sms/config/ResponseCode.java
View file @
9eb6393b
...
@@ -2,9 +2,12 @@ package com.jz.sms.config;
...
@@ -2,9 +2,12 @@ package com.jz.sms.config;
public
enum
ResponseCode
{
public
enum
ResponseCode
{
SUCCESS
(
"200"
,
"处理成功"
),
SUCCESS
(
"200"
,
"处理成功"
),
UPSTREAM_FAIL
(
"UF01"
,
"渠道交易失败"
),
UPSTREAM_FAIL
(
"US01"
,
"渠道交易失败"
),
UPSTREAM_UNKNOWN_MODEL
(
"US01"
,
"未知通知模式"
),
UPSTREAM_BLANK
(
"US00"
,
"渠道同步响应为空"
),
SYSTEM_ERROR
(
"99"
,
"系统异常:"
);
SYSTEM_ERROR
(
"99"
,
"系统异常:"
);
private
String
code
;
private
String
code
;
private
String
msg
;
private
String
msg
;
...
@@ -17,6 +20,7 @@ public enum ResponseCode {
...
@@ -17,6 +20,7 @@ public enum ResponseCode {
return
code
;
return
code
;
}
}
public
String
getMsg
()
{
public
String
getMsg
()
{
return
msg
;
return
msg
;
}
}
...
...
src/main/java/com/jz/sms/dto/DmHubBatchSendResponse.java
deleted
100644 → 0
View file @
561456b1
package
com
.
jz
.
sms
.
dto
;
public
class
DmHubBatchSendResponse
{
private
String
code
;
private
String
msg
;
public
DmHubBatchSendResponse
()
{
}
public
DmHubBatchSendResponse
(
String
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
}
src/main/java/com/jz/sms/dto/DmHubSendResponse.java
View file @
9eb6393b
package
com
.
jz
.
sms
.
dto
;
package
com
.
jz
.
sms
.
dto
;
import
com.jz.sms.config.ResponseCode
;
public
class
DmHubSendResponse
{
public
class
DmHubSendResponse
{
private
String
code
;
private
String
msg
;
public
DmHubSendResponse
()
{
}
public
DmHubSendResponse
(
String
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
}
public
DmHubSendResponse
(
ResponseCode
responseCode
)
{
this
.
code
=
responseCode
.
getCode
();
this
.
msg
=
responseCode
.
getMsg
();
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
}
}
src/main/java/com/jz/sms/service/MessageService.java
View file @
9eb6393b
...
@@ -26,5 +26,5 @@ public interface MessageService {
...
@@ -26,5 +26,5 @@ public interface MessageService {
* @param requestDTO
* @param requestDTO
* @return
* @return
*/
*/
DmHub
Batch
SendResponse
batchSend
(
DmHubBatchSendRequest
requestDTO
);
DmHubSendResponse
batchSend
(
DmHubBatchSendRequest
requestDTO
);
}
}
src/main/java/com/jz/sms/service/impl/MessageServiceImpl.java
View file @
9eb6393b
...
@@ -3,8 +3,7 @@ package com.jz.sms.service.impl;
...
@@ -3,8 +3,7 @@ package com.jz.sms.service.impl;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.jz.sms.chuanglan.dto.CLSendSMSResponse
;
import
com.jz.sms.chuanglan.dto.CLBizResponse
;
import
com.jz.sms.chuanglan.dto.CLTemplateResponse
;
import
com.jz.sms.chuanglan.service.ChuangLanSmsService
;
import
com.jz.sms.chuanglan.service.ChuangLanSmsService
;
import
com.jz.sms.config.ResponseCode
;
import
com.jz.sms.config.ResponseCode
;
import
com.jz.sms.dto.*
;
import
com.jz.sms.dto.*
;
...
@@ -87,7 +86,7 @@ public class MessageServiceImpl implements MessageService {
...
@@ -87,7 +86,7 @@ public class MessageServiceImpl implements MessageService {
//TODO 发送告警
//TODO 发送告警
}
}
String
chaunglanCreate
=
dmHub2ChuangLanCreate
(
chuanglanSend
);
String
chaunglanCreate
=
dmHub2ChuangLanCreate
(
chuanglanSend
);
CL
Template
Response
template
=
chuangLanSmsService
.
createTemplate
(
chaunglanCreate
,
smsType
);
CL
Biz
Response
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
();
...
@@ -223,27 +222,39 @@ public class MessageServiceImpl implements MessageService {
...
@@ -223,27 +222,39 @@ public class MessageServiceImpl implements MessageService {
sysBatchInfo
.
setLastUpdated
(
new
Date
());
sysBatchInfo
.
setLastUpdated
(
new
Date
());
boolean
insert
=
sysBatchService
.
insert
(
sysBatchInfo
);
boolean
insert
=
sysBatchService
.
insert
(
sysBatchInfo
);
CLBizResponse
response
;
// 判断模板是固定短信还是变量短信
// 判断模板是固定短信还是变量短信
if
(
paramsArr
==
null
||
paramsArr
.
isEmpty
())
{
if
(
paramsArr
==
null
||
paramsArr
.
isEmpty
())
{
CLSendSMSResponse
chuanglanResponse
=
chuangLanSmsService
.
sendByFixed
(
dmHubBatchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
response
=
chuangLanSmsService
.
sendByFixed
(
dmHubBatchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
if
(
ResponseCode
.
SUCCESS
.
getCode
().
equals
(
code
))
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
else
{
}
else
{
return
new
DmHubSendResponse
(
code
,
msg
);
// 4、封裝數據
}
CLSendSMSResponse
response
=
chuangLanSmsService
.
sendByVariable
(
dmHubBatchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
}
else
{
response
=
chuangLanSmsService
.
sendByVariable
(
dmHubBatchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
if
(
ResponseCode
.
SUCCESS
.
getCode
().
equals
(
code
))
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
else
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
}
return
null
;
}
}
@Override
@Override
public
DmHub
Batch
SendResponse
batchSend
(
DmHubBatchSendRequest
request
)
{
public
DmHubSendResponse
batchSend
(
DmHubBatchSendRequest
request
)
{
String
batchId
=
request
.
getBatchId
();
String
batchId
=
request
.
getBatchId
();
String
templateId
=
request
.
getTemplateId
();
String
templateId
=
request
.
getTemplateId
();
...
@@ -252,7 +263,7 @@ public class MessageServiceImpl implements MessageService {
...
@@ -252,7 +263,7 @@ public class MessageServiceImpl implements MessageService {
SmsTemplateInfo
templateInfo
=
smsTemplateService
.
selectOne
(
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"dm_template_id"
,
templateId
));
SmsTemplateInfo
templateInfo
=
smsTemplateService
.
selectOne
(
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"dm_template_id"
,
templateId
));
if
(
null
==
templateInfo
)
{
if
(
null
==
templateInfo
)
{
return
new
DmHub
Batch
SendResponse
(
"500"
,
"模板不存在"
);
return
new
DmHubSendResponse
(
"500"
,
"模板不存在"
);
}
}
// 模板参数占位符
// 模板参数占位符
...
@@ -310,24 +321,41 @@ public class MessageServiceImpl implements MessageService {
...
@@ -310,24 +321,41 @@ public class MessageServiceImpl implements MessageService {
info
.
setDateCreated
(
new
Date
());
info
.
setDateCreated
(
new
Date
());
info
.
setLastUpdated
(
new
Date
());
info
.
setLastUpdated
(
new
Date
());
sysBatchService
.
insert
(
info
);
sysBatchService
.
insert
(
info
);
CLBizResponse
response
;
if
(
paramsArr
==
null
||
paramsArr
.
isEmpty
())
{
if
(
paramsArr
==
null
||
paramsArr
.
isEmpty
())
{
try
{
try
{
CLSendSMSResponse
response
=
chuangLanSmsService
.
sendByFixed
(
batchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
response
=
chuangLanSmsService
.
sendByFixed
(
batchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
if
(
ResponseCode
.
SUCCESS
.
getCode
().
equals
(
code
))
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
else
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
return
null
;
// TODO 根据DM hub需要的返回数据封装
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
}
}
else
{
}
else
{
try
{
try
{
CLSendSMSResponse
response
=
chuangLanSmsService
.
sendByVariable
(
batchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
response
=
chuangLanSmsService
.
sendByVariable
(
batchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
templateInfo
.
getType
());
String
code
=
response
.
getCode
();
String
msg
=
response
.
getMsg
();
// TODO 根据DM hub需要的返回数据封装
if
(
ResponseCode
.
SUCCESS
.
getCode
().
equals
(
code
))
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
else
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
return
n
ull
;
return
n
ew
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
)
;
}
}
}
}
return
null
;
}
}
public
String
test
(
Object
value
,
StringBuilder
keyBuffer
)
{
public
String
test
(
Object
value
,
StringBuilder
keyBuffer
)
{
...
...
src/main/java/com/jz/sms/util/OkHttpUtil.java
0 → 100644
View file @
9eb6393b
package
com
.
jz
.
sms
.
util
;
import
com.baomidou.mybatisplus.toolkit.MapUtils
;
import
com.jz.sms.api.BizController
;
import
okhttp3.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.Iterator
;
import
java.util.Map
;
@Component
public
class
OkHttpUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
OkHttpUtil
.
class
);
private
static
OkHttpClient
okHttpClient
;
@Autowired
public
OkHttpUtil
(
OkHttpClient
okHttpClient
)
{
OkHttpUtil
.
okHttpClient
=
okHttpClient
;
}
/**
* get
*
* @param url 请求的url
* @param queries 请求的参数,在浏览器?后面的数据,没有可以传null
* @return
*/
public
static
String
get
(
String
url
,
Map
<
String
,
String
>
queries
)
{
String
responseBody
=
""
;
StringBuffer
sb
=
new
StringBuffer
(
url
);
if
(
MapUtils
.
isNotEmpty
(
queries
))
{
boolean
firstFlag
=
true
;
Iterator
iterator
=
queries
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
<
String
,
String
>)
iterator
.
next
();
if
(
firstFlag
)
{
sb
.
append
(
"?"
+
entry
.
getKey
()
+
"="
+
entry
.
getValue
());
firstFlag
=
false
;
}
else
{
sb
.
append
(
"&"
+
entry
.
getKey
()
+
"="
+
entry
.
getValue
());
}
}
}
Request
request
=
new
Request
.
Builder
().
url
(
sb
.
toString
()).
build
();
Response
response
=
null
;
try
{
response
=
okHttpClient
.
newCall
(
request
).
execute
();
//int status = response.code();
if
(
response
.
isSuccessful
())
{
return
response
.
body
().
string
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"okhttp3 put error >> ex = {}"
,
e
);
}
finally
{
if
(
response
!=
null
)
{
response
.
close
();
}
}
return
responseBody
;
}
/**
* Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON
* 参数三:请求回调
*/
public
static
String
postJsonParams
(
String
url
,
String
jsonParams
)
{
String
responseBody
=
""
;
RequestBody
requestBody
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/json; charset=utf-8"
),
jsonParams
);
Request
request
=
new
Request
.
Builder
().
url
(
url
).
post
(
requestBody
).
build
();
Response
response
=
null
;
try
{
response
=
okHttpClient
.
newCall
(
request
).
execute
();
// int status = response.code();
if
(
response
.
isSuccessful
())
{
return
response
.
body
().
string
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"okhttp3 post error >> ex = {}"
,
e
);
}
finally
{
if
(
response
!=
null
)
{
response
.
close
();
}
}
return
responseBody
;
}
}
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