Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
调整离线回调
Browse files Browse the repository at this point in the history
  • Loading branch information
Acexy committed Oct 31, 2018
1 parent 8c2a2b7 commit c441370
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
- [更多介绍](https://www.thankjava.com/opensource/069239e5eee95a2299b804d9f98f1f9a)

---
> ### Bug fixes & 升级备注
> ### 升级备注
```
1.1.3
升级了关键依赖版本
掉线事件回调函数返回了SmartQQClient实例,方便业务关闭实例
1.1.2
升级部分依赖组件版本
关闭httpclient cookie检查的警告日志
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.thankjava.wqq</groupId>
<artifactId>smartqq-agreement-core</artifactId>
<version>1.2.0</version>
<version>1.1.3</version>

<parent>
<groupId>org.sonatype.oss</groupId>
Expand All @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<fast-toolkit.version>1.1.0</fast-toolkit.version>
<fast-toolkit.version>1.1.1-SNAPSHOT</fast-toolkit.version>
<httpasyncclient.version>4.1.4</httpasyncclient.version>
<fastjson.version>1.2.49</fastjson.version>
<org.slf4j.version>1.7.25</org.slf4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private boolean doExceptionCheck(PullMsgStatus pullMsgStatus) {
logger.debug("执行重连失败已达到上限,已放弃尝试");
CallBackListener callBackListener = WQQClient.getOfflineListener();
if (callBackListener != null) {
callBackListener.onListener(new ActionListener());
callBackListener.onListener(new ActionListener(WQQClient.getInstance()));
}
}
} catch (Exception e) {
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/com/thankjava/wqq/test/qq/MessageListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import com.thankjava.wqq.entity.msg.PollMsg;
import com.thankjava.wqq.entity.msg.SendMsg;
import com.thankjava.wqq.extend.NotifyListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MessageListener implements NotifyListener {

private static final Logger logger = LoggerFactory.getLogger(MessageListener.class);

@Override
public void handler(SmartQQClient smartQQClient, PollMsg pollMsg) {

// 获取到的消息内容
System.out.println("received msg : " + pollMsg.getMsgContext());
logger.debug("received msg : " + pollMsg.getMsgContext());
switch (pollMsg.getMsgType()) {
case message:
smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg: `Friend`"));
Expand All @@ -29,7 +32,7 @@ public void handler(SmartQQClient smartQQClient, PollMsg pollMsg) {
// sendMsg 接口能通过pollMsg得到msg的类型,然后自动回复该类型的msg
// @Override
// public void handler(SmartQQClient smartQQClient, PollMsg pollMsg) {
// System.out.println("received msg : " + pollMsg.getMsgContext());
// logger.debug("received msg : " + pollMsg.getMsgContext());
// smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg"));
// }

Expand Down
17 changes: 9 additions & 8 deletions src/test/java/com/thankjava/wqq/test/qq/TestSmartQQ.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.thankjava.wqq.test.qq;

import com.thankjava.toolkit3d.fastjson.FastJson;
import com.thankjava.toolkit3d.core.fastjson.FastJson;
import com.thankjava.wqq.SmartQQClient;
import com.thankjava.wqq.SmartQQClientBuilder;
import com.thankjava.wqq.entity.enums.LoginResultStatus;
Expand Down Expand Up @@ -29,7 +29,6 @@ public static void main(String[] args) {
* step 1 > 利用指定使用SmartQQClientBuilder指南来构建SmartQQClient实例
*/
SmartQQClientBuilder builder = SmartQQClientBuilder.custom(

// 注册一个通知事件的处理器,它将在SmartQQClient获得到相关信息时被调用执行
new MessageListener()
);
Expand All @@ -42,12 +41,14 @@ public static void main(String[] args) {
.setAutoGetInfoAfterLogin() // 设置登录成功后立即拉取一些信息
.setExceptionRetryMaxTimes(3) // 设置如果请求异常重试3次
.setAutoRefreshQrcode() // 设置若发现登录二维码过期则自动重新拉取
// .setOffLineListener(new CallBackListener() { // 注册一个离线通知 掉线后将被调用执行
// @Override
// public void onListener(ActionListener actionListener) {
// logger.info("登录的QQ已由掉线无法继续使用(系统已经尝试自动处理)");
// }
// })
.setOffLineListener(new CallBackListener() { // 注册一个离线通知 掉线后将被调用执行
@Override
public void onListener(ActionListener actionListener) {
logger.info("登录的QQ已掉线无法继续使用(系统已经尝试自动处理)");
SmartQQClient smartQQClient = (SmartQQClient) actionListener.getData();
smartQQClient.shutdown();
}
})
;

/**
Expand Down

0 comments on commit c441370

Please sign in to comment.