@@ -115,11 +115,15 @@ public String getComponentAccessToken(boolean forceRefresh) throws WxErrorExcept
115
115
}
116
116
117
117
private String post (String uri , String postData ) throws WxErrorException {
118
+ return post (uri , postData , "component_access_token" );
119
+ }
120
+
121
+ private String post (String uri , String postData , String accessTokenKey ) throws WxErrorException {
118
122
String componentAccessToken = getComponentAccessToken (false );
119
- String uriWithComponentAccessToken = uri + (uri .contains ("?" ) ? "&" : "?" ) + "component_access_token =" + componentAccessToken ;
123
+ String uriWithComponentAccessToken = uri + (uri .contains ("?" ) ? "&" : "?" ) + accessTokenKey + " =" + componentAccessToken ;
120
124
try {
121
125
return getWxOpenService ().post (uriWithComponentAccessToken , postData );
122
- }catch (WxErrorException e ){
126
+ } catch (WxErrorException e ) {
123
127
WxError error = e .getError ();
124
128
/*
125
129
* 发生以下情况时尝试刷新access_token
@@ -131,7 +135,7 @@ private String post(String uri, String postData) throws WxErrorException {
131
135
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
132
136
this .getWxOpenConfigStorage ().expireComponentAccessToken ();
133
137
if (this .getWxOpenConfigStorage ().autoRefreshToken ()) {
134
- return this .post (uri , postData );
138
+ return this .post (uri , postData , accessTokenKey );
135
139
}
136
140
}
137
141
if (error .getErrorCode () != 0 ) {
@@ -142,11 +146,14 @@ private String post(String uri, String postData) throws WxErrorException {
142
146
}
143
147
144
148
private String get (String uri ) throws WxErrorException {
149
+ return get (uri , "component_access_token" );
150
+ }
151
+ private String get (String uri , String accessTokenKey ) throws WxErrorException {
145
152
String componentAccessToken = getComponentAccessToken (false );
146
- String uriWithComponentAccessToken = uri + (uri .contains ("?" ) ? "&" : "?" ) + "component_access_token =" + componentAccessToken ;
153
+ String uriWithComponentAccessToken = uri + (uri .contains ("?" ) ? "&" : "?" ) + accessTokenKey + " =" + componentAccessToken ;
147
154
try {
148
155
return getWxOpenService ().get (uriWithComponentAccessToken , null );
149
- }catch (WxErrorException e ){
156
+ } catch (WxErrorException e ) {
150
157
WxError error = e .getError ();
151
158
/*
152
159
* 发生以下情况时尝试刷新access_token
@@ -158,7 +165,7 @@ private String get(String uri) throws WxErrorException {
158
165
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
159
166
this .getWxOpenConfigStorage ().expireComponentAccessToken ();
160
167
if (this .getWxOpenConfigStorage ().autoRefreshToken ()) {
161
- return this .get (uri );
168
+ return this .get (uri , accessTokenKey );
162
169
}
163
170
}
164
171
if (error .getErrorCode () != 0 ) {
@@ -298,7 +305,7 @@ public WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCod
298
305
299
306
@ Override
300
307
public List <WxOpenMaCodeTemplate > getTemplateDraftList () throws WxErrorException {
301
- String responseContent = get (GET_TEMPLATE_DRAFT_LIST_URL );
308
+ String responseContent = get (GET_TEMPLATE_DRAFT_LIST_URL , "access_token" );
302
309
JsonObject response = JSON_PARSER .parse (StringUtils .defaultString (responseContent , "{}" )).getAsJsonObject ();
303
310
boolean hasDraftList = response .has ("draft_list" );
304
311
if (hasDraftList ) {
@@ -312,7 +319,7 @@ public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException
312
319
313
320
@ Override
314
321
public List <WxOpenMaCodeTemplate > getTemplateList () throws WxErrorException {
315
- String responseContent = get (GET_TEMPLATE_LIST_URL );
322
+ String responseContent = get (GET_TEMPLATE_LIST_URL , "access_token" );
316
323
JsonObject response = JSON_PARSER .parse (StringUtils .defaultString (responseContent , "{}" )).getAsJsonObject ();
317
324
boolean hasDraftList = response .has ("template_list" );
318
325
if (hasDraftList ) {
@@ -328,13 +335,13 @@ public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException {
328
335
public void addToTemplate (long draftId ) throws WxErrorException {
329
336
JsonObject param = new JsonObject ();
330
337
param .addProperty ("draft_id" , draftId );
331
- post (ADD_TO_TEMPLATE_URL , param .toString ());
338
+ post (ADD_TO_TEMPLATE_URL , param .toString (), "access_token" );
332
339
}
333
340
334
341
@ Override
335
342
public void deleteTemplate (long templateId ) throws WxErrorException {
336
343
JsonObject param = new JsonObject ();
337
344
param .addProperty ("template_id" , templateId );
338
- post (DELETE_TEMPLATE_URL , param .toString ());
345
+ post (DELETE_TEMPLATE_URL , param .toString (), "access_token" );
339
346
}
340
347
}
0 commit comments