public static WebAccessToken getJsAccessToken(String code) { ApiConfig ac = ApiConfigKit.getApiConfig(); String json = HttpKit.get( "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + ac.getAppId() + "&secret=" + ac.getAppSecret() + "&code=" + code + "&grant_type=authorization_code"); return new WebAccessToken(json); }
private static synchronized AccessToken requestAccessToken() { AccessToken result = null; ApiConfig ac = ApiConfigKit.getApiConfig(); for (int i = 0; i < 3; i++) { String appId = ac.getAppId(); String appSecret = ac.getAppSecret(); Map<String, String> queryParas = ParaMap.create("appid", appId).put("secret", appSecret).getData(); String json = HttpKit.get(url, queryParas); result = new AccessToken(json); if (result.isAvailable()) break; } return result; }
private static synchronized WebAccessToken refreshWebAccessToken(WebAccessToken webAccessToken) { ApiConfig ac = ApiConfigKit.getApiConfig(); String json = HttpKit.get( "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=" + ac.getAppId() + "&grant_type=refresh_token&refresh_token=" + webAccessToken.getRefreshToken()); try { WebAccessToken newwat = new WebAccessToken(json); return newwat; } catch (Exception e) { throw new RuntimeException(e); } }