Skip to content

Commit

Permalink
维护微信状态
Browse files Browse the repository at this point in the history
  • Loading branch information
yaphone committed Jun 15, 2017
1 parent 5c7798f commit 4d9da3a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

- 2017-6-13:修复获取群列表为空问题,增加根据群ID获取群成员列表方法

- 2017-6-16:增加微信状态维护


## API说明
Expand Down Expand Up @@ -76,55 +78,63 @@ public static JSONArray getMemberListByGroupId(String groupIdList)
public static void logout()
```

#### 5.根据用户昵称修改用户备注MessageTools.remarkNameByNickName(String nickName, String remName)
#### 5.获取微信在线状态WechatTools.getWechatState()

查询微信在线状态,在线返回`true`,离线返回`false`,其函数声明为

```java
public static boolean getWechatState()
```

#### 6.根据用户昵称修改用户备注MessageTools.remarkNameByNickName(String nickName, String remName)

根据用户昵称修改用户备注名称,其函数声明为:

```
public static void remarkNameByNickName(String nickName, String remName)
```

#### 6. 根据好友昵称发送文本消息,MessageTools.sendMsgByNickName(String text, String nickName)
#### 7. 根据好友昵称发送文本消息,MessageTools.sendMsgByNickName(String text, String nickName)

此方法根据用户昵称发送文本消息,注意,用户需在你的好友列表里,否则发送失败,如果你的好友列表里有存在昵称一样的多个用户,则只会给第一个匹配的好友发送消息。方法接受两个参数,`text`为要发送的文本消息,`nickName`为要发送消息的好友昵称,成功发送时返回true,失败返回false。其函数声明为:

```
public static boolean sendMsgByNickName(String text, String nickName)
```

#### 7.根据ID发送文本消息, MessageTools.sendMsgById(String text, String id)
#### 8.根据ID发送文本消息, MessageTools.sendMsgById(String text, String id)

根据ID发送文本消息,发送者ID可以从`msg`里通过`msg.getString("FromUserName")`获取,格式为`@@d052d34b9c9228830363013ee53deb461404f80ea353dbdd8fc9391cbf5f1c46`(群消息)或`@a257b99314d8313862cd44ab02fe0f81`(非群消息),调用此方法可向指定id发送消息。其函数声明为:

```
public static void sendMsgById(String text, String id)
```

#### 8.根据好友昵称发送图片消息,MessageTools.sendPicMsgByNickName(String nickName, String filePath)
#### 9.根据好友昵称发送图片消息,MessageTools.sendPicMsgByNickName(String nickName, String filePath)

此方法根据好友昵称发送图片消息,`filePath`为图片文件路径,如`D:/itchat4j/pic/test.jpg`,成功返回true,失败返回false。其函数声明为:

```
public static boolean sendPicMsgByNickName(String nickName, String filePath)
```

#### 9.根据ID发送图片消息,MessageTools.sendPicMsgByUserId(String userId, String filePath)
#### 10.根据ID发送图片消息,MessageTools.sendPicMsgByUserId(String userId, String filePath)

此方法根据好友ID发送图片消息,filePath`为图片文件路径,如`D:/itchat4j/pic/test.jpg`,成功返回true,失败返回false。其函数声明为:

```
public static boolean sendPicMsgByUserId(String userId, String filePath)
```

#### 10.根据好友昵称发送文件消息,MessageTools.sendFileMsgByNickName(String nickName, String filePath)
#### 11.根据好友昵称发送文件消息,MessageTools.sendFileMsgByNickName(String nickName, String filePath)

此方法根据好友昵称发送文件消息,文件可以为多种类型,如txt、PDF、小视频、语音、excel、docx等,发送时请保证文件后缀名正确。成功返回true,失败返回false。其函数声明为:

```
public static boolean sendPicFileByNickName(String nickName, String filePath)
```

#### 11.根据ID发送文件消息,MessageTools.sendFileMsgByNickName(String nickName, String filePath)
#### 12.根据ID发送文件消息,MessageTools.sendFileMsgByNickName(String nickName, String filePath)

此方法根据好友昵称发送文件消息,成功返回true,失败返回false。其函数声明为:

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/cn/zhouyafeng/itchat4j/api/WechatTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public static JSONArray getMemberListByGroupId(String groupIdList) {
*/
public static void logout() {
webWxLogout();
core.setAlive(false);
}

private static boolean webWxLogout() {
Expand Down Expand Up @@ -180,4 +179,14 @@ public static void remarkNameByNickName(String nickName, String remName) {
}
}

/**
* 获取微信在线状态
*
* @date 2017年6月16日 上午12:47:46
* @return
*/
public static boolean getWechatState() {
return core.isAlive();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ public void webWxGetContact() {
member.addAll(fullFriendsJsonList.getJSONArray(StorageLoginInfoEnum.MemberList.getKey()));
}
core.setMemberCount(member.size());
LOG.info(JSON.toJSONString(member));
for (Iterator<?> iterator = member.iterator(); iterator.hasNext();) {
JSONObject o = (JSONObject) iterator.next();
if ((o.getInteger("VerifyFlag") & 8) != 0) { // 公众号/服务号
Expand Down

0 comments on commit 4d9da3a

Please sign in to comment.