/** * 使用授权后的Request Token换取Access Token * * @param oauth * @return * @throws Exception */ public OAuth accessToken(OAuth oauth) throws Exception { log.info( "accessToken oauth.getOauth_token() = " + oauth.getOauth_token() + "oauth.getOauth_verifier() = " + oauth.getOauth_verifier()); String url = "https://open.t.qq.com/cgi-bin/access_token"; QHttpClient http = new QHttpClient(); String queryString = getOauthParams( url, "GET", oauth.getOauth_consumer_secret(), oauth.getOauth_token_secret(), oauth.getAccessParams()); log.info("accessToken queryString = " + queryString); log.info("accessToken url = " + url); String responseData = http.httpGet(url, queryString); log.info("accessToken responseData = " + responseData); if (!parseToken(responseData, oauth)) { // Access Token 授权不通过 oauth.setStatus(2); } return oauth; }
/** * 获取未授权的Request Token * * @param oauth * @return * @throws Exception */ public OAuth requestToken(OAuth oauth) throws Exception { String url = "https://open.t.qq.com/cgi-bin/request_token"; QHttpClient http = new QHttpClient(); String queryString = getOauthParams(url, "GET", oauth.getOauth_consumer_secret(), "", oauth.getParams()); log.info("requestToken queryString = " + queryString); System.out.println("queryString:" + queryString); String responseData = http.httpGet(url, queryString); log.info("requestToken responseData = " + responseData); System.out.println("responseData:" + responseData); if (!parseToken(responseData, oauth)) { // Request Token 授权不通过 oauth.setStatus(1); log.info("requestToken past !"); } return oauth; }