抽取公众号部分微信请求URL到常量类中 #195

This commit is contained in:
Binary Wang
2017-04-28 14:28:20 +08:00
parent 091e47897d
commit bb83ead12c
5 changed files with 139 additions and 101 deletions

View File

@@ -0,0 +1,90 @@
package me.chanjar.weixin.mp.api;
/**
* <pre>
* 公众号相关接口URL常量类
* Created by Binary Wang on 2017-4-28.
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a>
* </pre>
*/
public class WxMpApiUrls {
/**
* 获取access_token
*/
public static final String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
/**
* 获得jsapi_ticket
*/
public static final String GET_JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
/**
* 上传群发用的图文消息
*/
public static final String MEDIA_UPLOAD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadnews";
/**
* 上传群发用的视频
*/
public static final String MEDIA_UPLOAD_VIDEO_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo";
/**
* 分组群发消息
*/
public static final String MESSAGE_MASS_SENDALL_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall";
/**
* 按openId列表群发消息
*/
public static final String MESSAGE_MASS_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/send";
/**
* 群发消息预览接口
*/
public static final String MESSAGE_MASS_PREVIEW_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/preview";
/**
* 长链接转短链接接口
*/
public static final String SHORTURL_API_URL = "https://api.weixin.qq.com/cgi-bin/shorturl";
/**
* 语义查询接口
*/
public static final String SEMANTIC_SEMPROXY_SEARCH_URL = "https://api.weixin.qq.com/semantic/semproxy/search";
/**
* 用code换取oauth2的access token
*/
public static final String OAUTH2_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
/**
* 刷新oauth2的access token
*/
public static final String OAUTH2_REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s";
/**
* 用oauth2获取用户信息
*/
public static final String OAUTH2_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=%s";
/**
* 验证oauth2的access token是否有效
*/
public static final String OAUTH2_VALIDATE_TOKEN_URL = "https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s";
/**
* 获取微信服务器IP地址
*/
public static final String GET_CALLBACK_IP_URL = "https://api.weixin.qq.com/cgi-bin/getcallbackip";
/**
* 第三方使用网站应用授权登录的url
*/
public static final String QRCONNECT_URL = "https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect";
/**
* oauth2授权的url连接
*/
public static final String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect";
}

View File

@@ -15,6 +15,7 @@ import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.mp.api.*; import me.chanjar.weixin.mp.api.*;
import me.chanjar.weixin.mp.bean.*; import me.chanjar.weixin.mp.bean.*;
import me.chanjar.weixin.mp.bean.result.*; import me.chanjar.weixin.mp.bean.result.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -70,8 +71,7 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ
} }
if (this.getWxMpConfigStorage().isJsapiTicketExpired()) { if (this.getWxMpConfigStorage().isJsapiTicketExpired()) {
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi"; String responseContent = execute(new SimpleGetRequestExecutor(), WxMpApiUrls.GET_JSAPI_TICKET_URL, null);
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
@@ -107,93 +107,66 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ
@Override @Override
public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews"; String responseContent = this.post(WxMpApiUrls.MEDIA_UPLOAD_NEWS_URL, news.toJson());
String responseContent = this.post(url, news.toJson());
return WxMpMassUploadResult.fromJson(responseContent); return WxMpMassUploadResult.fromJson(responseContent);
} }
@Override @Override
public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException { public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo"; String responseContent = this.post(WxMpApiUrls.MEDIA_UPLOAD_VIDEO_URL, video.toJson());
String responseContent = this.post(url, video.toJson());
return WxMpMassUploadResult.fromJson(responseContent); return WxMpMassUploadResult.fromJson(responseContent);
} }
@Override @Override
public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException { public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"; String responseContent = this.post(WxMpApiUrls.MESSAGE_MASS_SENDALL_URL, message.toJson());
String responseContent = this.post(url, message.toJson());
return WxMpMassSendResult.fromJson(responseContent); return WxMpMassSendResult.fromJson(responseContent);
} }
@Override @Override
public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException { public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send"; String responseContent = this.post(WxMpApiUrls.MESSAGE_MASS_SEND_URL, message.toJson());
String responseContent = this.post(url, message.toJson());
return WxMpMassSendResult.fromJson(responseContent); return WxMpMassSendResult.fromJson(responseContent);
} }
@Override @Override
public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception { public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception {
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"; String responseContent = this.post(WxMpApiUrls.MESSAGE_MASS_PREVIEW_URL, wxMpMassPreviewMessage.toJson());
String responseContent = this.post(url, wxMpMassPreviewMessage.toJson());
return WxMpMassSendResult.fromJson(responseContent); return WxMpMassSendResult.fromJson(responseContent);
} }
@Override @Override
public String shortUrl(String long_url) throws WxErrorException { public String shortUrl(String long_url) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/shorturl";
JsonObject o = new JsonObject(); JsonObject o = new JsonObject();
o.addProperty("action", "long2short"); o.addProperty("action", "long2short");
o.addProperty("long_url", long_url); o.addProperty("long_url", long_url);
String responseContent = this.post(url, o.toString()); String responseContent = this.post(WxMpApiUrls.SHORTURL_API_URL, o.toString());
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
} }
@Override @Override
public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException { public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException {
String url = "https://api.weixin.qq.com/semantic/semproxy/search"; String responseContent = this.post(WxMpApiUrls.SEMANTIC_SEMPROXY_SEARCH_URL, semanticQuery.toJson());
String responseContent = this.post(url, semanticQuery.toJson());
return WxMpSemanticQueryResult.fromJson(responseContent); return WxMpSemanticQueryResult.fromJson(responseContent);
} }
@Override @Override
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) { public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
StringBuilder url = new StringBuilder(); return String.format(WxMpApiUrls.CONNECT_OAUTH2_AUTHORIZE_URL,
url.append("https://open.weixin.qq.com/connect/oauth2/authorize?"); this.getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state));
url.append("appid=").append(this.getWxMpConfigStorage().getAppId());
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
url.append("&response_type=code");
url.append("&scope=").append(scope);
if (state != null) {
url.append("&state=").append(state);
}
url.append("#wechat_redirect");
return url.toString();
} }
@Override @Override
public String buildQrConnectUrl(String redirectURI, String scope, public String buildQrConnectUrl(String redirectURI, String scope, String state) {
String state) { return String.format(WxMpApiUrls.QRCONNECT_URL,
StringBuilder url = new StringBuilder(); this.getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state));
url.append("https://open.weixin.qq.com/connect/qrconnect?");
url.append("appid=").append(this.getWxMpConfigStorage().getAppId());
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
url.append("&response_type=code");
url.append("&scope=").append(scope);
if (state != null) {
url.append("&state=").append(state);
}
url.append("#wechat_redirect");
return url.toString();
} }
private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxErrorException { private WxMpOAuth2AccessToken getOAuth2AccessToken(String url) throws WxErrorException {
try { try {
RequestExecutor<String, String> executor = new SimpleGetRequestExecutor(); RequestExecutor<String, String> executor = new SimpleGetRequestExecutor();
String responseText = executor.execute(this, url.toString(), null); String responseText = executor.execute(this, url, null);
return WxMpOAuth2AccessToken.fromJson(responseText); return WxMpOAuth2AccessToken.fromJson(responseText);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -202,42 +175,27 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ
@Override @Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException { public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
StringBuilder url = new StringBuilder(); String url = String.format(WxMpApiUrls.OAUTH2_ACCESS_TOKEN_URL, this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret(), code);
url.append("https://api.weixin.qq.com/sns/oauth2/access_token?");
url.append("appid=").append(this.getWxMpConfigStorage().getAppId());
url.append("&secret=").append(this.getWxMpConfigStorage().getSecret());
url.append("&code=").append(code);
url.append("&grant_type=authorization_code");
return this.getOAuth2AccessToken(url); return this.getOAuth2AccessToken(url);
} }
@Override @Override
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException { public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
StringBuilder url = new StringBuilder(); String url = String.format(WxMpApiUrls.OAUTH2_REFRESH_TOKEN_URL, this.getWxMpConfigStorage().getAppId(), refreshToken);
url.append("https://api.weixin.qq.com/sns/oauth2/refresh_token?");
url.append("appid=").append(this.getWxMpConfigStorage().getAppId());
url.append("&grant_type=refresh_token");
url.append("&refresh_token=").append(refreshToken);
return this.getOAuth2AccessToken(url); return this.getOAuth2AccessToken(url);
} }
@Override @Override
public WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken oAuth2AccessToken, String lang) throws WxErrorException { public WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken oAuth2AccessToken, String lang) throws WxErrorException {
StringBuilder url = new StringBuilder();
url.append("https://api.weixin.qq.com/sns/userinfo?");
url.append("access_token=").append(oAuth2AccessToken.getAccessToken());
url.append("&openid=").append(oAuth2AccessToken.getOpenId());
if (lang == null) { if (lang == null) {
url.append("&lang=zh_CN"); lang = "zh_CN";
} else {
url.append("&lang=").append(lang);
} }
String url = String.format(WxMpApiUrls.OAUTH2_USERINFO_URL, oAuth2AccessToken.getAccessToken(), oAuth2AccessToken.getOpenId(), lang);
try { try {
RequestExecutor<String, String> executor = new SimpleGetRequestExecutor(); RequestExecutor<String, String> executor = new SimpleGetRequestExecutor();
String responseText = executor.execute(this, url.toString(), null); String responseText = executor.execute(this, url, null);
return WxMpUser.fromJson(responseText); return WxMpUser.fromJson(responseText);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -246,14 +204,11 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ
@Override @Override
public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken) { public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken) {
StringBuilder url = new StringBuilder(); String url = String.format(WxMpApiUrls.OAUTH2_VALIDATE_TOKEN_URL, oAuth2AccessToken.getAccessToken(), oAuth2AccessToken.getOpenId());
url.append("https://api.weixin.qq.com/sns/auth?");
url.append("access_token=").append(oAuth2AccessToken.getAccessToken());
url.append("&openid=").append(oAuth2AccessToken.getOpenId());
try { try {
RequestExecutor<String, String> executor = new SimpleGetRequestExecutor(); RequestExecutor<String, String> executor = new SimpleGetRequestExecutor();
executor.execute(this, url.toString(), null); executor.execute(this, url, null);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (WxErrorException e) { } catch (WxErrorException e) {
@@ -264,8 +219,7 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ
@Override @Override
public String[] getCallbackIP() throws WxErrorException { public String[] getCallbackIP() throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip"; String responseContent = this.get(WxMpApiUrls.GET_CALLBACK_IP_URL, null);
String responseContent = get(url, null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
String[] ipArray = new String[ipList.size()]; String[] ipArray = new String[ipList.size()];

View File

@@ -1,8 +1,13 @@
package me.chanjar.weixin.mp.api.impl.apache; package me.chanjar.weixin.mp.api.impl.apache;
import java.io.IOException; import me.chanjar.weixin.common.bean.WxAccessToken;
import java.util.concurrent.locks.Lock; import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.mp.api.WxMpApiUrls;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.impl.AbstractWxMpServiceImpl;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@@ -10,13 +15,8 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import me.chanjar.weixin.common.bean.WxAccessToken; import java.io.IOException;
import me.chanjar.weixin.common.bean.result.WxError; import java.util.concurrent.locks.Lock;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.impl.AbstractWxMpServiceImpl;
/** /**
* apache-http方式实现 * apache-http方式实现
@@ -66,9 +66,8 @@ public class WxMpServiceImpl extends AbstractWxMpServiceImpl<CloseableHttpClient
} }
if (this.getWxMpConfigStorage().isAccessTokenExpired()) { if (this.getWxMpConfigStorage().isAccessTokenExpired()) {
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + String url = String.format(WxMpApiUrls.GET_ACCESS_TOKEN_URL,
"&appid=" + this.getWxMpConfigStorage().getAppId() + "&secret=" this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
+ this.getWxMpConfigStorage().getSecret();
try { try {
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);
if (this.getRequestHttpProxy() != null) { if (this.getRequestHttpProxy() != null) {

View File

@@ -51,9 +51,8 @@ public class WxMpServiceImpl extends AbstractWxMpServiceImpl<HttpConnectionProvi
} }
if (this.getWxMpConfigStorage().isAccessTokenExpired()) { if (this.getWxMpConfigStorage().isAccessTokenExpired()) {
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + String url = String.format(WxMpApiUrls.GET_ACCESS_TOKEN_URL,
"&appid=" + this.getWxMpConfigStorage().getAppId() + "&secret=" this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
+ this.getWxMpConfigStorage().getSecret();
HttpRequest request = HttpRequest.get(url); HttpRequest request = HttpRequest.get(url);

View File

@@ -1,23 +1,21 @@
package me.chanjar.weixin.mp.api.impl.okhttp; package me.chanjar.weixin.mp.api.impl.okhttp;
import java.io.IOException;
import java.util.concurrent.locks.Lock;
import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo;
import me.chanjar.weixin.mp.api.*; import me.chanjar.weixin.mp.api.WxMpApiUrls;
import me.chanjar.weixin.mp.api.impl.*; import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.impl.AbstractWxMpServiceImpl;
import okhttp3.*; import okhttp3.*;
import java.io.IOException;
import java.util.concurrent.locks.Lock;
public class WxMpServiceImpl extends AbstractWxMpServiceImpl<ConnectionPool, OkhttpProxyInfo> { public class WxMpServiceImpl extends AbstractWxMpServiceImpl<ConnectionPool, OkhttpProxyInfo> {
private ConnectionPool httpClient; private ConnectionPool httpClient;
private OkhttpProxyInfo httpProxy; private OkhttpProxyInfo httpProxy;
@Override @Override
public ConnectionPool getRequestHttpClient() { public ConnectionPool getRequestHttpClient() {
return httpClient; return httpClient;
@@ -28,7 +26,6 @@ public class WxMpServiceImpl extends AbstractWxMpServiceImpl<ConnectionPool, Okh
return httpProxy; return httpProxy;
} }
@Override @Override
public String getAccessToken(boolean forceRefresh) throws WxErrorException { public String getAccessToken(boolean forceRefresh) throws WxErrorException {
Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); Lock lock = this.getWxMpConfigStorage().getAccessTokenLock();
@@ -40,9 +37,8 @@ public class WxMpServiceImpl extends AbstractWxMpServiceImpl<ConnectionPool, Okh
} }
if (this.getWxMpConfigStorage().isAccessTokenExpired()) { if (this.getWxMpConfigStorage().isAccessTokenExpired()) {
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" + String url = String.format(WxMpApiUrls.GET_ACCESS_TOKEN_URL,
"&appid=" + this.getWxMpConfigStorage().getAppId() + "&secret=" this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
+ this.getWxMpConfigStorage().getSecret();
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().connectionPool(httpClient); OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().connectionPool(httpClient);
//设置代理 //设置代理
@@ -62,8 +58,8 @@ public class WxMpServiceImpl extends AbstractWxMpServiceImpl<ConnectionPool, Okh
//得到httpClient //得到httpClient
OkHttpClient client = clientBuilder.build(); OkHttpClient client = clientBuilder.build();
Request request =new Request.Builder().url(url).get().build(); Request request = new Request.Builder().url(url).get().build();
Response response =client.newCall(request).execute(); Response response = client.newCall(request).execute();
String resultContent = response.body().toString(); String resultContent = response.body().toString();
WxError error = WxError.fromJson(resultContent); WxError error = WxError.fromJson(resultContent);
if (error.getErrorCode() != 0) { if (error.getErrorCode() != 0) {