#536 企业号模块增加获取企业号应用相关接口
* 定义《企业号应用》的bean * 增加《获取企业号应用》接口实现 * 增加获取测试企业号应用信息测试类
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpAgent;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 管理企业号应用
|
||||
* Created by huansinho on 2018/4/13.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/huansinho">huansinho</a>
|
||||
*/
|
||||
public interface WxCpAgentService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取企业号应用信息
|
||||
* 该API用于获取企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息
|
||||
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=获取企业号应用
|
||||
* </pre>
|
||||
*
|
||||
* @param agentId 企业应用的id
|
||||
* @return 部门id
|
||||
*/
|
||||
WxCpAgent get(Integer agentId) throws WxErrorException;
|
||||
|
||||
}
|
||||
@@ -249,6 +249,8 @@ public interface WxCpService {
|
||||
*/
|
||||
WxCpUserService getUserService();
|
||||
|
||||
WxCpAgentService getAgentService();
|
||||
|
||||
/**
|
||||
* http请求对象
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpAgentService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpAgent;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 管理企业号应用
|
||||
* Created by huansinho on 2018/4/13.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/huansinho">huansinho</a>
|
||||
*/
|
||||
public class WxCpAgentServiceImpl implements WxCpAgentService {
|
||||
private WxCpService mainService;
|
||||
|
||||
public WxCpAgentServiceImpl(WxCpService mainService) {
|
||||
this.mainService = mainService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpAgent get(Integer agentId) throws WxErrorException {
|
||||
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/agent/get";
|
||||
if (agentId != null) {
|
||||
url += "?agentid=" + agentId;
|
||||
} else {
|
||||
throw new IllegalArgumentException("缺少agentid参数");
|
||||
}
|
||||
String responseContent = this.mainService.get(url, null);
|
||||
return WxCpAgent.fromJson(responseContent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,6 +39,7 @@ public abstract class WxCpServiceAbstractImpl<H, P> implements WxCpService, Requ
|
||||
private WxCpMenuService menuService = new WxCpMenuServiceImpl(this);
|
||||
private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this);
|
||||
private WxCpTagService tagService = new WxCpTagServiceImpl(this);
|
||||
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
|
||||
|
||||
/**
|
||||
* 全局的是否正在刷新access token的锁
|
||||
@@ -368,4 +369,13 @@ public abstract class WxCpServiceAbstractImpl<H, P> implements WxCpService, Requ
|
||||
public void setTagService(WxCpTagService tagService) {
|
||||
this.tagService = tagService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpAgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
public void setAgentService(WxCpAgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 企业号应用信息.
|
||||
* Created by huansinho on 2018/4/13.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/huansinho">huansinho</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxCpAgent implements Serializable {
|
||||
|
||||
@SerializedName("errcode")
|
||||
private Integer errcode;
|
||||
|
||||
@SerializedName("errmsg")
|
||||
private String errmsg;
|
||||
|
||||
@SerializedName("agentid")
|
||||
private Integer agentid;
|
||||
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
|
||||
@SerializedName("square_logo_url")
|
||||
private String squareLogoUrl;
|
||||
|
||||
@SerializedName("description")
|
||||
private String description;
|
||||
|
||||
@SerializedName("allow_userinfos")
|
||||
private Users allowUserinfos;
|
||||
|
||||
@SerializedName("allow_partys")
|
||||
private Partys allowPartys;
|
||||
|
||||
@SerializedName("allow_tags")
|
||||
private Tags allowTags;
|
||||
|
||||
@SerializedName("close")
|
||||
private Integer close;
|
||||
|
||||
@SerializedName("redirect_domain")
|
||||
private String redirectDomain;
|
||||
|
||||
@SerializedName("report_location_flag")
|
||||
private Integer reportLocationFlag;
|
||||
|
||||
@SerializedName("isreportenter")
|
||||
private Integer isreportenter;
|
||||
|
||||
@SerializedName("home_url")
|
||||
private String homeUrl;
|
||||
|
||||
public static WxCpAgent fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpAgent.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Users implements Serializable {
|
||||
@SerializedName("user")
|
||||
private List<User> user;
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public class User implements Serializable {
|
||||
@SerializedName("userid")
|
||||
private String userid;
|
||||
}
|
||||
|
||||
@Data
|
||||
public class Partys {
|
||||
@SerializedName("partyid")
|
||||
private List<Integer> partyids = null;
|
||||
}
|
||||
|
||||
@Data
|
||||
public class Tags {
|
||||
@SerializedName("tagid")
|
||||
private List<Integer> tagids = null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user