mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 22:11:40 +08:00
#1081 开放平台模块增加获取所有授权方列表的接口
This commit is contained in:
parent
90b5ca56c2
commit
18e3f75028
@ -7,10 +7,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||
import me.chanjar.weixin.open.bean.WxOpenCreateResult;
|
||||
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
|
||||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenResult;
|
||||
import me.chanjar.weixin.open.bean.result.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -25,6 +22,7 @@ public interface WxOpenComponentService {
|
||||
String API_GET_AUTHORIZER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info";
|
||||
String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option";
|
||||
String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option";
|
||||
String API_GET_AUTHORIZER_LIST = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list?component_access_token=%s";
|
||||
|
||||
String COMPONENT_LOGIN_PAGE_URL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s&auth_type=xxx&biz_appid=xxx";
|
||||
|
||||
@ -126,6 +124,11 @@ public interface WxOpenComponentService {
|
||||
*/
|
||||
WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取所有授权方列表
|
||||
*/
|
||||
WxOpenAuthorizerListResult getAuthorizerList(int begin, int len) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 设置授权方的选项信息
|
||||
*/
|
||||
|
@ -18,10 +18,7 @@ import me.chanjar.weixin.open.bean.WxOpenCreateResult;
|
||||
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
|
||||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo;
|
||||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenResult;
|
||||
import me.chanjar.weixin.open.bean.result.*;
|
||||
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@ -304,6 +301,21 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
|
||||
return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerInfoResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxOpenAuthorizerListResult getAuthorizerList(int begin, int len) throws WxErrorException {
|
||||
|
||||
String url = String.format(API_GET_AUTHORIZER_LIST, getComponentAccessToken(false));
|
||||
begin = begin < 0 ? 0 : begin;
|
||||
len = len == 0 ? 10 : len;
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
|
||||
jsonObject.addProperty("offset", begin);
|
||||
jsonObject.addProperty("count", len);
|
||||
String responseContent = post(url, jsonObject.toString());
|
||||
return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerListResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
@ -0,0 +1,15 @@
|
||||
package me.chanjar.weixin.open.bean.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author robgao
|
||||
*/
|
||||
@Data
|
||||
public class WxOpenAuthorizerListResult {
|
||||
private int totalCount;
|
||||
private List<Map<String,String>> list;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package me.chanjar.weixin.open.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerListResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author robgao
|
||||
* @Email 315789501@qq.com
|
||||
*/
|
||||
public class WxOpenAuthorizerListResultGsonAdapter implements JsonDeserializer<WxOpenAuthorizerListResult> {
|
||||
|
||||
private static final String AUTHORIZER_APPID="authorizer_appid";
|
||||
private static final String REFRESH_TOKEN="refresh_token";
|
||||
private static final String AUTH_TIME="auth_time";
|
||||
@Override
|
||||
public WxOpenAuthorizerListResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
|
||||
WxOpenAuthorizerListResult wxOpenAuthorizerListResult= new WxOpenAuthorizerListResult();
|
||||
wxOpenAuthorizerListResult.setTotalCount(GsonHelper.getInteger(jsonObject, "total_count").intValue());
|
||||
|
||||
List<Map<String,String>> list = new ArrayList<>();
|
||||
Iterator<JsonElement> jsonElementIterator = jsonObject.getAsJsonArray("list").iterator();
|
||||
|
||||
while(jsonElementIterator.hasNext()){
|
||||
JsonObject authorizer = jsonElementIterator.next().getAsJsonObject();
|
||||
Map<String,String> authorizerMap = new HashMap<>(10);
|
||||
|
||||
authorizerMap.put(AUTHORIZER_APPID, GsonHelper.getString(authorizer,AUTHORIZER_APPID));
|
||||
authorizerMap.put(REFRESH_TOKEN, GsonHelper.getString(authorizer,REFRESH_TOKEN));
|
||||
authorizerMap.put(AUTH_TIME, GsonHelper.getString(authorizer,AUTH_TIME));
|
||||
list.add(authorizerMap);
|
||||
}
|
||||
wxOpenAuthorizerListResult.setList(list);
|
||||
return wxOpenAuthorizerListResult;
|
||||
}
|
||||
}
|
@ -6,10 +6,7 @@ import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
|
||||
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
|
||||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo;
|
||||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo;
|
||||
import me.chanjar.weixin.open.bean.result.WxFastMaAccountBasicInfoResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult;
|
||||
import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult;
|
||||
import me.chanjar.weixin.open.bean.result.*;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
@ -27,8 +24,8 @@ public class WxOpenGsonBuilder {
|
||||
INSTANCE.registerTypeAdapter(WxOpenQueryAuthResult.class, new WxOpenQueryAuthResultGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxOpenAuthorizerInfoResult.class, new WxOpenAuthorizerInfoResultGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxOpenAuthorizerOptionResult.class, new WxOpenAuthorizerOptionResultGsonAdapter());
|
||||
|
||||
INSTANCE.registerTypeAdapter(WxFastMaAccountBasicInfoResult.class, new WxFastMaAccountBasicInfoGsonAdapter ());
|
||||
INSTANCE.registerTypeAdapter(WxOpenAuthorizerListResult.class, new WxOpenAuthorizerListResultGsonAdapter ());
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user