Commit c4065944 by 111-PC\111

[+]代码规范

1 parent b96b0d6f
...@@ -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;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!