mirror of
https://gitee.com/yadong.zhang/JustAuth.git
synced 2025-12-06 16:58:24 +08:00
⬆️ 升级 simple-http 到 1.0.5
This commit is contained in:
parent
2de0ad5013
commit
644ef02264
@ -1,3 +1,7 @@
|
||||
## 1.16.4
|
||||
|
||||
### 2021/9/**
|
||||
|
||||
## 1.16.3
|
||||
|
||||
### 2021/8/15
|
||||
|
||||
@ -1 +1 @@
|
||||
1.16.3
|
||||
1.16.4
|
||||
|
||||
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.16.3</version>
|
||||
<version>1.16.4</version>
|
||||
|
||||
<name>JustAuth</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
@ -57,7 +57,7 @@
|
||||
<maven-surefire-version>2.20</maven-surefire-version>
|
||||
<maven-gpg-version>1.6</maven-gpg-version>
|
||||
<maven.test.skip>false</maven.test.skip>
|
||||
<simple-http.version>1.0.3</simple-http.version>
|
||||
<simple-http.version>1.0.5</simple-http.version>
|
||||
<lombok-version>1.18.10</lombok-version>
|
||||
<junit-version>4.13.1</junit-version>
|
||||
<fastjson-version>1.2.76</fastjson-version>
|
||||
|
||||
@ -43,7 +43,7 @@ public abstract class AbstractAuthDingtalkRequest extends AuthDefaultRequest {
|
||||
String code = authToken.getAccessCode();
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("tmp_auth_code", code);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString()).getBody();
|
||||
JSONObject object = JSON.parseObject(response);
|
||||
if (object.getIntValue("errcode") != 0) {
|
||||
throw new AuthException(object.getString("errmsg"));
|
||||
|
||||
@ -53,7 +53,7 @@ public abstract class AbstractAuthMicrosoftRequest extends AuthDefaultRequest {
|
||||
|
||||
Map<String, String> form = MapUtil.parseStringToMap(accessTokenUrl, false);
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(accessTokenObject);
|
||||
@ -87,7 +87,7 @@ public abstract class AbstractAuthMicrosoftRequest extends AuthDefaultRequest {
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Authorization", jwt);
|
||||
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(object);
|
||||
return AuthUser.builder()
|
||||
|
||||
@ -130,7 +130,7 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
||||
.queryParam("access_token", accessToken)
|
||||
.queryParam("userid", userId)
|
||||
.build();
|
||||
return new HttpUtils(config.getHttpConfig()).get(userDetailUrl);
|
||||
return new HttpUtils(config.getHttpConfig()).get(userDetailUrl).getBody();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ public class AuthAmazonRequest extends AuthDefaultRequest {
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Host", "api.amazon.com");
|
||||
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=UTF-8");
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(url, param, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(url, param, httpHeader, false).getBody();
|
||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(jsonObject);
|
||||
return AuthToken.builder()
|
||||
@ -147,7 +147,7 @@ public class AuthAmazonRequest extends AuthDefaultRequest {
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Host", "api.amazon.com");
|
||||
httpHeader.add("Authorization", "bearer " + accessToken);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(this.source.userInfo(), new HashMap<>(0), httpHeader, false);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(this.source.userInfo(), new HashMap<>(0), httpHeader, false).getBody();
|
||||
JSONObject jsonObject = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(jsonObject);
|
||||
|
||||
@ -164,7 +164,7 @@ public class AuthAmazonRequest extends AuthDefaultRequest {
|
||||
}
|
||||
|
||||
private void checkToken(String accessToken) {
|
||||
String tokenInfo = new HttpUtils(config.getHttpConfig()).get("https://api.amazon.com/auth/o2/tokeninfo?access_token=" + UrlUtil.urlEncode(accessToken));
|
||||
String tokenInfo = new HttpUtils(config.getHttpConfig()).get("https://api.amazon.com/auth/o2/tokeninfo?access_token=" + UrlUtil.urlEncode(accessToken)).getBody();
|
||||
JSONObject jsonObject = JSONObject.parseObject(tokenInfo);
|
||||
if (!config.getClientId().equals(jsonObject.getString("aud"))) {
|
||||
throw new AuthException(AuthResponseStatus.ILLEGAL_TOKEN);
|
||||
|
||||
@ -88,7 +88,7 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
|
||||
.queryParam("client_id", this.config.getClientId())
|
||||
.queryParam("client_secret", this.config.getClientSecret())
|
||||
.build();
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(refreshUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(refreshUrl).getBody();
|
||||
return AuthResponse.builder()
|
||||
.code(AuthResponseStatus.SUCCESS.getCode())
|
||||
.data(this.getAuthToken(response))
|
||||
|
||||
@ -211,7 +211,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
|
||||
* @return Response
|
||||
*/
|
||||
protected String doPostAuthorizationCode(String code) {
|
||||
return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code));
|
||||
return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code)).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +221,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
|
||||
* @return Response
|
||||
*/
|
||||
protected String doGetAuthorizationCode(String code) {
|
||||
return new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(code));
|
||||
return new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(code)).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +232,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
|
||||
*/
|
||||
@Deprecated
|
||||
protected String doPostUserInfo(AuthToken authToken) {
|
||||
return new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken));
|
||||
return new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken)).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,7 +242,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
|
||||
* @return Response
|
||||
*/
|
||||
protected String doGetUserInfo(AuthToken authToken) {
|
||||
return new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken));
|
||||
return new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken)).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,7 +253,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
|
||||
*/
|
||||
@Deprecated
|
||||
protected String doPostRevoke(AuthToken authToken) {
|
||||
return new HttpUtils(config.getHttpConfig()).post(revokeUrl(authToken));
|
||||
return new HttpUtils(config.getHttpConfig()).post(revokeUrl(authToken)).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -263,7 +263,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
|
||||
* @return Response
|
||||
*/
|
||||
protected String doGetRevoke(AuthToken authToken) {
|
||||
return new HttpUtils(config.getHttpConfig()).get(revokeUrl(authToken));
|
||||
return new HttpUtils(config.getHttpConfig()).get(revokeUrl(authToken)).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -87,7 +87,7 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
this.checkResponse(object);
|
||||
JSONObject dataObj = object.getJSONObject("data");
|
||||
|
||||
@ -52,7 +52,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
|
||||
form.put("grant_type", "authorization_code");
|
||||
|
||||
HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_FORM, this.getRequestId(), true);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
@ -91,7 +91,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
|
||||
paramsMap.put("signature", signature);
|
||||
|
||||
HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_JSON, requestId, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), JSONObject.toJSONString(paramsMap), httpHeader);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), JSONObject.toJSONString(paramsMap), httpHeader).getBody();
|
||||
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
@ -123,7 +123,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
|
||||
form.put("grant_type", "refresh_token");
|
||||
|
||||
HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_FORM, this.getRequestId(), true);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, httpHeader, false).getBody();
|
||||
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ public class AuthGithubRequest extends AuthDefaultRequest {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
HttpHeader header = new HttpHeader();
|
||||
header.add("Authorization", "token " + authToken.getAccessToken());
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo()).build(), null, header, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo()).build(), null, header, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object.containsKey("error"), object.getString("error_description"));
|
||||
|
||||
@ -50,7 +50,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Authorization", "Bearer " + authToken.getAccessToken());
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, httpHeader);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, httpHeader).getBody();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(object);
|
||||
return AuthUser.builder()
|
||||
|
||||
@ -54,7 +54,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
|
||||
form.put("client_secret", config.getClientSecret());
|
||||
form.put("redirect_uri", config.getRedirectUri());
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false).getBody();
|
||||
return getAuthToken(response);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
|
||||
form.put("nsp_fmt", "JS");
|
||||
form.put("nsp_svc", "OpenUP.User.getInfo");
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
@ -106,7 +106,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
|
||||
form.put("refresh_token", authToken.getRefreshToken());
|
||||
form.put("grant_type", "refresh_token");
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false).getBody();
|
||||
return AuthResponse.builder().code(SUCCESS.getCode()).data(getAuthToken(response)).build();
|
||||
}
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
|
||||
params.put("app_secret", config.getClientSecret());
|
||||
params.put("grant_type", "authorization_code");
|
||||
params.put("code", authCallback.getCode());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
@ -70,7 +70,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
|
||||
.queryParam("timestamp", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
||||
.queryParam("v", "2.0");
|
||||
urlBuilder.queryParam("sign", GlobalAuthUtils.generateJdSignature(config.getClientSecret(), urlBuilder.getReadOnlyParams()));
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(urlBuilder.build(true));
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(urlBuilder.build(true)).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
@ -109,7 +109,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
|
||||
params.put("app_secret", config.getClientSecret());
|
||||
params.put("grant_type", "refresh_token");
|
||||
params.put("refresh_token", oldToken.getRefreshToken());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), params, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), params, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
|
||||
@ -76,7 +76,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo())
|
||||
.queryParam("access_token", authToken.getAccessToken())
|
||||
.queryParam("open_id", openId)
|
||||
.build());
|
||||
.build()).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
if (!"0".equals(object.getString("c"))) {
|
||||
throw new AuthException(object.getString("m"));
|
||||
@ -103,14 +103,14 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
|
||||
private String getOpenId(AuthToken authToken) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl("https://oauth.kujiale.com/oauth2/auth/user")
|
||||
.queryParam("access_token", authToken.getAccessToken())
|
||||
.build());
|
||||
.build()).getBody();
|
||||
JSONObject accessTokenObject = checkResponse(response);
|
||||
return accessTokenObject.getString("d");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(refreshTokenUrl(authToken.getRefreshToken()));
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(refreshTokenUrl(authToken.getRefreshToken())).getBody();
|
||||
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getAuthToken(response)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
|
||||
params.put("redirect_uri", config.getRedirectUri());
|
||||
params.put("client_id", config.getClientId());
|
||||
params.put("client_secret", config.getClientSecret());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
@ -59,7 +59,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Bearer ".concat(authToken.getAccessToken())), false);
|
||||
.add("Authorization", "Bearer ".concat(authToken.getAccessToken())), false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
return AuthUser.builder()
|
||||
.rawUserInfo(object)
|
||||
@ -80,7 +80,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
|
||||
params.put("access_token", authToken.getAccessToken());
|
||||
params.put("client_id", config.getClientId());
|
||||
params.put("client_secret", config.getClientSecret());
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).post(source.revoke(), params, false);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).post(source.revoke(), params, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
// 返回1表示取消授权成功,否则失败
|
||||
AuthResponseStatus status = object.getBooleanValue("revoked") ? AuthResponseStatus.SUCCESS : AuthResponseStatus.FAILURE;
|
||||
@ -94,7 +94,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
|
||||
params.put("refresh_token", oldToken.getRefreshToken());
|
||||
params.put("client_id", config.getClientId());
|
||||
params.put("client_secret", config.getClientSecret());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
return AuthResponse.builder()
|
||||
.code(AuthResponseStatus.SUCCESS.getCode())
|
||||
|
||||
@ -48,7 +48,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
|
||||
httpHeader.add("Connection", "Keep-Alive");
|
||||
httpHeader.add("Authorization", "Bearer " + accessToken);
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false).getBody();
|
||||
JSONObject userInfoObject = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(userInfoObject);
|
||||
@ -138,7 +138,9 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
|
||||
httpHeader.add("Connection", "Keep-Alive");
|
||||
httpHeader.add("Authorization", "Bearer " + accessToken);
|
||||
|
||||
String emailResponse = new HttpUtils(config.getHttpConfig()).get("https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))", null, httpHeader, false);
|
||||
String emailResponse = new HttpUtils(config.getHttpConfig())
|
||||
.get("https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))", null, httpHeader, false)
|
||||
.getBody();
|
||||
JSONObject emailObj = JSONObject.parseObject(emailResponse);
|
||||
|
||||
this.checkResponse(emailObj);
|
||||
@ -178,7 +180,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
|
||||
httpHeader.add("Host", "www.linkedin.com");
|
||||
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, null, httpHeader);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, null, httpHeader).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(accessTokenObject);
|
||||
|
||||
@ -41,7 +41,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
|
||||
form.put("code", authCallback.getCode());
|
||||
form.put("grant_type", "authorization_code");
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
@ -60,7 +60,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
|
||||
form.put("secret", config.getClientSecret());
|
||||
form.put("access_token", authToken.getAccessToken());
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
@ -85,7 +85,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
|
||||
form.put("refresh_token", oldToken.getRefreshToken());
|
||||
form.put("grant_type", "refresh_token");
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
|
||||
@ -43,7 +43,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
|
||||
}
|
||||
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();
|
||||
String jsonStr = response.replace(PREFIX, Constants.EMPTY);
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(jsonStr);
|
||||
|
||||
@ -91,7 +91,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
|
||||
String emailPhoneUrl = MessageFormat.format("{0}?clientId={1}&token={2}", "https://open.account.xiaomi.com/user/phoneAndEmail", config
|
||||
.getClientId(), authToken.getAccessToken());
|
||||
|
||||
String emailResponse = new HttpUtils(config.getHttpConfig()).get(emailPhoneUrl);
|
||||
String emailResponse = new HttpUtils(config.getHttpConfig()).get(emailPhoneUrl).getBody();
|
||||
JSONObject userEmailPhone = JSONObject.parseObject(emailResponse);
|
||||
if (!"error".equalsIgnoreCase(userEmailPhone.getString("result"))) {
|
||||
JSONObject emailPhone = userEmailPhone.getJSONObject("data");
|
||||
|
||||
@ -50,7 +50,7 @@ public class AuthOktaRequest extends AuthDefaultRequest {
|
||||
.add("accept", "application/json")
|
||||
.add("content-type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Basic " + Base64Utils.encode(config.getClientId().concat(":").concat(config.getClientSecret())));
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl, null, header, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl, null, header, false).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(accessTokenObject);
|
||||
return AuthToken.builder()
|
||||
@ -82,7 +82,7 @@ public class AuthOktaRequest extends AuthDefaultRequest {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Authorization", "Bearer " + authToken.getAccessToken());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, header, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, header, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
this.checkResponse(object);
|
||||
JSONObject address = object.getJSONObject("address");
|
||||
|
||||
@ -50,7 +50,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String userinfoUrl = userInfoUrl(authToken);
|
||||
// TODO: 是否需要 .setFollowRedirects(true)
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(userinfoUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(userinfoUrl).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
this.checkResponse(object);
|
||||
JSONObject userObj = object.getJSONObject("data");
|
||||
|
||||
@ -41,7 +41,7 @@ public class AuthProginnRequest extends AuthDefaultRequest {
|
||||
params.put("client_secret", config.getClientSecret());
|
||||
params.put("grant_type", "authorization_code");
|
||||
params.put("redirect_uri", config.getRedirectUri());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(AuthDefaultSource.PROGINN.accessToken(), params, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(AuthDefaultSource.PROGINN.accessToken(), params, false).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(accessTokenObject);
|
||||
return AuthToken.builder()
|
||||
|
||||
@ -40,7 +40,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(refreshTokenUrl(authToken.getRefreshToken()));
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(refreshTokenUrl(authToken.getRefreshToken())).getBody();
|
||||
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getAuthToken(response)).build();
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl("https://graph.qq.com/oauth2.0/me")
|
||||
.queryParam("access_token", authToken.getAccessToken())
|
||||
.queryParam("unionid", config.isUnionId() ? 1 : 0)
|
||||
.build());
|
||||
.build()).getBody();
|
||||
String removePrefix = response.replace("callback(", "");
|
||||
String removeSuffix = removePrefix.replace(");", "");
|
||||
String openId = removeSuffix.trim();
|
||||
|
||||
@ -68,7 +68,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
|
||||
}
|
||||
|
||||
private AuthToken getToken(String url) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(url);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(url).getBody();
|
||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
if (jsonObject.containsKey("error")) {
|
||||
throw new AuthException("Failed to get token from Renren: " + jsonObject);
|
||||
|
||||
@ -38,7 +38,8 @@ public class AuthSlackRequest extends AuthDefaultRequest {
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded");
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(authCallback.getCode()), null, header, false);
|
||||
String response = new HttpUtils(config.getHttpConfig())
|
||||
.get(accessTokenUrl(authCallback.getCode()), null, header, false).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(accessTokenObject);
|
||||
return AuthToken.builder()
|
||||
@ -54,7 +55,8 @@ public class AuthSlackRequest extends AuthDefaultRequest {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Bearer ".concat(authToken.getAccessToken()));
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, header, false);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig())
|
||||
.get(userInfoUrl(authToken), null, header, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(object);
|
||||
JSONObject user = object.getJSONObject("user");
|
||||
@ -77,7 +79,8 @@ public class AuthSlackRequest extends AuthDefaultRequest {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Bearer ".concat(authToken.getAccessToken()));
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(source.revoke(), null, header, false);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig())
|
||||
.get(source.revoke(), null, header, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(object);
|
||||
// 返回1表示取消授权成功,否则失败
|
||||
|
||||
@ -42,7 +42,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
|
||||
Map<String, String> form = MapUtil.parseStringToMap(accessTokenUrl, false);
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false).getBody();
|
||||
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(accessTokenObject);
|
||||
@ -60,7 +60,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
|
||||
.queryParam("site", "stackoverflow")
|
||||
.queryParam("key", this.config.getStackOverflowKey())
|
||||
.build();
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
this.checkResponse(object);
|
||||
JSONObject userObj = object.getJSONArray("items").getJSONObject(0);
|
||||
|
||||
@ -81,7 +81,7 @@ public class AuthTaobaoRequest extends AuthDefaultRequest {
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
String tokenUrl = refreshTokenUrl(oldToken.getRefreshToken());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
return AuthResponse.builder()
|
||||
.code(AuthResponseStatus.SUCCESS.getCode())
|
||||
|
||||
@ -45,7 +45,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
|
||||
form.put("code", authCallback.getCode());
|
||||
form.put("grant_type", "code");
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(accessTokenObject);
|
||||
@ -63,7 +63,8 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Authorization", "OAuth2 " + accessToken);
|
||||
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig())
|
||||
.get(source.userInfo(), null, httpHeader, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(object);
|
||||
@ -93,7 +94,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
form.put("_userId", uid);
|
||||
form.put("refresh_token", refreshToken);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false).getBody();
|
||||
JSONObject refreshTokenObject = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(refreshTokenObject);
|
||||
|
||||
@ -72,7 +72,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
httpHeader.add("User-Agent", "themattharris' HTTP Client");
|
||||
httpHeader.add("Host", "api.twitter.com");
|
||||
httpHeader.add("Accept", "*/*");
|
||||
String requestToken = new HttpUtils(config.getHttpConfig()).post(baseUrl, null, httpHeader);
|
||||
String requestToken = new HttpUtils(config.getHttpConfig()).post(baseUrl, null, httpHeader).getBody();
|
||||
|
||||
Map<String, String> res = MapUtil.parseStringToMap(requestToken, false);
|
||||
|
||||
@ -104,7 +104,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
|
||||
Map<String, String> form = new HashMap<>(3);
|
||||
form.put("oauth_verifier", authCallback.getOauth_verifier());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false).getBody();
|
||||
|
||||
Map<String, String> requestToken = MapUtil.parseStringToMap(response, false);
|
||||
|
||||
@ -132,7 +132,8 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Authorization", header);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
|
||||
String response = new HttpUtils(config.getHttpConfig())
|
||||
.get(userInfoUrl(authToken), null, httpHeader, false).getBody();
|
||||
JSONObject userInfo = JSONObject.parseObject(response);
|
||||
|
||||
return AuthUser.builder()
|
||||
|
||||
@ -75,7 +75,7 @@ public class AuthWeChatEnterpriseThirdQrcodeRequest extends AbstractAuthWeChatEn
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("corpid", config.getClientId());
|
||||
data.put("provider_secret", config.getClientSecret());
|
||||
return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code), data.toJSONString());
|
||||
return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code), data.toJSONString()).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,13 +96,15 @@ public class AuthWeChatEnterpriseThirdQrcodeRequest extends AbstractAuthWeChatEn
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doGetUserInfo(AuthToken authToken) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("auth_code", authToken.getCode());
|
||||
return new HttpUtils(config.getHttpConfig())
|
||||
.post(userInfoUrl(authToken), data.toJSONString());
|
||||
.post(userInfoUrl(authToken), data.toJSONString()).getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String userInfoUrl(AuthToken authToken) {
|
||||
return UrlBuilder.fromBaseUrl(source.userInfo())
|
||||
.queryParam("access_token", authToken.getAccessToken()).
|
||||
|
||||
@ -97,7 +97,7 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest {
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(accessTokenObject);
|
||||
|
||||
@ -94,7 +94,7 @@ public class AuthWeChatOpenRequest extends AuthDefaultRequest {
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
|
||||
this.checkResponse(accessTokenObject);
|
||||
|
||||
@ -56,7 +56,8 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Authorization", "OAuth2 " + oauthParam);
|
||||
httpHeader.add("API-RemoteIP", IpUtils.getLocalIp());
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig())
|
||||
.get(userInfoUrl(authToken), null, httpHeader, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(object.getString("error"));
|
||||
|
||||
@ -50,7 +50,7 @@ public class AuthXmlyRequest extends AuthDefaultRequest {
|
||||
map.put("device_id", config.getDeviceId());
|
||||
map.put("grant_type", "authorization_code");
|
||||
map.put("redirect_uri", config.getRedirectUri());
|
||||
String response = HttpUtil.post(source.accessToken(), map, true);
|
||||
String response = HttpUtil.post(source.accessToken(), map, true).getBody();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(accessTokenObject);
|
||||
|
||||
@ -97,7 +97,7 @@ public class AuthXmlyRequest extends AuthDefaultRequest {
|
||||
map.put("pack_id", config.getPackId());
|
||||
map.put("access_token", authToken.getAccessToken());
|
||||
map.put("sig", GlobalAuthUtils.generateXmlySignature(map, config.getClientSecret()));
|
||||
String rawUserInfo = HttpUtil.get(source.userInfo(), map, false);
|
||||
String rawUserInfo = HttpUtil.get(source.userInfo(), map, false).getBody();
|
||||
JSONObject object = JSONObject.parseObject(rawUserInfo);
|
||||
checkResponse(object);
|
||||
return AuthUser.builder()
|
||||
|
||||
@ -3,17 +3,22 @@ package me.zhyd.oauth.utils;
|
||||
import com.xkcoding.http.HttpUtil;
|
||||
import com.xkcoding.http.config.HttpConfig;
|
||||
import com.xkcoding.http.support.HttpHeader;
|
||||
import com.xkcoding.http.support.SimpleHttpResponse;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* HttpUtil 工具,统一处理 http 请求,方便对 simple-http 做定制
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class HttpUtils {
|
||||
|
||||
private SimpleHttpResponse httpResponse;
|
||||
|
||||
public HttpUtils(HttpConfig config) {
|
||||
HttpUtil.setConfig(config);
|
||||
}
|
||||
@ -26,10 +31,11 @@ public class HttpUtils {
|
||||
* GET 请求
|
||||
*
|
||||
* @param url URL
|
||||
* @return 结果
|
||||
* @return HttpUtils
|
||||
*/
|
||||
public String get(String url) {
|
||||
return HttpUtil.get(url);
|
||||
public HttpUtils get(String url) {
|
||||
this.httpResponse = HttpUtil.get(url, null, null, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,20 +45,22 @@ public class HttpUtils {
|
||||
* @param params 参数
|
||||
* @param header 请求头
|
||||
* @param encode 是否需要 url encode
|
||||
* @return 结果
|
||||
* @return HttpUtils
|
||||
*/
|
||||
public String get(String url, Map<String, String> params, HttpHeader header, boolean encode) {
|
||||
return HttpUtil.get(url, params, header, encode);
|
||||
public HttpUtils get(String url, Map<String, String> params, HttpHeader header, boolean encode) {
|
||||
this.httpResponse = HttpUtil.get(url, params, header, encode);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求
|
||||
*
|
||||
* @param url URL
|
||||
* @return 结果
|
||||
* @return HttpUtils
|
||||
*/
|
||||
public String post(String url) {
|
||||
return HttpUtil.post(url);
|
||||
public HttpUtils post(String url) {
|
||||
this.httpResponse = HttpUtil.post(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,10 +68,11 @@ public class HttpUtils {
|
||||
*
|
||||
* @param url URL
|
||||
* @param data JSON 参数
|
||||
* @return 结果
|
||||
* @return HttpUtils
|
||||
*/
|
||||
public String post(String url, String data) {
|
||||
return HttpUtil.post(url, data);
|
||||
public HttpUtils post(String url, String data) {
|
||||
this.httpResponse = HttpUtil.post(url, data);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,10 +81,11 @@ public class HttpUtils {
|
||||
* @param url URL
|
||||
* @param data JSON 参数
|
||||
* @param header 请求头
|
||||
* @return 结果
|
||||
* @return HttpUtils
|
||||
*/
|
||||
public String post(String url, String data, HttpHeader header) {
|
||||
return HttpUtil.post(url, data, header);
|
||||
public HttpUtils post(String url, String data, HttpHeader header) {
|
||||
this.httpResponse = HttpUtil.post(url, data, header);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,10 +94,11 @@ public class HttpUtils {
|
||||
* @param url URL
|
||||
* @param params form 参数
|
||||
* @param encode 是否需要 url encode
|
||||
* @return 结果
|
||||
* @return HttpUtils
|
||||
*/
|
||||
public String post(String url, Map<String, String> params, boolean encode) {
|
||||
return HttpUtil.post(url, params, encode);
|
||||
public HttpUtils post(String url, Map<String, String> params, boolean encode) {
|
||||
this.httpResponse = HttpUtil.post(url, params, encode);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,9 +108,28 @@ public class HttpUtils {
|
||||
* @param params form 参数
|
||||
* @param header 请求头
|
||||
* @param encode 是否需要 url encode
|
||||
* @return 结果
|
||||
* @return HttpUtils
|
||||
*/
|
||||
public String post(String url, Map<String, String> params, HttpHeader header, boolean encode) {
|
||||
return HttpUtil.post(url, params, header, encode);
|
||||
public HttpUtils post(String url, Map<String, String> params, HttpHeader header, boolean encode) {
|
||||
this.httpResponse = HttpUtil.post(url, params, header, encode);
|
||||
return this;
|
||||
}
|
||||
|
||||
private HttpUtils check() {
|
||||
if (null == httpResponse) {
|
||||
throw new AuthException("Invalid SimpleHttpResponse.");
|
||||
}
|
||||
if (!httpResponse.isSuccess()) {
|
||||
throw new AuthException(httpResponse.getError());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return this.check().getHttpResponse().getBody();
|
||||
}
|
||||
|
||||
public SimpleHttpResponse getHttpResponse() {
|
||||
return httpResponse;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user