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
Hide 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 @@
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</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>
<build>
<finalName>
dmhub-plugin
</finalName>
...
...
src/main/java/com/jz/sms/api/BizController.java
View file @
9eb6393b
...
...
@@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/test"
)
public
class
BizController
{
...
...
@@ -41,9 +39,9 @@ public class BizController {
* @return
*/
@PostMapping
(
"/sms/batch"
)
public
DmHub
Batch
SendResponse
batch
(
@RequestBody
DmHubBatchSendRequest
request
)
{
public
DmHubSendResponse
batch
(
@RequestBody
DmHubBatchSendRequest
request
)
{
log
.
info
(
"**********批量发送入参*******:{}"
,
JSONObject
.
toJSONString
(
request
));
DmHub
Batch
SendResponse
response
=
messageService
.
batchSend
(
request
);
DmHubSendResponse
response
=
messageService
.
batchSend
(
request
);
// log.info("**********批量发送入参*******:{}", response);
return
response
;
}
...
...
src/main/java/com/jz/sms/api/ChuangLanApi.java
View file @
9eb6393b
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.ReportDto
;
import
com.jz.sms.chuanglan.service.ChuangLanSmsService
;
...
...
@@ -40,8 +41,7 @@ public class ChuangLanApi {
public
String
report
(
@RequestParam
ReportDto
report
)
{
log
.
info
(
"回送报告接口入参:{}"
,
report
);
chuangLanSmsService
.
report
(
report
);
CLBizResponse
responses
=
chuangLanSmsService
.
report
(
report
);
String
response
=
"success"
;
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
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.sms.config.ResponseCode
;
import
java.io.Serializable
;
public
class
CL
Template
Response
implements
Serializable
{
public
class
CL
Biz
Response
implements
Serializable
{
private
String
code
;
...
...
@@ -13,28 +14,40 @@ public class CLTemplateResponse implements Serializable {
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
.
msg
=
responseCode
.
getMsg
();
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
.
msg
=
responseCode
.
getMsg
()+
msg
;
}
public
CL
Template
Response
(
String
code
,
String
msg
)
{
public
CL
Biz
Response
(
String
code
,
String
msg
)
{
this
.
code
=
code
;
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
.
msg
=
msg
;
this
.
id
=
id
;
...
...
@@ -61,6 +74,15 @@ public class CLTemplateResponse implements Serializable {
}
public
void
setId
(
String
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 {
*/
private
String
code
;
private
String
failNum
;
private
String
successNum
;
public
CLSendSMSResponse
(){}
...
...
@@ -58,6 +62,22 @@ public class CLSendSMSResponse {
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
public
String
toString
()
{
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 {
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) {
// super();
// 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;
import
com.jz.sms.chuanglan.dto.CLNotifyRequest
;
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.dto.*
;
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;
import
com.jz.sms.chuanglan.utils.ChuangLanSmsUtil
;
import
com.jz.sms.chuanglan.config.ChuangLanSMSConfig
;
import
com.jz.sms.config.ResponseCode
;
import
com.jz.sms.dto.*
;
import
com.jz.sms.repository.domain.SmsTemplateInfo
;
import
com.jz.sms.service.SmsTemplateService
;
import
com.jz.sms.util.HttpUtil
;
...
...
@@ -22,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -42,7 +40,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
private
SmsTemplateService
templateService
;
@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
;
log
.
info
(
"进入创蓝创建短信接口模板的逻辑:{}"
,
content
);
Map
<
String
,
Object
>
requestMap
=
new
HashMap
<>();
...
...
@@ -56,7 +54,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
}
else
{
// TODO 自定义异常,发送警告
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退订"
,
""
);
...
...
@@ -75,16 +73,15 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String
status
=
retJson
.
getString
(
"status"
);
if
(
SUCCESS
.
equals
(
status
))
{
JSONObject
data
=
retJson
.
getJSONObject
(
"data"
);
String
id
=
data
.
getString
(
"id"
);
return
new
CLTemplateResponse
(
ResponseCode
.
SUCCESS
,
id
);
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
,
data
);
}
else
{
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
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
password
;
if
(
"notification"
.
equals
(
type
))
{
...
...
@@ -109,14 +106,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
log
.
info
(
"【{}】发送固定内容短信,上游返回数据为:{}"
,
batchId
,
requestJson
);
if
(
StringUtils
.
isBlank
(
responseStr
))
{
return
new
CL
SendSMSResponse
(
"500"
,
"渠道同步响应为空"
);
return
new
CL
BizResponse
(
ResponseCode
.
UPSTREAM_BLANK
);
}
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
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
password
;
if
(
"notification"
.
equals
(
type
))
{
...
...
@@ -133,43 +140,58 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
}
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
);
log
.
info
(
"【{}】发送固定内容短信,请求上游数据为:{},\r\n请求地址为:{}"
,
batchId
,
requestJson
,
ChuangLanSMSConfig
.
sendVariable
);
log
.
info
(
"【{}】发送固定内容短信,请求上游数据为:{},\r\n请求地址为:{}"
,
batchId
,
requestJson
,
ChuangLanSMSConfig
.
sendVariable
);
String
responseStr
=
ChuangLanSmsUtil
.
sendSmsByPost
(
ChuangLanSMSConfig
.
sendVariable
,
requestJson
);
log
.
info
(
"【{}】发送固定内容短信,上游返回数据为:{}"
,
batchId
,
responseStr
);
if
(
StringUtils
.
isBlank
(
responseStr
))
{
return
new
CL
SendSMSResponse
(
"500"
,
"渠道同步响应为空"
);
return
new
CL
BizResponse
(
ResponseCode
.
UPSTREAM_BLANK
);
}
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
public
void
asyncNotify
(
CLNotifyRequest
notifyInfo
)
{
public
CLBizResponse
asyncNotify
(
CLNotifyRequest
notifyInfo
)
{
String
action
=
notifyInfo
.
getAction
();
if
(!
"messageModel"
.
equals
(
action
))
{
return
;
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_UNKNOWN_MODEL
)
;
}
String
id
=
notifyInfo
.
getId
();
String
status
=
notifyInfo
.
getAuditStatus
();
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 发送钉钉告警
log
.
error
(
"短信模板审核不通过,原因:{}"
,
msg
);
}
return
new
CLBizResponse
(
ResponseCode
.
SUCCESS
);
}
@Override
public
void
report
(
ReportDto
report
)
{
public
CLBizResponse
report
(
ReportDto
report
)
{
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;
public
enum
ResponseCode
{
SUCCESS
(
"200"
,
"处理成功"
),
UPSTREAM_FAIL
(
"UF01"
,
"渠道交易失败"
),
UPSTREAM_FAIL
(
"US01"
,
"渠道交易失败"
),
UPSTREAM_UNKNOWN_MODEL
(
"US01"
,
"未知通知模式"
),
UPSTREAM_BLANK
(
"US00"
,
"渠道同步响应为空"
),
SYSTEM_ERROR
(
"99"
,
"系统异常:"
);
private
String
code
;
private
String
msg
;
...
...
@@ -17,6 +20,7 @@ public enum ResponseCode {
return
code
;
}
public
String
getMsg
()
{
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
;
import
com.jz.sms.config.ResponseCode
;
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 {
* @param requestDTO
* @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;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.jz.sms.chuanglan.dto.CLSendSMSResponse
;
import
com.jz.sms.chuanglan.dto.CLTemplateResponse
;
import
com.jz.sms.chuanglan.dto.CLBizResponse
;
import
com.jz.sms.chuanglan.service.ChuangLanSmsService
;
import
com.jz.sms.config.ResponseCode
;
import
com.jz.sms.dto.*
;
...
...
@@ -87,7 +86,7 @@ public class MessageServiceImpl implements MessageService {
//TODO 发送告警
}
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
()))
{
String
id
=
template
.
getId
();
SmsTemplateInfo
updateInfo
=
new
SmsTemplateInfo
();
...
...
@@ -223,27 +222,39 @@ public class MessageServiceImpl implements MessageService {
sysBatchInfo
.
setLastUpdated
(
new
Date
());
boolean
insert
=
sysBatchService
.
insert
(
sysBatchInfo
);
CLBizResponse
response
;
// 判断模板是固定短信还是变量短信
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
{
return
new
DmHubSendResponse
(
code
,
msg
);
}
}
else
{
// 4、封裝數據
CLSendSMSResponse
response
=
chuangLanSmsService
.
sendByVariable
(
dmHubBatchId
,
templateInfo
.
getUpContent
(),
sendParams
.
toString
(),
type
);
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
)
{
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
return
null
;
}
@Override
public
DmHub
Batch
SendResponse
batchSend
(
DmHubBatchSendRequest
request
)
{
public
DmHubSendResponse
batchSend
(
DmHubBatchSendRequest
request
)
{
String
batchId
=
request
.
getBatchId
();
String
templateId
=
request
.
getTemplateId
();
...
...
@@ -252,7 +263,7 @@ public class MessageServiceImpl implements MessageService {
SmsTemplateInfo
templateInfo
=
smsTemplateService
.
selectOne
(
new
EntityWrapper
<
SmsTemplateInfo
>().
eq
(
"dm_template_id"
,
templateId
));
if
(
null
==
templateInfo
)
{
return
new
DmHub
Batch
SendResponse
(
"500"
,
"模板不存在"
);
return
new
DmHubSendResponse
(
"500"
,
"模板不存在"
);
}
// 模板参数占位符
...
...
@@ -310,24 +321,41 @@ public class MessageServiceImpl implements MessageService {
info
.
setDateCreated
(
new
Date
());
info
.
setLastUpdated
(
new
Date
());
sysBatchService
.
insert
(
info
);
CLBizResponse
response
;
if
(
paramsArr
==
null
||
paramsArr
.
isEmpty
())
{
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
)
{
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
return
null
;
// TODO 根据DM hub需要的返回数据封装
return
new
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
);
}
}
else
{
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
)
{
log
.
error
(
"调用创蓝逻辑错误:{}"
,
e
);
return
n
ull
;
return
n
ew
DmHubSendResponse
(
ResponseCode
.
SYSTEM_ERROR
)
;
}
}
return
null
;
}
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