Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Itchat4j dev #36

Merged
merged 3 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
修复获取群好友列表BUG
  • Loading branch information
yaphone committed Jun 21, 2017
commit 7bfe3daf8c501f01795cd39bf8dc6afc8ace74d8
6 changes: 6 additions & 0 deletions src/main/java/cn/zhouyafeng/itchat4j/api/MessageTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class MessageTools {
* @param toUserName
*/
private static void sendMsg(String text, String toUserName) {
if (text == null) {
return;
}
LOG.info(String.format("发送消息 %s: %s", toUserName, text));
webWxSendMsg(1, text, toUserName);
}
Expand All @@ -61,6 +64,9 @@ private static void sendMsg(String text, String toUserName) {
* @param id
*/
public static void sendMsgById(String text, String id) {
if (text == null) {
return;
}
sendMsg(text, id);
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/cn/zhouyafeng/itchat4j/api/WechatTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,26 @@ public static List<JSONObject> getGroupList() {
return core.getGroupList();
}

/**
* 获取群ID列表
*
* @date 2017年6月21日 下午11:42:56
* @return
*/
public static List<String> getGroupIdList() {
return core.getGroupIdList();
}

/**
* 获取群NickName列表
*
* @date 2017年6月21日 下午11:43:38
* @return
*/
public static List<String> getGroupNickNameList() {
return core.getGroupNickNameList();
}

/**
* 根据groupIdList返回群成员列表
*
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/cn/zhouyafeng/itchat4j/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public static Core getInstance() {
private List<JSONObject> groupMemeberList = new ArrayList<JSONObject>();; // 群聊成员字典
private List<JSONObject> publicUsersList = new ArrayList<JSONObject>();;// 公众号/服务号
private List<JSONObject> specialUsersList = new ArrayList<JSONObject>();;// 特殊账号
private List<String> groupIdList = new ArrayList<String>();
private List<String> groupIdList = new ArrayList<String>(); // 群ID列表
private List<String> groupNickNameList = new ArrayList<String>(); // 群NickName列表

private Map<String, JSONObject> userInfoMap = new HashMap<String, JSONObject>();

Map<String, Object> loginInfo = new HashMap<String, Object>();
Expand Down Expand Up @@ -251,4 +253,12 @@ public synchronized void setLastNormalRetcodeTime(long lastNormalRetcodeTime) {
this.lastNormalRetcodeTime = lastNormalRetcodeTime;
}

public List<String> getGroupNickNameList() {
return groupNickNameList;
}

public void setGroupNickNameList(List<String> groupNickNameList) {
this.groupNickNameList = groupNickNameList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ public boolean webWxInit() {
if (o.getString("UserName").indexOf("@@") != -1) {
core.getGroupIdList().add(o.getString("UserName")); // 更新GroupIdList
core.getGroupList().add(o); // 更新GroupList
core.getGroupNickNameList().add(o.getString("NickName"));
}
}

return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
return true;
}

@Override
Expand Down Expand Up @@ -307,6 +307,7 @@ public void webWxGetContact() {
String url = String.format(URLEnum.WEB_WX_GET_CONTACT.getUrl(),
core.getLoginInfo().get(StorageLoginInfoEnum.url.getKey()));
Map<String, Object> paramMap = core.getParamMap();
System.out.println(paramMap);
HttpEntity entity = httpClient.doPost(url, JSON.toJSONString(paramMap));

try {
Expand All @@ -322,7 +323,6 @@ public void webWxGetContact() {
}
core.setMemberCount(fullFriendsJsonList.getInteger(StorageLoginInfoEnum.MemberCount.getKey()));
JSONArray member = fullFriendsJsonList.getJSONArray(StorageLoginInfoEnum.MemberList.getKey());

// 循环获取seq直到为0,即获取全部好友列表 ==0:好友获取完毕 >0:好友未获取完毕,此时seq为已获取的字节数
while (seq > 0) {
// 设置seq传参
Expand Down Expand Up @@ -353,6 +353,7 @@ public void webWxGetContact() {
core.getSpecialUsersList().add(o);
} else if (o.getString("UserName").indexOf("@@") != -1) { // 群聊
if (!core.getGroupIdList().contains(o.getString("UserName"))) {
core.getGroupNickNameList().add(o.getString("NickName"));
core.getGroupIdList().add(o.getString("UserName"));
core.getGroupList().add(o);
}
Expand All @@ -369,6 +370,21 @@ public void webWxGetContact() {
return;
}

/**
* 获取群及群好友列表
*
* @date 2017年6月22日 上午12:45:21
*/
private void WebWxBatchGetContact() {
String url = String.format(URLEnum.WEB_WX_BATCH_GET_CONTACT.getUrl(),
core.getLoginInfo().get(StorageLoginInfoEnum.url.getKey()), new Date().getTime(),
core.getLoginInfo().get(StorageLoginInfoEnum.pass_ticket.getKey()));
Map<String, Object> paramMap = core.getParamMap();
HttpEntity entity = httpClient.doPost(url, JSON.toJSONString(paramMap));

// TODO
}

/**
* 检查登陆状态
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ public String textMsgHandle(JSONObject msg) {
WechatTools.remarkNameByNickName("yaphone", "Hello");
}
if (text.equals("333")) { // 测试群列表
LOG.info(WechatTools.getGroupIdList());
LOG.info(WechatTools.getGroupList().size());
LOG.info("********************");
LOG.info(WechatTools.getMemberListByGroupId(WechatTools.getGroupIdList().get(0)));
LOG.info("*********************");
LOG.info(WechatTools.getGroupNickNameList());
LOG.info(WechatTools.getGroupIdList().size());
}
return text;
}
Expand Down