|
|
@@ -142,7 +142,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String post(String uri, JsonObject postData,String tokenKeyName) throws WxErrorException { |
|
|
|
public String post(String uri, String postData,String tokenKeyName) throws WxErrorException { |
|
|
|
//"component_access_token" |
|
|
|
return postByCommonAccessToken(uri, postData, tokenKeyName); |
|
|
|
} |
|
|
@@ -157,10 +157,9 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
String componentAccessToken = getComponentAccessToken(false); |
|
|
|
return excuteRequet(uri, accessTokenKey, componentAccessToken, null, true, RequestMethod.GET); |
|
|
|
} |
|
|
|
private String postByCommonAccessToken(String uri, JsonObject postData ,String accessTokenKey) throws WxErrorException { |
|
|
|
private String postByCommonAccessToken(String uri, String postData ,String accessTokenKey) throws WxErrorException { |
|
|
|
String componentAccessToken = getComponentAccessToken(false); |
|
|
|
postData.addProperty(accessTokenKey,componentAccessToken); |
|
|
|
return excuteRequet(uri, accessTokenKey, componentAccessToken, postData.toString(), true, RequestMethod.POST); |
|
|
|
return excuteRequet(uri, accessTokenKey, componentAccessToken, postData, true, RequestMethod.POST); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -196,11 +195,12 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
* @throws WxErrorException |
|
|
|
*/ |
|
|
|
private String createPreAuthUrl(String redirectURI) throws WxErrorException { |
|
|
|
JsonObject jsonObject = new JsonObject(); |
|
|
|
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); |
|
|
|
String responseContent = post(API_CREATE_PREAUTHCODE_URL, jsonObject,"component_access_token"); |
|
|
|
String uri = API_CREATE_PREAUTHCODE_URL + "?component_appid="+getWxOpenConfigStorage().getComponentAppId(); |
|
|
|
|
|
|
|
String responseContent = post(API_CREATE_PREAUTHCODE_URL, null,"component_access_token"); |
|
|
|
log.info(responseContent +"----------responseContent"); |
|
|
|
jsonObject = TtOpenGsonBuilder.create().fromJson(responseContent, JsonObject.class); |
|
|
|
|
|
|
|
JsonObject jsonObject = TtOpenGsonBuilder.create().fromJson(responseContent, JsonObject.class); |
|
|
|
|
|
|
|
StringBuilder preAuthUrl = new StringBuilder(String.format(COMPONENT_LOGIN_PAGE_URL, |
|
|
|
getWxOpenConfigStorage().getComponentAppId(), |
|
|
@@ -251,7 +251,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
JsonObject jsonObject = new JsonObject(); |
|
|
|
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); |
|
|
|
jsonObject.addProperty("authorization_appid", authorizationCode); |
|
|
|
String responseContent = post(RETRIEVE_AUTHORIZER_TOKEN_URL, jsonObject, "component_access_token"); |
|
|
|
String responseContent = post(RETRIEVE_AUTHORIZER_TOKEN_URL, jsonObject.toString(), "component_access_token"); |
|
|
|
TtOpenRetrieveCode retrieveCode = TtOpenGsonBuilder.create().fromJson(responseContent, TtOpenRetrieveCode.class); |
|
|
|
if(retrieveCode == null){ |
|
|
|
return null; |
|
|
@@ -276,7 +276,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); |
|
|
|
jsonObject.addProperty("offset", begin); |
|
|
|
jsonObject.addProperty("count", len); |
|
|
|
String responseContent = post(API_GET_AUTHORIZER_LIST, jsonObject,"component_access_token"); |
|
|
|
String responseContent = post(API_GET_AUTHORIZER_LIST, jsonObject.toString(),"component_access_token"); |
|
|
|
WxOpenAuthorizerListResult ret = WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerListResult.class); |
|
|
|
if (ret != null && ret.getList() != null) { |
|
|
|
for (Map<String, String> data : ret.getList()) { |
|
|
@@ -296,7 +296,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); |
|
|
|
jsonObject.addProperty("authorizer_appid", authorizerAppid); |
|
|
|
jsonObject.addProperty("option_name", optionName); |
|
|
|
String responseContent = post(API_GET_AUTHORIZER_OPTION_URL, jsonObject,"component_access_token"); |
|
|
|
String responseContent = post(API_GET_AUTHORIZER_OPTION_URL, jsonObject.toString(),"component_access_token"); |
|
|
|
return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerOptionResult.class); |
|
|
|
} |
|
|
|
|
|
|
@@ -307,7 +307,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
jsonObject.addProperty("authorizer_appid", authorizerAppid); |
|
|
|
jsonObject.addProperty("option_name", optionName); |
|
|
|
jsonObject.addProperty("option_value", optionValue); |
|
|
|
post(API_SET_AUTHORIZER_OPTION_URL, jsonObject,"component_access_token"); |
|
|
|
post(API_SET_AUTHORIZER_OPTION_URL, jsonObject.toString(),"component_access_token"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -402,14 +402,14 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
public void addToTemplate(long draftId) throws WxErrorException { |
|
|
|
JsonObject param = new JsonObject(); |
|
|
|
param.addProperty("draft_id", draftId); |
|
|
|
post(ADD_TO_TEMPLATE_URL, param, "access_token"); |
|
|
|
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, "access_token"); |
|
|
|
post(DELETE_TEMPLATE_URL, param.toString(), "access_token"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -425,15 +425,11 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
|
|
|
|
|
|
|
|
private String excuteRequet(String uri,String tokenKey,String tokenValue,String postData,boolean isCompontAccessToken,RequestMethod method) throws WxErrorException { |
|
|
|
|
|
|
|
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + tokenKey + "=" + tokenValue; |
|
|
|
try { |
|
|
|
if (method == RequestMethod.POST) { |
|
|
|
String uriWithComponentAccessToken = uri; |
|
|
|
log.info("--------uri = "+uriWithComponentAccessToken); |
|
|
|
log.info("--------postData = "+postData); |
|
|
|
return getTtOpenService().post(uriWithComponentAccessToken, postData); |
|
|
|
}else { |
|
|
|
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + tokenKey + "=" + tokenValue; |
|
|
|
return getTtOpenService().get(uriWithComponentAccessToken, null); |
|
|
|
} |
|
|
|
} catch (WxErrorException e) { |
|
|
@@ -462,8 +458,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
|
|
|
|
if (isCompontAccessToken && this.getWxOpenConfigStorage().autoRefreshToken()) { |
|
|
|
if (method == RequestMethod.POST) { |
|
|
|
JsonObject object = TtOpenGsonBuilder.create().fromJson(postData, JsonObject.class); |
|
|
|
return this.post(uri, object, tokenKey); |
|
|
|
return this.post(uri, postData, tokenKey); |
|
|
|
}else { |
|
|
|
return this.get(uri, tokenKey); |
|
|
|
} |
|
|
@@ -521,7 +516,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat); |
|
|
|
jsonObject.addProperty("legal_persona_name", legalPersonaName); |
|
|
|
jsonObject.addProperty("component_phone", componentPhone); |
|
|
|
String response = post(FAST_REGISTER_WEAPP_URL, jsonObject, "component_access_token"); |
|
|
|
String response = post(FAST_REGISTER_WEAPP_URL, jsonObject.toString(), "component_access_token"); |
|
|
|
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); |
|
|
|
} |
|
|
|
|
|
|
@@ -531,7 +526,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService { |
|
|
|
jsonObject.addProperty("name", name); |
|
|
|
jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat); |
|
|
|
jsonObject.addProperty("legal_persona_name", legalPersonaName); |
|
|
|
String response = post(FAST_REGISTER_WEAPP_SEARCH_URL, jsonObject, "component_access_token"); |
|
|
|
String response = post(FAST_REGISTER_WEAPP_SEARCH_URL, jsonObject.toString(), "component_access_token"); |
|
|
|
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); |
|
|
|
} |
|
|
|
} |