Explorar el Código

update tt

master
xhxu hace 3 años
padre
commit
9f2869b60e
Se han modificado 2 ficheros con 19 adiciones y 24 borrados
  1. +1
    -1
      mallinkService/src/main/java/com/iformall/service/toutiao/api/TtOpenComponentService.java
  2. +18
    -23
      mallinkService/src/main/java/com/iformall/service/toutiao/api/impl/TtOpenComponentServiceImpl.java

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/toutiao/api/TtOpenComponentService.java Ver fichero

@@ -90,7 +90,7 @@ public interface TtOpenComponentService {


String getComponentAccessToken(boolean forceRefresh) throws WxErrorException; String getComponentAccessToken(boolean forceRefresh) throws WxErrorException;


String post(String uri, JsonObject postData, String tokenKeyName) throws WxErrorException;
String post(String uri, String postData, String tokenKeyName) throws WxErrorException;


String postByAppAccessToken(String appId,String uri, String postData,String tokenKeyName) throws WxErrorException; String postByAppAccessToken(String appId,String uri, String postData,String tokenKeyName) throws WxErrorException;


+ 18
- 23
mallinkService/src/main/java/com/iformall/service/toutiao/api/impl/TtOpenComponentServiceImpl.java Ver fichero

@@ -142,7 +142,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
} }


@Override @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" //"component_access_token"
return postByCommonAccessToken(uri, postData, tokenKeyName); return postByCommonAccessToken(uri, postData, tokenKeyName);
} }
@@ -157,10 +157,9 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
String componentAccessToken = getComponentAccessToken(false); String componentAccessToken = getComponentAccessToken(false);
return excuteRequet(uri, accessTokenKey, componentAccessToken, null, true, RequestMethod.GET); 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); 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 @Override
@@ -196,11 +195,12 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
* @throws WxErrorException * @throws WxErrorException
*/ */
private String createPreAuthUrl(String redirectURI) 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"); 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, StringBuilder preAuthUrl = new StringBuilder(String.format(COMPONENT_LOGIN_PAGE_URL,
getWxOpenConfigStorage().getComponentAppId(), getWxOpenConfigStorage().getComponentAppId(),
@@ -251,7 +251,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
jsonObject.addProperty("authorization_appid", authorizationCode); 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); TtOpenRetrieveCode retrieveCode = TtOpenGsonBuilder.create().fromJson(responseContent, TtOpenRetrieveCode.class);
if(retrieveCode == null){ if(retrieveCode == null){
return null; return null;
@@ -276,7 +276,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
jsonObject.addProperty("offset", begin); jsonObject.addProperty("offset", begin);
jsonObject.addProperty("count", len); 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); WxOpenAuthorizerListResult ret = WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerListResult.class);
if (ret != null && ret.getList() != null) { if (ret != null && ret.getList() != null) {
for (Map<String, String> data : ret.getList()) { for (Map<String, String> data : ret.getList()) {
@@ -296,7 +296,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
jsonObject.addProperty("authorizer_appid", authorizerAppid); jsonObject.addProperty("authorizer_appid", authorizerAppid);
jsonObject.addProperty("option_name", optionName); 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); return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerOptionResult.class);
} }


@@ -307,7 +307,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
jsonObject.addProperty("authorizer_appid", authorizerAppid); jsonObject.addProperty("authorizer_appid", authorizerAppid);
jsonObject.addProperty("option_name", optionName); jsonObject.addProperty("option_name", optionName);
jsonObject.addProperty("option_value", optionValue); 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 @Override
@@ -402,14 +402,14 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
public void addToTemplate(long draftId) throws WxErrorException { public void addToTemplate(long draftId) throws WxErrorException {
JsonObject param = new JsonObject(); JsonObject param = new JsonObject();
param.addProperty("draft_id", draftId); param.addProperty("draft_id", draftId);
post(ADD_TO_TEMPLATE_URL, param, "access_token");
post(ADD_TO_TEMPLATE_URL, param.toString(), "access_token");
} }


@Override @Override
public void deleteTemplate(long templateId) throws WxErrorException { public void deleteTemplate(long templateId) throws WxErrorException {
JsonObject param = new JsonObject(); JsonObject param = new JsonObject();
param.addProperty("template_id", templateId); param.addProperty("template_id", templateId);
post(DELETE_TEMPLATE_URL, param, "access_token");
post(DELETE_TEMPLATE_URL, param.toString(), "access_token");
} }


@Override @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 { 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 { try {
if (method == RequestMethod.POST) { if (method == RequestMethod.POST) {
String uriWithComponentAccessToken = uri;
log.info("--------uri = "+uriWithComponentAccessToken);
log.info("--------postData = "+postData);
return getTtOpenService().post(uriWithComponentAccessToken, postData); return getTtOpenService().post(uriWithComponentAccessToken, postData);
}else { }else {
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + tokenKey + "=" + tokenValue;
return getTtOpenService().get(uriWithComponentAccessToken, null); return getTtOpenService().get(uriWithComponentAccessToken, null);
} }
} catch (WxErrorException e) { } catch (WxErrorException e) {
@@ -462,8 +458,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
if (isCompontAccessToken && this.getWxOpenConfigStorage().autoRefreshToken()) { if (isCompontAccessToken && this.getWxOpenConfigStorage().autoRefreshToken()) {
if (method == RequestMethod.POST) { 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 { }else {
return this.get(uri, tokenKey); return this.get(uri, tokenKey);
} }
@@ -521,7 +516,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat); jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat);
jsonObject.addProperty("legal_persona_name", legalPersonaName); jsonObject.addProperty("legal_persona_name", legalPersonaName);
jsonObject.addProperty("component_phone", componentPhone); 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); return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
} }


@@ -531,7 +526,7 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
jsonObject.addProperty("name", name); jsonObject.addProperty("name", name);
jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat); jsonObject.addProperty("legal_persona_wechat", legalPersonaWechat);
jsonObject.addProperty("legal_persona_name", legalPersonaName); 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); return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
} }
} }

Cargando…
Cancelar
Guardar