mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-25 01:14:36 +08:00
重构企业号代码
This commit is contained in:
parent
a90628c3b8
commit
6b1b7f1a81
@ -0,0 +1,57 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxCpDepartmentService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 创建部门
|
||||
* 最多支持创建500个部门
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
|
||||
* </pre>
|
||||
*
|
||||
* @param depart 部门
|
||||
* @return 部门id
|
||||
*/
|
||||
Integer create(WxCpDepart depart) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 查询所有部门
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
|
||||
* </pre>
|
||||
*/
|
||||
List<WxCpDepart> listAll() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 修改部门名
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
|
||||
* 如果id为0(未部门),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
|
||||
* </pre>
|
||||
*
|
||||
* @param group 要更新的group,group的id,name必须设置
|
||||
*/
|
||||
void update(WxCpDepart group) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 删除部门
|
||||
* </pre>
|
||||
*
|
||||
* @param departId 部门id
|
||||
*/
|
||||
void delete(Integer departId) throws WxErrorException;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxCpMediaService {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxCpMenuService {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxCpOauth2Service {
|
||||
}
|
@ -9,6 +9,7 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.cp.bean.*;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -33,16 +34,6 @@ public interface WxCpService {
|
||||
*/
|
||||
boolean checkSignature(String msgSignature, String timestamp, String nonce, String data);
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 用在二次验证的时候
|
||||
* 企业在员工验证成功后,调用本方法告诉企业号平台该员工关注成功。
|
||||
* </pre>
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
void userAuthenticated(String userId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取access_token, 不强制刷新access_token
|
||||
*
|
||||
@ -218,109 +209,77 @@ public interface WxCpService {
|
||||
WxMenu menuGet(Integer agentId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 创建部门
|
||||
* 最多支持创建500个部门
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
|
||||
* </pre>
|
||||
*
|
||||
* @param depart 部门
|
||||
* @return 部门id
|
||||
* @deprecated 请使用 {@link WxCpDepartmentService#create(WxCpDepart depart) }
|
||||
*/
|
||||
@Deprecated
|
||||
Integer departCreate(WxCpDepart depart) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 查询所有部门
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
|
||||
* </pre>
|
||||
*/
|
||||
List<WxCpDepart> departGet() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 修改部门名
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
|
||||
* 如果id为0(未部门),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
|
||||
* </pre>
|
||||
*
|
||||
* @param group 要更新的group,group的id,name必须设置
|
||||
* @deprecated 请使用 {@link WxCpDepartmentService#update(WxCpDepart group) }
|
||||
*/
|
||||
@Deprecated
|
||||
void departUpdate(WxCpDepart group) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口 - 删除部门
|
||||
* </pre>
|
||||
*
|
||||
* @param departId 部门id
|
||||
* @deprecated 请使用 {@link WxCpDepartmentService#delete(Integer departId) }
|
||||
*/
|
||||
@Deprecated
|
||||
void departDelete(Integer departId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取部门成员(详情)
|
||||
*
|
||||
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29
|
||||
* </pre>
|
||||
*
|
||||
* @param departId 必填。部门id
|
||||
* @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员
|
||||
* @param status 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
|
||||
* @deprecated 请使用 {@link WxCpDepartmentService#listAll() }
|
||||
*/
|
||||
List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
|
||||
@Deprecated
|
||||
List<WxCpDepart> departGet() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取部门成员
|
||||
*
|
||||
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98
|
||||
* </pre>
|
||||
*
|
||||
* @param departId 必填。部门id
|
||||
* @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员
|
||||
* @param status 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
|
||||
* @deprecated 请使用 {@link WxCpUserService#authenticate(String userId) }
|
||||
*/
|
||||
List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
|
||||
@Deprecated
|
||||
void userAuthenticated(String userId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 新建用户
|
||||
*
|
||||
* @param user 用户对象
|
||||
* @deprecated 请使用 {@link WxCpUserService#create(WxCpUser user) }
|
||||
*/
|
||||
@Deprecated
|
||||
void userCreate(WxCpUser user) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*
|
||||
* @param user 用户对象
|
||||
* @deprecated 请使用 {@link WxCpUserService#update(WxCpUser user)}
|
||||
*/
|
||||
@Deprecated
|
||||
void userUpdate(WxCpUser user) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param userid 用户id
|
||||
* @deprecated 请使用 {@link WxCpUserService#delete(String... userids) }
|
||||
*/
|
||||
@Deprecated
|
||||
void userDelete(String userid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 批量删除成员
|
||||
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98
|
||||
* </pre>
|
||||
*
|
||||
* @param userids 员工UserID列表。对应管理端的帐号
|
||||
* @deprecated 请使用 {@link WxCpUserService#delete(String[] userids) }
|
||||
*/
|
||||
@Deprecated
|
||||
void userDelete(String[] userids) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*
|
||||
* @param userid 用户id
|
||||
* @deprecated 请使用 {@link WxCpUserService#getById(String userid) }
|
||||
*/
|
||||
@Deprecated
|
||||
WxCpUser userGet(String userid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* @deprecated 请使用 {@link WxCpUserService#listByDepartment(Integer departId, Boolean fetchChild, Integer status) }
|
||||
*/
|
||||
@Deprecated
|
||||
List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* @deprecated 请使用 {@link WxCpUserService#listSimpleByDepartment(Integer departId, Boolean fetchChild, Integer status) }
|
||||
*/
|
||||
@Deprecated
|
||||
List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 创建标签
|
||||
*
|
||||
@ -560,4 +519,34 @@ public interface WxCpService {
|
||||
* @param wxConfigProvider 配置对象
|
||||
*/
|
||||
void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider);
|
||||
|
||||
/**
|
||||
* 获取部门相关接口的服务类对象
|
||||
*/
|
||||
WxCpDepartmentService getDepartmentService();
|
||||
|
||||
/**
|
||||
* 获取媒体相关接口的服务类对象
|
||||
*/
|
||||
WxCpMediaService getMediaService();
|
||||
|
||||
/**
|
||||
* 获取菜单相关接口的服务类对象
|
||||
*/
|
||||
WxCpMenuService getMenuService();
|
||||
|
||||
/**
|
||||
* 获取Oauth2相关接口的服务类对象
|
||||
*/
|
||||
WxCpOauth2Service getOauth2Service();
|
||||
|
||||
/**
|
||||
* 获取标签相关接口的服务类对象
|
||||
*/
|
||||
WxCpTagService getTagService();
|
||||
|
||||
/**
|
||||
* 获取用户相关接口的服务类对象
|
||||
*/
|
||||
WxCpUserService getUserService();
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxCpTagService {
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 用户管理接口
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxCpUserService {
|
||||
/**
|
||||
* <pre>
|
||||
* 用在二次验证的时候
|
||||
* 企业在员工验证成功后,调用本方法告诉企业号平台该员工关注成功。
|
||||
* </pre>
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
void authenticate(String userId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取部门成员(详情)
|
||||
*
|
||||
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29
|
||||
* </pre>
|
||||
*
|
||||
* @param departId 必填。部门id
|
||||
* @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员
|
||||
* @param status 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
|
||||
*/
|
||||
List<WxCpUser> listByDepartment(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取部门成员
|
||||
*
|
||||
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98
|
||||
* </pre>
|
||||
*
|
||||
* @param departId 必填。部门id
|
||||
* @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员
|
||||
* @param status 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
|
||||
*/
|
||||
List<WxCpUser> listSimpleByDepartment(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 新建用户
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
void create(WxCpUser user) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*
|
||||
* @param user 用户对象
|
||||
*/
|
||||
void update(WxCpUser user) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 删除用户/批量删除成员
|
||||
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98
|
||||
* </pre>
|
||||
*
|
||||
* @param userIds 员工UserID列表。对应管理端的帐号
|
||||
*/
|
||||
void delete(String... userIds) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*
|
||||
* @param userid 用户id
|
||||
*/
|
||||
WxCpUser getById(String userid) throws WxErrorException;
|
||||
}
|
@ -15,9 +15,9 @@ import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.fs.FileUtils;
|
||||
import me.chanjar.weixin.common.util.http.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.api.*;
|
||||
import me.chanjar.weixin.cp.bean.*;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@ -30,9 +30,15 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> {
|
||||
|
||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private WxCpUserService userService = new WxCpUserServiceImpl(this);
|
||||
private WxCpDepartmentService departmentService = new WxCpDepartmentServiceImpl(this);
|
||||
private WxCpMediaService mediaService;
|
||||
private WxCpMenuService menuService;
|
||||
private WxCpOauth2Service oauth2Service;
|
||||
private WxCpTagService tagService;
|
||||
|
||||
/**
|
||||
* 全局的是否正在刷新access token的锁
|
||||
*/
|
||||
@ -65,12 +71,6 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userAuthenticated(String userId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?userid=" + userId;
|
||||
get(url, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessToken() throws WxErrorException {
|
||||
return getAccessToken(false);
|
||||
@ -134,11 +134,13 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void menuCreate(WxMenu menu) throws WxErrorException {
|
||||
menuCreate(this.configStorage.getAgentId(), menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void menuCreate(Integer agentId, WxMenu menu) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid="
|
||||
+ agentId;
|
||||
@ -146,22 +148,26 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void menuDelete() throws WxErrorException {
|
||||
menuDelete(this.configStorage.getAgentId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void menuDelete(Integer agentId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=" + agentId;
|
||||
get(url, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxMenu menuGet() throws WxErrorException {
|
||||
return menuGet(this.configStorage.getAgentId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxMenu menuGet(Integer agentId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + agentId;
|
||||
try {
|
||||
@ -177,18 +183,21 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream)
|
||||
throws WxErrorException, IOException {
|
||||
return mediaUpload(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?type=" + mediaType;
|
||||
return execute(MediaUploadRequestExecutor.create(this), url, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public File mediaDownload(String mediaId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get";
|
||||
return execute(
|
||||
@ -197,130 +206,56 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
url, "media_id=" + mediaId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer departCreate(WxCpDepart depart) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
|
||||
String responseContent = execute(
|
||||
SimplePostRequestExecutor.create(this),
|
||||
url,
|
||||
depart.toJson());
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void departUpdate(WxCpDepart group) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
|
||||
post(url, group.toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void departDelete(Integer departId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=" + departId;
|
||||
get(url, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxCpDepart> departGet() throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
|
||||
String responseContent = get(url, null);
|
||||
/*
|
||||
* 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
|
||||
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
|
||||
*/
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return WxCpGsonBuilder.INSTANCE.create()
|
||||
.fromJson(
|
||||
tmpJsonElement.getAsJsonObject().get("department"),
|
||||
new TypeToken<List<WxCpDepart>>() {
|
||||
}.getType()
|
||||
);
|
||||
@Deprecated
|
||||
public void userAuthenticated(String userId) throws WxErrorException {
|
||||
this.getUserService().authenticate(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void userCreate(WxCpUser user) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/create";
|
||||
post(url, user.toJson());
|
||||
this.getUserService().create(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void userUpdate(WxCpUser user) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/update";
|
||||
post(url, user.toJson());
|
||||
this.getUserService().update(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void userDelete(String userid) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?userid=" + userid;
|
||||
get(url, null);
|
||||
this.getUserService().delete(userid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void userDelete(String[] userids) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String userid : userids) {
|
||||
jsonArray.add(new JsonPrimitive(userid));
|
||||
}
|
||||
jsonObject.add("useridlist", jsonArray);
|
||||
post(url, jsonObject.toString());
|
||||
this.getUserService().delete(userids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxCpUser userGet(String userid) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?userid=" + userid;
|
||||
String responseContent = get(url, null);
|
||||
return WxCpUser.fromJson(responseContent);
|
||||
return this.getUserService().getById(userid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
|
||||
String params = "";
|
||||
if (fetchChild != null) {
|
||||
params += "&fetch_child=" + (fetchChild ? "1" : "0");
|
||||
}
|
||||
if (status != null) {
|
||||
params += "&status=" + status;
|
||||
} else {
|
||||
params += "&status=0";
|
||||
}
|
||||
|
||||
String responseContent = get(url, params);
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return WxCpGsonBuilder.INSTANCE.create()
|
||||
.fromJson(tmpJsonElement.getAsJsonObject().get("userlist"),
|
||||
new TypeToken<List<WxCpUser>>() {
|
||||
}.getType()
|
||||
);
|
||||
return this.getUserService().listByDepartment(departId, fetchChild, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;
|
||||
String params = "";
|
||||
if (fetchChild != null) {
|
||||
params += "&fetch_child=" + (fetchChild ? "1" : "0");
|
||||
}
|
||||
if (status != null) {
|
||||
params += "&status=" + status;
|
||||
} else {
|
||||
params += "&status=0";
|
||||
}
|
||||
|
||||
String responseContent = get(url, params);
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return WxCpGsonBuilder.INSTANCE.create()
|
||||
.fromJson(
|
||||
tmpJsonElement.getAsJsonObject().get("userlist"),
|
||||
new TypeToken<List<WxCpUser>>() {
|
||||
}.getType()
|
||||
);
|
||||
return this.getUserService().listSimpleByDepartment(departId, fetchChild, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String tagCreate(String tagName) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/create";
|
||||
JsonObject o = new JsonObject();
|
||||
@ -331,6 +266,7 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void tagUpdate(String tagId, String tagName) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/update";
|
||||
JsonObject o = new JsonObject();
|
||||
@ -340,12 +276,14 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void tagDelete(String tagId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?tagid=" + tagId;
|
||||
get(url, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<WxCpTag> tagGet() throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/list";
|
||||
String responseContent = get(url, null);
|
||||
@ -359,6 +297,7 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<WxCpUser> tagGetUsers(String tagId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagid=" + tagId;
|
||||
String responseContent = get(url, null);
|
||||
@ -372,6 +311,7 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
@ -394,6 +334,7 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
@ -407,6 +348,7 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String oauth2buildAuthorizationUrl(String state) {
|
||||
return this.oauth2buildAuthorizationUrl(
|
||||
this.configStorage.getOauth2redirectUri(),
|
||||
@ -415,6 +357,7 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String oauth2buildAuthorizationUrl(String redirectUri, String state) {
|
||||
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
|
||||
url += "appid=" + this.configStorage.getCorpId();
|
||||
@ -429,11 +372,13 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] oauth2getUserInfo(String code) throws WxErrorException {
|
||||
return oauth2getUserInfo(this.configStorage.getAgentId(), code);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] oauth2getUserInfo(Integer agentId, String code) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?"
|
||||
+ "code=" + code
|
||||
@ -588,7 +533,6 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
return this.sessionManager.getSession(id, create);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setSessionManager(WxSessionManager sessionManager) {
|
||||
this.sessionManager = sessionManager;
|
||||
@ -624,4 +568,57 @@ public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, Requ
|
||||
this.tmpDirFile = tmpDirFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpDepartmentService getDepartmentService() {
|
||||
return departmentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpMediaService getMediaService() {
|
||||
return mediaService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpMenuService getMenuService() {
|
||||
return menuService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpOauth2Service getOauth2Service() {
|
||||
return oauth2Service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpTagService getTagService() {
|
||||
return tagService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpUserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Integer departCreate(WxCpDepart depart) throws WxErrorException {
|
||||
return this.getDepartmentService().create(depart);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void departUpdate(WxCpDepart depart) throws WxErrorException {
|
||||
this.getDepartmentService().update(depart);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void departDelete(Integer departId) throws WxErrorException {
|
||||
this.getDepartmentService().delete(departId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public List<WxCpDepart> departGet() throws WxErrorException {
|
||||
return this.getDepartmentService().listAll();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
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.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 部门管理接口
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
|
||||
private WxCpService mainService;
|
||||
|
||||
public WxCpDepartmentServiceImpl(WxCpService mainService) {
|
||||
this.mainService = mainService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer create(WxCpDepart depart) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
|
||||
String responseContent = this.mainService.post(url, depart.toJson());
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(WxCpDepart group) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
|
||||
this.mainService.post(url, group.toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Integer departId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=" + departId;
|
||||
this.mainService.get(url, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxCpDepart> listAll() throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
|
||||
String responseContent = this.mainService.get(url, null);
|
||||
/*
|
||||
* 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
|
||||
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
|
||||
*/
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return WxCpGsonBuilder.INSTANCE.create()
|
||||
.fromJson(tmpJsonElement.getAsJsonObject().get("department"),
|
||||
new TypeToken<List<WxCpDepart>>() {
|
||||
}.getType()
|
||||
);
|
||||
}
|
||||
}
|
@ -7,8 +7,8 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.HttpType;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.impl.AbstractWxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
@ -17,6 +17,7 @@ import org.apache.http.impl.client.BasicResponseHandler;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class WxCpServiceApacheHttpClientImpl extends AbstractWxCpServiceImpl<CloseableHttpClient, HttpHost> {
|
||||
protected CloseableHttpClient httpClient;
|
||||
|
@ -5,8 +5,7 @@ import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.HttpType;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.impl.AbstractWxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
|
||||
public class WxCpServiceJoddHttpImpl extends AbstractWxCpServiceImpl<HttpConnectionProvider, ProxyInfo> {
|
||||
protected HttpConnectionProvider httpClient;
|
||||
|
@ -5,8 +5,7 @@ import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.HttpType;
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.impl.AbstractWxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -0,0 +1,118 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.api.WxCpUserService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxCpUserServiceImpl implements WxCpUserService {
|
||||
private WxCpService mainService;
|
||||
|
||||
public WxCpUserServiceImpl(WxCpService mainService) {
|
||||
this.mainService = mainService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticate(String userId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?userid=" + userId;
|
||||
this.mainService.get(url, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(WxCpUser user) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/create";
|
||||
this.mainService.post(url, user.toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(WxCpUser user) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/update";
|
||||
this.mainService.post(url, user.toJson());
|
||||
}
|
||||
|
||||
public void deleteOne(String userId) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?userid=" + userId;
|
||||
this.mainService.get(url, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String... userIds) throws WxErrorException {
|
||||
if (userIds.length == 1) {
|
||||
this.deleteOne(userIds[0]);
|
||||
}
|
||||
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String userid : userIds) {
|
||||
jsonArray.add(new JsonPrimitive(userid));
|
||||
}
|
||||
jsonObject.add("useridlist", jsonArray);
|
||||
this.mainService.post(url, jsonObject.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpUser getById(String userid) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?userid=" + userid;
|
||||
String responseContent = this.mainService.get(url, null);
|
||||
return WxCpUser.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxCpUser> listByDepartment(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
|
||||
String params = "";
|
||||
if (fetchChild != null) {
|
||||
params += "&fetch_child=" + (fetchChild ? "1" : "0");
|
||||
}
|
||||
if (status != null) {
|
||||
params += "&status=" + status;
|
||||
} else {
|
||||
params += "&status=0";
|
||||
}
|
||||
|
||||
String responseContent = this.mainService.get(url, params);
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return WxCpGsonBuilder.INSTANCE.create()
|
||||
.fromJson(tmpJsonElement.getAsJsonObject().get("userlist"),
|
||||
new TypeToken<List<WxCpUser>>() {
|
||||
}.getType()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxCpUser> listSimpleByDepartment(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;
|
||||
String params = "";
|
||||
if (fetchChild != null) {
|
||||
params += "&fetch_child=" + (fetchChild ? "1" : "0");
|
||||
}
|
||||
if (status != null) {
|
||||
params += "&status=" + status;
|
||||
} else {
|
||||
params += "&status=0";
|
||||
}
|
||||
|
||||
String responseContent = this.mainService.get(url, params);
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return WxCpGsonBuilder.INSTANCE.create()
|
||||
.fromJson(
|
||||
tmpJsonElement.getAsJsonObject().get("userlist"),
|
||||
new TypeToken<List<WxCpUser>>() {
|
||||
}.getType()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ package me.chanjar.weixin.cp.bean;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
|
||||
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
@ -3,7 +3,7 @@ package me.chanjar.weixin.cp.bean;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.bean.outxmlbuilder.*;
|
||||
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
|
||||
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
|
||||
|
@ -22,7 +22,7 @@
|
||||
package me.chanjar.weixin.cp.util.crypto;
|
||||
|
||||
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
public class WxCpCryptUtil extends WxCryptUtil {
|
||||
|
@ -6,6 +6,8 @@ import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -25,10 +27,10 @@ public class ApiTestModule implements Module {
|
||||
.getSystemResourceAsStream("test-config.xml")) {
|
||||
WxXmlCpInMemoryConfigStorage config = fromXml(
|
||||
WxXmlCpInMemoryConfigStorage.class, is1);
|
||||
WxCpServiceImpl wxService = new WxCpServiceImpl();
|
||||
WxCpService wxService = new WxCpServiceImpl();
|
||||
wxService.setWxCpConfigStorage(config);
|
||||
|
||||
binder.bind(WxCpServiceImpl.class).toInstance(wxService);
|
||||
binder.bind(WxCpService.class).toInstance(wxService);
|
||||
binder.bind(WxCpConfigStorage.class).toInstance(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.api;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
|
@ -3,6 +3,9 @@ package me.chanjar.weixin.cp.api;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.session.StandardSessionManager;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.cp.message.WxCpMessageHandler;
|
||||
import me.chanjar.weixin.cp.message.WxCpMessageMatcher;
|
||||
import me.chanjar.weixin.cp.message.WxCpMessageRouter;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
|
||||
import org.testng.Assert;
|
||||
|
@ -4,6 +4,7 @@ import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -1,76 +0,0 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
|
||||
/**
|
||||
* 测试用户接口
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
@Test(groups = "userAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxCpUserAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxCpServiceImpl wxCpService;
|
||||
|
||||
public void testUserCreate() throws WxErrorException {
|
||||
WxCpUser user = new WxCpUser();
|
||||
user.setUserId("some.woman");
|
||||
user.setName("Some Woman");
|
||||
user.setDepartIds(new Integer[]{9, 8});
|
||||
user.setEmail("none@none.com");
|
||||
user.setGender("女");
|
||||
user.setMobile("13560084979");
|
||||
user.setPosition("woman");
|
||||
user.setTelephone("3300393");
|
||||
user.addExtAttr("爱好", "table");
|
||||
this.wxCpService.userCreate(user);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUserCreate")
|
||||
public void testUserUpdate() throws WxErrorException {
|
||||
WxCpUser user = new WxCpUser();
|
||||
user.setUserId("some.woman");
|
||||
user.setName("Some Woman");
|
||||
user.addExtAttr("爱好", "table2");
|
||||
this.wxCpService.userUpdate(user);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUserUpdate")
|
||||
public void testUserGet() throws WxErrorException {
|
||||
WxCpUser user = this.wxCpService.userGet("some.woman");
|
||||
Assert.assertNotNull(user);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUserGet")
|
||||
public void testDepartGetUsers() throws WxErrorException {
|
||||
List<WxCpUser> users = this.wxCpService.departGetUsers(1, true, 0);
|
||||
assertNotEquals(users.size(), 0);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testDepartGetUsers")
|
||||
public void testUserDelete() throws WxErrorException {
|
||||
this.wxCpService.userDelete("some.woman");
|
||||
}
|
||||
|
||||
public void testUserList() throws WxErrorException {
|
||||
List<WxCpUser> users = this.wxCpService.userList(1, true, 0);
|
||||
assertNotEquals(users.size(), 0);
|
||||
for (WxCpUser user : users) {
|
||||
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxCpDepartmentServiceImplTest {
|
||||
@Inject
|
||||
private WxCpService wxCpService;
|
||||
|
||||
private WxCpDepart depart;
|
||||
|
||||
@Test
|
||||
public void testCreate() throws Exception {
|
||||
WxCpDepart cpDepart = new WxCpDepart();
|
||||
cpDepart.setName("子部门" + System.currentTimeMillis());
|
||||
cpDepart.setParentId(1);
|
||||
cpDepart.setOrder(1);
|
||||
Integer departId = this.wxCpService.getDepartmentService().create(cpDepart);
|
||||
System.out.println(departId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAll() throws Exception {
|
||||
System.out.println("=================获取部门");
|
||||
List<WxCpDepart> departList = this.wxCpService.getDepartmentService().listAll();
|
||||
assertNotNull(departList);
|
||||
assertTrue(departList.size() > 0);
|
||||
for (WxCpDepart g : departList) {
|
||||
this.depart = g;
|
||||
System.out.println(this.depart.getId() + ":" + this.depart.getName());
|
||||
assertNotNull(g.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testListAll", "testCreate"})
|
||||
public void testUpdate() throws Exception {
|
||||
System.out.println("=================更新部门");
|
||||
this.depart.setName("子部门改名" + System.currentTimeMillis());
|
||||
this.wxCpService.getDepartmentService().update(this.depart);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUpdate")
|
||||
public void testDelete() throws Exception {
|
||||
System.out.println("=================删除部门");
|
||||
System.out.println(this.depart.getId() + ":" + this.depart.getName());
|
||||
this.wxCpService.getDepartmentService().delete(this.depart.getId());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.cp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxCpUserServiceImplTest {
|
||||
@Inject
|
||||
private WxCpService wxCpService;
|
||||
|
||||
@Test
|
||||
public void testAuthenticate() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() throws Exception {
|
||||
WxCpUser user = new WxCpUser();
|
||||
user.setUserId("some.woman");
|
||||
user.setName("Some Woman");
|
||||
user.setDepartIds(new Integer[]{9, 8});
|
||||
user.setEmail("none@none.com");
|
||||
user.setGender("女");
|
||||
user.setMobile("13560084979");
|
||||
user.setPosition("woman");
|
||||
user.setTelephone("3300393");
|
||||
user.addExtAttr("爱好", "table");
|
||||
this.wxCpService.getUserService().create(user);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreate")
|
||||
public void testUpdate() throws Exception {
|
||||
WxCpUser user = new WxCpUser();
|
||||
user.setUserId("some.woman");
|
||||
user.setName("Some Woman");
|
||||
user.addExtAttr("爱好", "table2");
|
||||
this.wxCpService.getUserService().update(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() throws Exception {
|
||||
this.wxCpService.getUserService().delete("some.woman");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUpdate")
|
||||
public void testGetById() throws Exception {
|
||||
WxCpUser user = this.wxCpService.getUserService().getById("some.woman");
|
||||
assertNotNull(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListByDepartment() throws Exception {
|
||||
List<WxCpUser> users = this.wxCpService.getUserService().listByDepartment(1, true, 0);
|
||||
assertNotEquals(users.size(), 0);
|
||||
for (WxCpUser user : users) {
|
||||
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListSimpleByDepartment() throws Exception {
|
||||
List<WxCpUser> users = this.wxCpService.getUserService().listSimpleByDepartment(1, true, 0);
|
||||
assertNotEquals(users.size(), 0);
|
||||
for (WxCpUser user : users) {
|
||||
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ package me.chanjar.weixin.cp.demo;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.cp.api.WxCpInMemoryConfigStorage;
|
||||
import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package me.chanjar.weixin.cp.demo;
|
||||
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.WxCpMessageHandler;
|
||||
import me.chanjar.weixin.cp.api.WxCpMessageRouter;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.message.WxCpMessageHandler;
|
||||
import me.chanjar.weixin.cp.message.WxCpMessageRouter;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.demo;
|
||||
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.WxCpMessageRouter;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.message.WxCpMessageRouter;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
|
||||
|
Loading…
Reference in New Issue
Block a user