Commit 1786ba45 by 111-PC\111

[+]代码整改

1 parent 8ff8f943
......@@ -7,6 +7,7 @@ import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.model.param.UserBo;
import cn.com.glsx.modules.model.param.UserInfo;
import cn.com.glsx.modules.utils.AccessTokenService;
import cn.com.glsx.modules.utils.HeaderParamUtils;
import cn.com.glsx.modules.utils.HttpUtil;
import cn.com.glsx.modules.utils.TuyaUtils;
import com.alibaba.fastjson.JSON;
......@@ -73,14 +74,7 @@ public class UserService {
private ResponseBody sendRequestRegisterUser(String accessToken, UserBo userBo) {
ResponseBody responseBody = null;
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getBussinessSign(timeMillis, client_id, secret, accessToken);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
headerParams.put("access_token", accessToken);
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken);
try {
JSONObject jsonObject = HttpUtil.sendPost(registerUserUrl, JSONObject.toJSONString(userBo), headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......@@ -115,14 +109,7 @@ public class UserService {
private ResponseBody sendRequestGetUserInfo(String id, String accessToken) {
ResponseBody responseBody = null;
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getBussinessSign(timeMillis, client_id, secret, accessToken);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
headerParams.put("access_token", accessToken);
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken);
try {
JSONObject jsonObject = HttpUtil.sendGet(getUserInfoUrl.replace("{uid}", id), null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......
......@@ -91,13 +91,7 @@ public class AccessTokenService {
*/
private ResponseBody sendRequestFlashToken(String flashtoken) {
ResponseBody responseBody = null;
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getLoginSign(timeMillis, client_id, secret);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret);
try {
JSONObject jsonObject = HttpUtil.sendGet(tokenFlashUrl + flashtoken, null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......@@ -115,13 +109,7 @@ public class AccessTokenService {
*/
private ResponseBody sendRequestGetToken() {
ResponseBody responseBody = null;
long timeMillis = System.currentTimeMillis();
String loginSign = TuyaUtils.getLoginSign(timeMillis, client_id, secret);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", loginSign);
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret);
try {
JSONObject jsonObject = HttpUtil.sendGet(getTokenUrl, null, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
......@@ -131,4 +119,6 @@ public class AccessTokenService {
}
return responseBody;
}
}
package cn.com.glsx.modules.utils;
import java.util.HashMap;
import java.util.Map;
/**
* @author zhouhaibao
* @date 2021/3/5 9:24
*/
public class HeaderParamUtils {
public static Map<String,String> buildHeaderParams(String client_id,String secret){
long timeMillis = System.currentTimeMillis();
String loginSign = TuyaUtils.getLoginSign(timeMillis, client_id, secret);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", loginSign);
return headerParams;
}
public static Map<String,String> buildHeaderParams(String client_id,String secret,String accessToken){
long timeMillis = System.currentTimeMillis();
String sign = TuyaUtils.getBussinessSign(timeMillis, client_id, secret, accessToken);
Map<String, String> headerParams = new HashMap<>();
headerParams.put("client_id", client_id);
headerParams.put("t", timeMillis + "");
headerParams.put("sign_method", "HMAC-SHA256");
headerParams.put("sign", sign);
headerParams.put("access_token", accessToken);
return headerParams;
}
}
......@@ -58,6 +58,4 @@ public class TuyaUtils {
}
return hash;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!