企业号:增加用户进入应用的callback事件&增加批量获取用户详情的接口

This commit is contained in:
jy.hu 2014-12-28 15:46:58 +08:00
parent 96b3080c2d
commit 3f4c174580
24 changed files with 143 additions and 37 deletions

View File

@ -197,6 +197,12 @@ netty的代码没有放到maven中心仓库,也没什么意义,因为最终需
+ clear code with findbugs plugin + clear code with findbugs plugin
+ change the version to 1.1 + change the version to 1.1
* 2014-12-28
+ **weixin4j-qy**:增加用户进入应用的callback事件
+ **weixin4j-qy**:增加批量获取用户详情的接口
接下来 接下来
------ ------

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j</artifactId> <artifactId>weixin4j</artifactId>
<version>1.1</version> <version>1.2-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>weixin4j</name> <name>weixin4j</name>
<url>https://github.com/foxinmy/weixin4j</url> <url>https://github.com/foxinmy/weixin4j</url>

View File

@ -1,11 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j</artifactId> <artifactId>weixin4j</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>weixin4j-base</artifactId> <artifactId>weixin4j-base</artifactId>
<name>weixin4j-base</name> <name>weixin4j-base</name>

View File

@ -34,7 +34,7 @@ public class BaseMsg implements Serializable {
} }
public BaseMsg(String msgType) { public BaseMsg(String msgType) {
this(msgType, null, null); this.msgType = msgType;
} }
public BaseMsg(String toUserName, String fromUserName) { public BaseMsg(String toUserName, String fromUserName) {

View File

@ -0,0 +1,37 @@
package com.foxinmy.weixin4j.msg.event;
import com.foxinmy.weixin4j.type.EventType;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/**
* 用户进入应用的事件推送(企业号)本事件只有在应用的回调模式中打开上报开关时上报
*
* @className EnterAgentEventMessage
* @author jy
* @date 2014年12月28日
* @since JDK 1.7
* @see<a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E4%BA%8B%E4%BB%B6#.E7.94.A8.E6.88.B7.E8.BF.9B.E5.85.A5.E5.BA.94.E7.94.A8.E7.9A.84.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81"
* >用户进入应用的事件推送</a>
*/
public class EnterAgentEventMessage extends EventMessage {
private static final long serialVersionUID = 7675732524832500820L;
public EnterAgentEventMessage() {
super(EventType.enter_agent);
}
@XStreamAlias("EventKey")
private String eventKey; // 事件KEY值与自定义菜单接口中KEY值对应
public String getEventKey() {
return eventKey;
}
@Override
public String toString() {
return "EnterAgentEventMessage [eventKey=" + eventKey + ", "
+ super.toString() + "]";
}
}

View File

@ -4,7 +4,7 @@ import com.foxinmy.weixin4j.type.EventType;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* 模板消息事件推送 * 模板消息事件推送(公众平台)
* *
* @className TemplatesendjobfinishMessage * @className TemplatesendjobfinishMessage
* @author jy * @author jy

View File

@ -37,6 +37,7 @@ public class MenuEventMessage extends EventMessage {
@Override @Override
public String toString() { public String toString() {
return "eventKey=" + eventKey + ", " + super.toString(); return "MenuEventMessage [eventKey=" + eventKey + ", "
+ super.toString() + "]";
} }
} }

View File

@ -8,6 +8,7 @@ import com.foxinmy.weixin4j.msg.model.Base;
import com.foxinmy.weixin4j.msg.model.News; import com.foxinmy.weixin4j.msg.model.News;
import com.foxinmy.weixin4j.msg.model.Responseable; import com.foxinmy.weixin4j.msg.model.Responseable;
import com.foxinmy.weixin4j.util.ClassUtil; import com.foxinmy.weixin4j.util.ClassUtil;
import com.foxinmy.weixin4j.xml.TextConverter;
import com.foxinmy.weixin4j.xml.XmlStream; import com.foxinmy.weixin4j.xml.XmlStream;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
@ -107,10 +108,7 @@ public class ResponseMessage extends BaseMsg {
@Override @Override
public String toString() { public String toString() {
return "ResponseMessage [" + box.toString() + ", attach=" + attach return "ResponseMessage [ " + super.toString() + ", attach=" + attach
+ ", getToUserName()=" + getToUserName() + ", box=" + box + "]";
+ ", getFromUserName()=" + getFromUserName()
+ ", getCreateTime()=" + getCreateTime() + ", getMsgType()="
+ getMsgType() + "]";
} }
} }

View File

@ -1,5 +1,6 @@
package com.foxinmy.weixin4j.type; package com.foxinmy.weixin4j.type;
import com.foxinmy.weixin4j.msg.event.EnterAgentEventMessage;
import com.foxinmy.weixin4j.msg.event.EventMessage; import com.foxinmy.weixin4j.msg.event.EventMessage;
import com.foxinmy.weixin4j.msg.event.LocationEventMessage; import com.foxinmy.weixin4j.msg.event.LocationEventMessage;
import com.foxinmy.weixin4j.msg.event.MassEventMessage; import com.foxinmy.weixin4j.msg.event.MassEventMessage;
@ -31,7 +32,7 @@ public enum EventType {
MenuLocationEventMessage.class), click(MenuEventMessage.class), location( MenuLocationEventMessage.class), click(MenuEventMessage.class), location(
LocationEventMessage.class),masssendjobfinish( LocationEventMessage.class),masssendjobfinish(
MassEventMessage.class), templatesendjobfinish( MassEventMessage.class), templatesendjobfinish(
TemplatesendjobfinishMessage.class); TemplatesendjobfinishMessage.class),enter_agent(EnterAgentEventMessage.class);
private Class<? extends EventMessage> eventClass; private Class<? extends EventMessage> eventClass;

View File

@ -1,4 +1,4 @@
package com.foxinmy.weixin4j.response; package com.foxinmy.weixin4j.xml;
import com.foxinmy.weixin4j.msg.model.Text; import com.foxinmy.weixin4j.msg.model.Text;
import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.SingleValueConverter;

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j</artifactId> <artifactId>weixin4j</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>weixin4j-mp</artifactId> <artifactId>weixin4j-mp</artifactId>
<name>weixin4j-mp</name> <name>weixin4j-mp</name>

View File

@ -1,11 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j-mp</artifactId> <artifactId>weixin4j-mp</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>weixin4j-mp-api</artifactId> <artifactId>weixin4j-mp-api</artifactId>
<name>weixin4j-mp-api</name> <name>weixin4j-mp-api</name>

View File

@ -1,11 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j-mp</artifactId> <artifactId>weixin4j-mp</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>weixin4j-mp-server</artifactId> <artifactId>weixin4j-mp-server</artifactId>
<name>weixin4j-mp-server</name> <name>weixin4j-mp-server</name>

View File

@ -88,3 +88,9 @@ weixin4j-qy
* 2014-11-24 * 2014-11-24
+ **weixin4j-qy-server**: 新增netty服务与消息分发 + **weixin4j-qy-server**: 新增netty服务与消息分发
* 2014-12-28
+ **weixin4j-qy**:增加用户进入应用的callback事件
+ **weixin4j-qy**:增加批量获取用户详情的接口

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j</artifactId> <artifactId>weixin4j</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>weixin4j-qy</artifactId> <artifactId>weixin4j-qy</artifactId>
<name>weixin4j-qy</name> <name>weixin4j-qy</name>

View File

@ -57,3 +57,7 @@ weixin.properties说明
+ 新增`用户管理`接口 + 新增`用户管理`接口
+ 新增`标签管理`接口 + 新增`标签管理`接口
* 2014-12-28
+ 增加`批量获取用户详情`的接口

View File

@ -1,11 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j-qy</artifactId> <artifactId>weixin4j-qy</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>weixin4j-qy-api</artifactId> <artifactId>weixin4j-qy-api</artifactId>
<name>weixin4j-qy-api</name> <name>weixin4j-qy-api</name>

View File

@ -185,6 +185,8 @@ public class WeixinProxy {
* 是否递归获取子部门下面的成员 非必须 * 是否递归获取子部门下面的成员 非必须
* @param userStatus * @param userStatus
* 成员状态 status可叠加 非必须 * 成员状态 status可叠加 非必须
* @param findDetail
* 是否获取详细信息
* @see com.foxinmy.weixin4j.qy.model.User * @see com.foxinmy.weixin4j.qy.model.User
* @see <a * @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98">获取部门成员说明</a> * href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98">获取部门成员说明</a>
@ -193,8 +195,8 @@ public class WeixinProxy {
* @throws WeixinException * @throws WeixinException
*/ */
public List<User> listUser(int departId, boolean fetchChild, public List<User> listUser(int departId, boolean fetchChild,
UserStatus userStatus) throws WeixinException { UserStatus userStatus, boolean findDetail) throws WeixinException {
return userApi.listUser(departId, fetchChild, userStatus); return userApi.listUser(departId, fetchChild, userStatus, findDetail);
} }
/** /**
@ -244,7 +246,8 @@ public class WeixinProxy {
/** /**
* 更新标签(管理组必须是指定标签的创建者) * 更新标签(管理组必须是指定标签的创建者)
* *
* @param tag 标签信息 * @param tag
* 标签信息
* @see <a href= * @see <a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E6.9B.B4.E6.96.B0.E6.A0.87.E7.AD.BE.E5.90.8D.E5.AD.97" * "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E6.9B.B4.E6.96.B0.E6.A0.87.E7.AD.BE.E5.90.8D.E5.AD.97"
* >更新标签说明</a> * >更新标签说明</a>

View File

@ -1,8 +1,10 @@
package com.foxinmy.weixin4j.qy.api; package com.foxinmy.weixin4j.qy.api;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException; import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.JsonResult; import com.foxinmy.weixin4j.http.JsonResult;
@ -132,6 +134,8 @@ public class UserApi extends QyApi {
* 是否递归获取子部门下面的成员 非必须 * 是否递归获取子部门下面的成员 非必须
* @param userStatus * @param userStatus
* 成员状态 status可叠加 非必须 * 成员状态 status可叠加 非必须
* @param findDetail
* 是否获取详细信息
* @see com.foxinmy.weixin4j.qy.model.User * @see com.foxinmy.weixin4j.qy.model.User
* @see <a * @see <a
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98">获取部门成员说明</a> * href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98">获取部门成员说明</a>
@ -139,14 +143,30 @@ public class UserApi extends QyApi {
* @throws WeixinException * @throws WeixinException
*/ */
public List<User> listUser(int departId, boolean fetchChild, public List<User> listUser(int departId, boolean fetchChild,
UserStatus userStatus) throws WeixinException { UserStatus userStatus, boolean findDetail) throws WeixinException {
String user_list_uri = getRequestUri("user_list_uri"); String user_list_uri = findDetail ? getRequestUri("user_list_uri")
: getRequestUri("user_slist_uri");
Token token = tokenHolder.getToken(); Token token = tokenHolder.getToken();
Response response = request.post(String.format(user_list_uri, Response response = request.post(String.format(user_list_uri,
token.getAccessToken(), departId, fetchChild ? 1 : 0, token.getAccessToken(), departId, fetchChild ? 1 : 0,
userStatus.getVal())); userStatus.getVal()));
return JSON.parseArray(response.getAsJson().getString("userlist"), List<User> list = null;
User.class); if (findDetail) {
JSONArray arrays = response.getAsJson().getJSONArray("userlist");
list = new ArrayList<User>(arrays.size());
for (int i = 0; i < arrays.size(); i++) {
JSONObject obj = arrays.getJSONObject(i);
Object attrs = obj.getJSONObject("extattr").remove("attrs");
if (attrs != null) {
obj.put("extattr", attrs);
}
list.add(JSON.toJavaObject(obj, User.class));
}
} else {
list = JSON.parseArray(response.getAsJson().getString("userlist"),
User.class);
}
return list;
} }
/** /**
@ -159,7 +179,7 @@ public class UserApi extends QyApi {
* @throws WeixinException * @throws WeixinException
*/ */
public List<User> listUser(int departId) throws WeixinException { public List<User> listUser(int departId) throws WeixinException {
return listUser(departId, false, UserStatus.BOTH); return listUser(departId, false, UserStatus.BOTH, false);
} }
/** /**

View File

@ -22,7 +22,9 @@ user_get_uri={api_base_url}/user/get?access_token=%s&userid=%s
# code\u83b7\u53d6\u6210\u5458\u4fe1\u606f # code\u83b7\u53d6\u6210\u5458\u4fe1\u606f
user_getid_uri={api_base_url}/getuserinfo?access_token=%s&code=%s&agentid=%d user_getid_uri={api_base_url}/getuserinfo?access_token=%s&code=%s&agentid=%d
# \u83b7\u53d6\u90e8\u95e8\u6210\u5458 # \u83b7\u53d6\u90e8\u95e8\u6210\u5458
user_list_uri={api_base_url}/user/simplelist?access_token=%s&department_id=%d&fetch_child=%d&status=%d user_slist_uri={api_base_url}/user/simplelist?access_token=%s&department_id=%d&fetch_child=%d&status=%d
# \u83b7\u53d6\u90e8\u95e8\u6210\u5458(\u8be6\u60c5)
user_list_uri={api_base_url}/user/list?access_token=%s&department_id=%d&fetch_child=%d&status=%d
# \u5220\u9664\u6210\u5458 # \u5220\u9664\u6210\u5458
user_delete_uri={api_base_url}/user/delete?access_token=%s&userid=%s user_delete_uri={api_base_url}/user/delete?access_token=%s&userid=%s
# \u6210\u5458\u4e8c\u6b21\u9a8c\u8bc1\u6210\u529f\u65f6\u8c03\u7528 # \u6210\u5458\u4e8c\u6b21\u9a8c\u8bc1\u6210\u529f\u65f6\u8c03\u7528

View File

@ -10,6 +10,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.JsonResult; import com.foxinmy.weixin4j.http.JsonResult;
import com.foxinmy.weixin4j.qy.api.UserApi; import com.foxinmy.weixin4j.qy.api.UserApi;
import com.foxinmy.weixin4j.qy.model.User; import com.foxinmy.weixin4j.qy.model.User;
import com.foxinmy.weixin4j.qy.type.UserStatus;
/** /**
* 部门API测试 * 部门API测试
@ -57,7 +58,10 @@ public class UserTest extends TokenTest {
@Test @Test
public void list() throws WeixinException { public void list() throws WeixinException {
List<User> userList = userApi.listUser(1); List<User> userList = userApi.listUser(1, true, UserStatus.BOTH, true);
Assert.assertFalse(userList.isEmpty());
System.out.println(userList);
userList = userApi.listUser(1);
Assert.assertFalse(userList.isEmpty()); Assert.assertFalse(userList.isEmpty());
System.out.println(userList); System.out.println(userList);
} }

View File

@ -51,4 +51,8 @@ weixin4j-qy-server
* 2014-11-24 * 2014-11-24
+ 新增netty服务与消息分发 + 新增netty服务与消息分发
* 2014-12-28
+ 增加用户进入应用的callback事件

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
<artifactId>weixin4j-qy</artifactId> <artifactId>weixin4j-qy</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>weixin4j-qy-server</artifactId> <artifactId>weixin4j-qy-server</artifactId>
<name>weixin4j-qy-server</name> <name>weixin4j-qy-server</name>

View File

@ -0,0 +1,24 @@
package com.foxinmy.weixin4j.qy.action.event;
import com.foxinmy.weixin4j.action.DebugAction;
import com.foxinmy.weixin4j.action.mapping.ActionAnnotation;
import com.foxinmy.weixin4j.msg.event.EnterAgentEventMessage;
import com.foxinmy.weixin4j.type.EventType;
import com.foxinmy.weixin4j.type.MessageType;
/**
* 用户进入应用的事件推送
*
* @className
* @author jy
* @date 2014年12月28日
* @since JDK 1.7
* @see com.foxinmy.weixin4j.msg.event.EnterAgentEventMessage
* @see<a href=
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E4%BA%8B%E4%BB%B6#.E7.94.A8.E6.88.B7.E8.BF.9B.E5.85.A5.E5.BA.94.E7.94.A8.E7.9A.84.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81"
* >用户进入应用的事件推送</a>
*/
@ActionAnnotation(msgType = MessageType.event, eventType = { EventType.enter_agent })
public class EnterAgentAction extends DebugAction<EnterAgentEventMessage> {
}