10000 fix 小程序代码模版库管理 access_token key 错误 by 007gzs · Pull Request #639 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content

fix 小程序代码模版库管理 access_token key 错误 #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ public String getComponentAccessToken(boolean forceRefresh) throws WxErrorExcept
}

private String post(String uri, String postData) throws WxErrorException {
return post(uri, postData, "component_access_token");
}

private String post(String uri, String postData, String accessTokenKey) throws WxErrorException {
String componentAccessToken = getComponentAccessToken(false);
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + "component_access_token=" + componentAccessToken;
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + accessTokenKey + "=" + componentAccessToken;
try {
return getWxOpenService().post(uriWithComponentAccessToken, postData);
}catch (WxErrorException e){
} catch (WxErrorException e) {
WxError error = e.getError();
/*
* 发生以下情况时尝试刷新access_token
Expand All @@ -131,7 +135,7 @@ private String post(String uri, String postData) throws WxErrorException {
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
this.getWxOpenConfigStorage().expireComponentAccessToken();
if (this.getWxOpenConfigStorage().autoRefreshToken()) {
return this.post(uri, postData);
return this.post(uri, postData, accessTokenKey);
}
}
if (error.getErrorCode() != 0) {
Expand All @@ -142,11 +146,14 @@ private String post(String uri, String postData) throws WxErrorException {
}

private String get(String uri) throws WxErrorException {
return get(uri, "component_access_token");
}
private String get(String uri, String accessTokenKey) throws WxErrorException {
String componentAccessToken = getComponentAccessToken(false);
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + "component_access_token=" + componentAccessToken;
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + accessTokenKey + "=" + componentAccessToken;
try {
return getWxOpenService().get(uriWithComponentAccessToken, null);
}catch (WxErrorException e){
} catch (WxErrorException e) {
WxError error = e.getError();
/*
* 发生以下情况时尝试刷新access_token
Expand All @@ -158,7 +165,7 @@ private String get(String uri) throws WxErrorException {
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
this.getWxOpenConfigStorage().expireComponentAccessToken();
if (this.getWxOpenConfigStorage().autoRefreshToken()) {
return this.get(uri);
return this.get(uri, accessTokenKey);
}
}
if (error.getErrorCode() != 0) {
Expand Down Expand Up @@ -298,7 +305,7 @@ public WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCod

@Override
public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL);
String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
boolean hasDraftList = response.has("draft_list");
if (hasDraftList) {
Expand All @@ -312,7 +319,7 @@ public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException

@Override
public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_LIST_URL);
String responseContent = get(GET_TEMPLATE_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
boolean hasDraftList = response.has("template_list");
if (hasDraftList) {
Expand All @@ -328,13 +335,13 @@ public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException {
public void addToTemplate(long draftId) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("draft_id", draftId);
post(ADD_TO_TEMPLATE_URL, param.toString());
post(ADD_TO_TEMPLATE_URL, param.toString(), "access_token");
}

@Override
public void deleteTemplate(long templateId) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("template_id", templateId);
post(DELETE_TEMPLATE_URL, param.toString());
post(DELETE_TEMPLATE_URL, param.toString(), "access_token");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,12 @@
private WxOpenComponentService wxOpenComponentService;
private WxMaConfig wxMaConfig;
private String appId;
private WxMaUserService wxMaUserService;

public WxOpenMaServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMaConfig wxMaConfig) {
this.wxOpenComponentService = wxOpenComponentService;
this.appId = appId;
this.wxMaConfig = wxMaConfig;
initHttp();
this.wxMaUserService = new WxOpenMaUserServiceImpl(wxOpenComponentService, this);
}

@Override
public WxMaUserService getUserService() {
return this.wxMaUserService;
}

@Override
Expand Down

This file was deleted.

0