/** * 使用Authorization code方式鉴权时,用授权码换取Access Token * * @param oAuth * @return * @throws Exception */ public static boolean accessToken(OAuthV2 oAuth) throws Exception { if (null == Q_HTTP_CLIENT) { throw new OAuthClientException("1001"); } log.info( "AuthorizeCode = " + oAuth.getAuthorizeCode() + "\nOpenid = " + oAuth.getOpenid() + "\nOpenkey =" + oAuth.getOpenkey()); String url = OAuthConstants.OAUTH_V2_GET_ACCESS_TOKEN_URL; String queryString = QStrOperate.getQueryString(oAuth.getAccessTokenByCodeParamsList()); log.info("authorization queryString = " + queryString); String responseData = Q_HTTP_CLIENT.simpleHttpGet(url, queryString); log.info("authorization responseData = " + responseData); if (!parseAccessToken(responseData, oAuth)) { // Access Token 授权不通过 oAuth.setStatus(3); return false; } else { return true; } }
/** * 使用Authorization code方式鉴权时,合成转向授权页面的url * * @param oAuth * @return */ public static String generateAuthorizationURL(OAuthV2 oAuth) { oAuth.setResponseType("code"); String queryString = QStrOperate.getQueryString(oAuth.getAuthorizationParamsList()); log.info("authorization queryString = " + queryString); String urlWithQueryString = OAuthConstants.OAUTH_V2_AUTHORIZE_URL + "?" + queryString; log.info("url with queryString = " + urlWithQueryString); return urlWithQueryString; }