♻️ 枚举类使用==替换equals,提高性能
参考:https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/comparing-java-enum-members-or-equals.md
This commit is contained in:
@@ -29,7 +29,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
|||||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||||
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(accessTokenObject.getString("error"));
|
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(accessTokenObject.getString("error"));
|
||||||
if (!AuthBaiduErrorCode.OK.equals(errorCode)) {
|
if (AuthBaiduErrorCode.OK != errorCode) {
|
||||||
throw new AuthException(errorCode.getDesc());
|
throw new AuthException(errorCode.getDesc());
|
||||||
}
|
}
|
||||||
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
||||||
@@ -42,7 +42,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
|||||||
String userInfo = response.body();
|
String userInfo = response.body();
|
||||||
JSONObject object = JSONObject.parseObject(userInfo);
|
JSONObject object = JSONObject.parseObject(userInfo);
|
||||||
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(object.getString("error"));
|
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(object.getString("error"));
|
||||||
if (!AuthBaiduErrorCode.OK.equals(errorCode)) {
|
if (AuthBaiduErrorCode.OK != errorCode) {
|
||||||
throw new AuthException(errorCode.getDesc());
|
throw new AuthException(errorCode.getDesc());
|
||||||
}
|
}
|
||||||
return AuthUser.builder()
|
return AuthUser.builder()
|
||||||
|
|||||||
@@ -40,13 +40,12 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
|
|||||||
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), timestamp);
|
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), timestamp);
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("tmp_auth_code", code);
|
param.put("tmp_auth_code", code);
|
||||||
HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, timestamp, config.getClientId()))
|
HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, timestamp, config
|
||||||
.body(param.toJSONString())
|
.getClientId())).body(param.toJSONString()).execute();
|
||||||
.execute();
|
|
||||||
String userInfo = response.body();
|
String userInfo = response.body();
|
||||||
JSONObject object = JSON.parseObject(userInfo);
|
JSONObject object = JSON.parseObject(userInfo);
|
||||||
AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getIntValue("errcode"));
|
AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getIntValue("errcode"));
|
||||||
if (!AuthDingTalkErrorCode.EC0.equals(errorCode)) {
|
if (AuthDingTalkErrorCode.EC0 != errorCode) {
|
||||||
throw new AuthException(errorCode.getDesc());
|
throw new AuthException(errorCode.getDesc());
|
||||||
}
|
}
|
||||||
object = object.getJSONObject("user_info");
|
object = object.getJSONObject("user_info");
|
||||||
|
|||||||
Reference in New Issue
Block a user