Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
smartDevices-platform-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c4065944
authored
May 07, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码规范
1 parent
b96b0d6f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
29 deletions
src/main/java/cn/com/glsx/modules/service/SendRequestService.java
src/main/java/cn/com/glsx/modules/service/SendRequestService.java
View file @
c406594
...
@@ -6,7 +6,6 @@ import cn.com.glsx.modules.utils.HttpUtil;
...
@@ -6,7 +6,6 @@ import cn.com.glsx.modules.utils.HttpUtil;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -42,14 +41,8 @@ public class SendRequestService {
...
@@ -42,14 +41,8 @@ public class SendRequestService {
*/
*/
public
ResponseBody
sendRequestPost
(
String
requesturl
,
String
requestBody
)
{
public
ResponseBody
sendRequestPost
(
String
requesturl
,
String
requestBody
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
)){
log
.
info
(
"获取token失败"
);
return
responseBody
;
}
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendPost
(
requesturl
,
requestBody
,
headerParams
);
JSONObject
jsonObject
=
HttpUtil
.
sendPost
(
requesturl
,
requestBody
,
buildRequestParam
()
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -66,14 +59,8 @@ public class SendRequestService {
...
@@ -66,14 +59,8 @@ public class SendRequestService {
*/
*/
public
ResponseBody
sendRequestGet
(
String
requesturl
)
{
public
ResponseBody
sendRequestGet
(
String
requesturl
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
)){
log
.
info
(
"获取token失败"
);
return
responseBody
;
}
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
requesturl
,
null
,
headerParams
);
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
requesturl
,
null
,
buildRequestParam
()
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
log
.
info
(
"请求涂鸦数据{}"
,
responseBody
);
log
.
info
(
"请求涂鸦数据{}"
,
responseBody
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -91,14 +78,8 @@ public class SendRequestService {
...
@@ -91,14 +78,8 @@ public class SendRequestService {
*/
*/
public
ResponseBody
sendRequestPut
(
String
requesturl
,
String
requestBody
)
{
public
ResponseBody
sendRequestPut
(
String
requesturl
,
String
requestBody
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
)){
log
.
info
(
"获取token失败"
);
return
responseBody
;
}
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendPut
(
requesturl
,
requestBody
,
headerParams
);
JSONObject
jsonObject
=
HttpUtil
.
sendPut
(
requesturl
,
requestBody
,
buildRequestParam
()
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
log
.
info
(
"请求涂鸦数据{}"
,
responseBody
);
log
.
info
(
"请求涂鸦数据{}"
,
responseBody
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -110,14 +91,8 @@ public class SendRequestService {
...
@@ -110,14 +91,8 @@ public class SendRequestService {
public
ResponseBody
sendRequestDelete
(
String
requesturl
)
{
public
ResponseBody
sendRequestDelete
(
String
requesturl
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
)){
log
.
info
(
"获取token失败"
);
return
responseBody
;
}
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendDelete
(
requesturl
,
headerParams
);
JSONObject
jsonObject
=
HttpUtil
.
sendDelete
(
requesturl
,
buildRequestParam
()
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -126,4 +101,10 @@ public class SendRequestService {
...
@@ -126,4 +101,10 @@ public class SendRequestService {
return
responseBody
;
return
responseBody
;
}
}
private
Map
<
String
,
String
>
buildRequestParam
(){
String
accessToken
=
accessTokenService
.
getAccessToken
();
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
return
headerParams
;
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment