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
f6ccbb26
Commit
f6ccbb26
authored
Apr 24, 2020
by
qinxunjia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
请求方式优化
parent
9eb6393b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
26 deletions
+65
-26
ChuangLanApi.java
src/main/java/com/jz/sms/api/ChuangLanApi.java
+6
-10
ChuangLanSmsServiceImpl.java
...z/sms/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
+6
-5
ChuangLanSmsUtil.java
...ain/java/com/jz/sms/chuanglan/utils/ChuangLanSmsUtil.java
+45
-6
MessageServiceImpl.java
...main/java/com/jz/sms/service/impl/MessageServiceImpl.java
+8
-5
No files found.
src/main/java/com/jz/sms/api/ChuangLanApi.java
View file @
f6ccbb26
package
com
.
jz
.
sms
.
api
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.sms.chuanglan.dto.CLBizResponse
;
import
com.jz.sms.chuanglan.dto.CLNotifyRequest
;
import
com.jz.sms.chuanglan.dto.ReportDto
;
...
...
@@ -8,10 +9,7 @@ import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -27,7 +25,7 @@ public class ChuangLanApi {
@PostMapping
(
"/notify"
)
public
String
notify
(
@RequestParam
CLNotifyRequest
notifyInfo
)
{
log
.
info
(
"创蓝异步通知接口入参:{}"
,
notifyInfo
);
log
.
info
(
"创蓝异步通知接口入参:{}"
,
JSONObject
.
toJSONString
(
notifyInfo
)
);
chuangLanSmsService
.
asyncNotify
(
notifyInfo
);
...
...
@@ -37,12 +35,10 @@ public class ChuangLanApi {
return
response
;
}
@PostMapping
(
"/report"
)
public
String
report
(
@RequestParam
ReportDto
report
)
{
log
.
info
(
"回送报告接口入参:{}"
,
report
);
@GetMapping
(
"/report"
)
public
String
report
(
ReportDto
report
)
{
log
.
info
(
"回送报告接口入参:{}"
,
JSONObject
.
toJSONString
(
report
));
CLBizResponse
responses
=
chuangLanSmsService
.
report
(
report
);
String
response
=
"success"
;
log
.
info
(
"创蓝异步通知接口出参:{}"
,
response
);
return
response
;
...
...
src/main/java/com/jz/sms/chuanglan/service/impl/ChuangLanSmsServiceImpl.java
View file @
f6ccbb26
...
...
@@ -41,7 +41,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
@Override
public
CLBizResponse
createTemplate
(
String
content
,
String
type
)
throws
Exception
{
int
i
=
1
/
0
;
// TODO 测试,不往上游请求
log
.
info
(
"进入创蓝创建短信接口模板的逻辑:{}"
,
content
);
Map
<
String
,
Object
>
requestMap
=
new
HashMap
<>();
String
appId
;
...
...
@@ -51,13 +51,13 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
appId
=
"49"
;
}
else
if
(
"marketing"
.
equals
(
type
))
{
appId
=
"52"
;
content
=
content
.
replaceAll
(
"回TD退订"
,
""
);
}
else
{
// TODO 自定义异常,发送警告
log
.
error
(
"错误,传入的模板类型未知,类型为:{}"
,
type
);
return
new
CLBizResponse
(
ResponseCode
.
SYSTEM_ERROR
,
"未知的模板类型:"
+
type
,
0
);
}
content
=
content
.
replaceAll
(
"回TD退订"
,
""
);
String
timestamp
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
String
encrypt
=
Md5Util
.
encrypt
(
new
StringBuffer
(
username
).
append
(
password
).
append
(
timestamp
).
toString
());
requestMap
.
put
(
"username"
,
username
);
...
...
@@ -135,7 +135,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
password
=
ChuangLanSMSConfig
.
marketingPassword
;
log
.
info
(
"发送短信的模式为:{营销类}"
);
}
else
{
log
.
info
(
"发送短信的模式为:{未知类型}
"
);
log
.
info
(
"发送短信的模式为:{未知类型}
,type:{}"
,
type
);
throw
new
Exception
(
"123"
);
}
content
=
"【九章数据】"
+
content
;
...
...
@@ -143,9 +143,9 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
CLSendVariableRequest
request
=
new
CLSendVariableRequest
(
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
);
log
.
info
(
"【{}】发送
变量
内容短信,上游返回数据为:{}"
,
batchId
,
responseStr
);
if
(
StringUtils
.
isBlank
(
responseStr
))
{
return
new
CLBizResponse
(
ResponseCode
.
UPSTREAM_BLANK
);
...
...
@@ -188,6 +188,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
@Override
public
CLBizResponse
report
(
ReportDto
report
)
{
// TODO 状态报告要特殊处理,一个个接受,批量发送
String
uid
=
report
.
getUid
();
return
null
;
...
...
src/main/java/com/jz/sms/chuanglan/utils/ChuangLanSmsUtil.java
View file @
f6ccbb26
...
...
@@ -9,19 +9,17 @@ import java.net.URL;
//import java.io.PrintWriter;
/**
*
* @author tianyh
* @Description:HTTP 请求
*/
public
class
ChuangLanSmsUtil
{
/**
*
* @author tianyh
* @Description
* @param path
* @param postContent
* @return String
* @throws
* @author tianyh
* @Description
*/
public
static
String
sendSmsByPost
(
String
path
,
String
postContent
)
{
URL
url
=
null
;
...
...
@@ -35,14 +33,14 @@ public class ChuangLanSmsUtil {
httpURLConnection
.
setDoOutput
(
true
);
httpURLConnection
.
setDoInput
(
true
);
httpURLConnection
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
//
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
// PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
// printWriter.write(postContent);
// printWriter.flush();
httpURLConnection
.
connect
();
OutputStream
os
=
httpURLConnection
.
getOutputStream
();
OutputStream
os
=
httpURLConnection
.
getOutputStream
();
os
.
write
(
postContent
.
getBytes
(
"UTF-8"
));
os
.
flush
();
...
...
@@ -58,7 +56,48 @@ public class ChuangLanSmsUtil {
}
br
.
close
();
return
sb
.
toString
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
String
sendTemplateByPost
(
String
path
,
String
postContent
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
path
);
HttpURLConnection
httpURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpURLConnection
.
setRequestMethod
(
"POST"
);
// 提交模式
httpURLConnection
.
setConnectTimeout
(
10000
);
//连接超时 单位毫秒
httpURLConnection
.
setReadTimeout
(
10000
);
//读取超时 单位毫秒
// 发送POST请求必须设置如下两行
httpURLConnection
.
setDoOutput
(
true
);
httpURLConnection
.
setDoInput
(
true
);
httpURLConnection
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
httpURLConnection
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
// PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
// printWriter.write(postContent);
// printWriter.flush();
httpURLConnection
.
connect
();
OutputStream
os
=
httpURLConnection
.
getOutputStream
();
os
.
write
(
postContent
.
getBytes
(
"UTF-8"
));
os
.
flush
();
StringBuilder
sb
=
new
StringBuilder
();
int
httpRspCode
=
httpURLConnection
.
getResponseCode
();
if
(
httpRspCode
==
HttpURLConnection
.
HTTP_OK
)
{
// 开始获取数据
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
httpURLConnection
.
getInputStream
(),
"utf-8"
));
String
line
=
null
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
sb
.
append
(
line
);
}
br
.
close
();
return
sb
.
toString
();
}
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/jz/sms/service/impl/MessageServiceImpl.java
View file @
f6ccbb26
...
...
@@ -204,9 +204,7 @@ public class MessageServiceImpl implements MessageService {
}
}
}
sendParams
.
append
(
";"
);
}
else
{
sendParams
.
append
(
","
);
}
String
type
=
templateInfo
.
getType
();
...
...
@@ -272,7 +270,9 @@ public class MessageServiceImpl implements MessageService {
// 封装参数
StringBuilder
sendParams
=
new
StringBuilder
();
int
i
=
0
;
for
(
JSONObject
json
:
data
)
{
i
++;
Set
<
String
>
keys
=
json
.
keySet
();
String
mobile
=
json
.
getString
(
"_audienceId"
);
json
.
remove
(
"name"
);
...
...
@@ -295,12 +295,15 @@ public class MessageServiceImpl implements MessageService {
}
}
}
sendParams
.
append
(
";"
);
if
(
i
!=
data
.
size
())
{
sendParams
.
append
(
";"
);
}
}
else
{
sendParams
.
append
(
","
);
if
(
i
!=
data
.
size
())
{
sendParams
.
append
(
","
);
}
}
}
System
.
out
.
println
(
sendParams
.
toString
());
DmBatchInfo
dmInfo
=
new
DmBatchInfo
();
dmInfo
.
setDmBatchId
(
batchId
);
...
...
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