SendRequestService.java
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cn.com.glsx.modules.service;
import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.utils.HeaderParamUtils;
import cn.com.glsx.modules.utils.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Map;
/**
* @author zhouhaibao
* @date 2021/3/5 14:37
*/
@Service
@Slf4j
public class SendRequestService {
@Value("${tuya.client_id}")
private String client_id;
@Value("${tuya.secret}")
private String secret;
public ResponseBody sendRequestPost(String requesturl,String accessToken, String requestBody) {
ResponseBody responseBody = null;
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken);
try {
JSONObject jsonObject = HttpUtil.sendPost(requesturl, JSONObject.toJSONString(requestBody), headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
} catch (IOException e) {
e.printStackTrace();
log.info("调用失败");
}
return responseBody;
}
public ResponseBody sendRequestGet(String requesturl, String accessToken) {
ResponseBody responseBody = null;
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken);
try {
JSONObject jsonObject = HttpUtil.sendGet(requesturl, null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
} catch (IOException e) {
e.printStackTrace();
log.info("请求用户信息接口异常,异常信息{}", e);
}
return responseBody;
}
public ResponseBody sendRequestGet(String requesturl) {
ResponseBody responseBody = null;
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret);
try {
JSONObject jsonObject = HttpUtil.sendGet(requesturl, null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
} catch (IOException e) {
e.printStackTrace();
log.info("请求用户信息接口异常,异常信息{}", e);
}
return responseBody;
}
}