diff --git a/README.md b/README.md index 5fff334..49842fa 100644 --- a/README.md +++ b/README.md @@ -9,35 +9,36 @@ --- > ### Bug fixes & 升级备注 ``` - 1.0.1 - 修复腾讯修改二维码校验流程带来的影响 - 1.0.2 - 调整代码易读性,增加稳定性等 - 代码结构调整 - 增加异常重试机制,增强稳定性 - 初始化SmartQQ的实现新增两个可选的构造参数 - 1.0.3 - 配合java-toolkit升级,修复async.http模块稳定性 - 配合async.http参数变更结构调整等 - 解决由于腾讯协议bug导致的自己发送的群消息识别为别人的信息 - 1.0.4 - 升级java-toolkit依赖的模块 - 1.0.5 - 升级依赖组件 - 调整代码结构 - 1.1.0 - 标注废除历史版本登录和应用初始化相关代码预计1.1.1将彻底移除) - 新增提供基于Fluent Interface风格代码的初始化,并提供测试案例代码 - 调整部分代码注释,调整可配参数代码 - 废弃主动登录接口,合并到初始化自动完成 - 闭环登录环节的相关异常,各个需要业务控制的回调均提供反馈调用 - 增加稳定性,新增应用健康状态监控,提供优化掉线自动重连机制 - 1.1.1 - 移除了历史版本登录测试方法和历史登录的相关支持代码 - 调整了测试代码优化了大量代码注释 - 1.1.2 - 升级部分依赖组件版本 - 关闭httpclient cookie检查的警告日志 +1.0.1 + 修复腾讯修改二维码校验流程带来的影响 +1.0.2 + 调整代码易读性,增加稳定性等 + 代码结构调整 + 增加异常重试机制,增强稳定性 + 初始化SmartQQ的实现新增两个可选的构造参数 +1.0.3 + 配合java-toolkit升级,修复async.http模块稳定性 + 配合async.http参数变更结构调整等 + 解决由于腾讯协议bug导致的自己发送的群消息识别为别人的信息 +1.0.4 + 升级java-toolkit依赖的模块 +1.0.5 + 升级依赖组件 + 调整代码结构 +1.1.0 + 标注废除历史版本登录和应用初始化相关代码预计1.1.1将彻底移除) + 新增提供基于Fluent Interface风格代码的初始化,并提供测试案例代码 + 调整部分代码注释,调整可配参数代码 + 废弃主动登录接口,合并到初始化自动完成 + 闭环登录环节的相关异常,各个需要业务控制的回调均提供反馈调用 + 增加稳定性,新增应用健康状态监控,提供优化掉线自动重连机制 +1.1.1 + 移除了历史版本登录测试方法和历史登录的相关支持代码 + 调整了测试代码优化了大量代码注释 +1.1.2 + 升级部分依赖组件版本 + 关闭httpclient cookie检查的警告日志 + 登录相关信息查询使用async.http的异步请求方式,提高登录速度 ``` --- diff --git a/src/main/java/com/thankjava/wqq/core/action/GetInfoAction.java b/src/main/java/com/thankjava/wqq/core/action/GetInfoAction.java index 715af2d..e90798c 100644 --- a/src/main/java/com/thankjava/wqq/core/action/GetInfoAction.java +++ b/src/main/java/com/thankjava/wqq/core/action/GetInfoAction.java @@ -1,5 +1,7 @@ package com.thankjava.wqq.core.action; +import com.thankjava.wqq.extend.ActionListener; +import com.thankjava.wqq.extend.CallBackListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,6 +45,7 @@ public class GetInfoAction { * @date 2016年12月22日 下午1:34:35 * @version 1.0 */ + @Deprecated public FriendsList getFriendsList() { AsyncResponse response = null; @@ -62,6 +65,42 @@ public FriendsList getFriendsList() { return null; } + /** + * 异步获取好友列表 + * + * @param callBackListener + * @param tryTimes + */ + public void getFriendsList(final CallBackListener callBackListener, final Integer... tryTimes) { + + final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1; + if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) { + logger.error("getUserFriends2 失败 (已尝试重试)"); + callBackListener.onListener(new ActionListener(null)); + return; + } + + getUserFriends2.doRequest(new CallBackListener() { + + @Override + public void onListener(ActionListener actionListener) { + if (actionListener.getData() != null) { + AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData(); + FriendsList friendsList = JSON2Entity.userFriends2(asyncResponse.getDataString()); + if (friendsList != null) { + session.setFriendsList(friendsList); + callBackListener.onListener(new ActionListener(friendsList)); + } else { + getFriendsList(callBackListener, tryTime); + } + } else { + getFriendsList(callBackListener, tryTime); + } + } + + }); + } + /** * 为当前好友列表数据查询在线状态 *
Function: getOnlineStatus
@@ -72,6 +111,7 @@ public FriendsList getFriendsList() { * @date 2017年6月14日 下午2:46:17 * @version 1.0 */ + @Deprecated public FriendsList getOnlineStatus() { FriendsList friendsList = session.getFriendsList(); @@ -96,6 +136,41 @@ public FriendsList getOnlineStatus() { return null; } + public void getOnlineStatus(final CallBackListener callBackListener, final Integer... tryTimes) { + + final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1; + if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) { + logger.error("getOnlineBuddies2 失败 (已尝试重试)"); + callBackListener.onListener(new ActionListener(null)); + return; + } + + getOnlineBuddies2.doRequest(new CallBackListener() { + + @Override + public void onListener(ActionListener actionListener) { + FriendsList friendsList = session.getFriendsList(); + if (friendsList == null) { + callBackListener.onListener(new ActionListener(null)); + return; + } + if (actionListener.getData() != null) { + AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData(); + friendsList = JSON2Entity.onlineStatus(friendsList, asyncResponse.getDataString()); + if (friendsList != null) { + session.setFriendsList(friendsList); + callBackListener.onListener(new ActionListener(friendsList)); + } else { + getOnlineStatus(callBackListener, tryTime); + } + } else { + getOnlineStatus(callBackListener, tryTime); + } + } + + }); + } + /** * 获取讨论组列表 *Function: getDiscusList
@@ -133,6 +208,7 @@ public DiscusList getDiscusList() { * @date 2016年12月22日 下午1:56:17 * @version 1.0 */ + @Deprecated public GroupsList getGroupsList() { AsyncResponse response = null; GroupsList groupList = null; @@ -150,6 +226,36 @@ public GroupsList getGroupsList() { return null; } + public void getGroupsList(final CallBackListener callBackListener, final Integer... tryTimes) { + + final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1; + + if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) { + logger.error("getGroupNameListMask2 失败 (已尝试重试)"); + callBackListener.onListener(new ActionListener(null)); + return; + } + + getGroupNameListMask2.doRequest(new CallBackListener() { + @Override + public void onListener(ActionListener actionListener) { + if (actionListener.getData() != null) { + AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData(); + GroupsList groupList = JSON2Entity.getGroupsList(asyncResponse.getDataString()); + if (groupList != null) { + session.setGroupsList(groupList); + callBackListener.onListener(new ActionListener(groupList)); + } else { + getOnlineStatus(callBackListener, tryTime); + } + } else { + getOnlineStatus(callBackListener, tryTime); + } + } + + }); + } + /** * 获取个人信息(登录人) *Function: getSelfInfo
@@ -178,6 +284,9 @@ public DetailedInfo getSelfInfo() { return null; } + public void getSelfInfo(final CallBackListener callBackListener, final Integer... tryTimes) { + } + void getRecentList() { getRecentList2.doRequest(null).isEmptyDataString(); } diff --git a/src/main/java/com/thankjava/wqq/core/action/LoginAction.java b/src/main/java/com/thankjava/wqq/core/action/LoginAction.java index c638221..fa9ad5c 100644 --- a/src/main/java/com/thankjava/wqq/core/action/LoginAction.java +++ b/src/main/java/com/thankjava/wqq/core/action/LoginAction.java @@ -189,19 +189,52 @@ private boolean beginLogin() { if (ConfigParams.INIT_LOGIN_INFO) { - FriendsList friendsList = getInfo.getFriendsList(); - if (friendsList == null) { - logger.error("获取好友列表失败"); - } else { - friendsList = getInfo.getOnlineStatus(); - if (friendsList == null) { - logger.error("为好友列表查询在线状态失败"); + getInfo.getFriendsList(new CallBackListener() { + @Override + public void onListener(ActionListener actionListener) { + if (actionListener.getData() == null) { + logger.error("获取好友列表失败"); + } else { + logger.debug("获取好友列表成功"); + getInfo.getOnlineStatus(new CallBackListener() { + @Override + public void onListener(ActionListener actionListener) { + if (actionListener.getData() == null) { + logger.error("查询好友状态失败"); + } else { + logger.error("查询好友状态失败"); + } + } + }); + } } - } - getInfo.getGroupsList(); - getInfo.getDiscusList(); + }); + + getInfo.getGroupsList(new CallBackListener() { + @Override + public void onListener(ActionListener actionListener) { + if (actionListener.getData() != null) { + logger.debug("获取群列表成功"); + } + } + }); + +// FriendsList friendsList = getInfo.getFriendsList(); +// if (friendsList == null) { +// logger.error("获取好友列表失败"); +// } else { +// friendsList = getInfo.getOnlineStatus(); +// if (friendsList == null) { +// logger.error("为好友列表查询在线状态失败"); +// } +// } +// getInfo.getGroupsList(); +// getInfo.getDiscusList(); getInfo.getSelfInfo(); getInfo.getRecentList(); + + + } diff --git a/src/main/java/com/thankjava/wqq/core/request/aop/DoRequest.java b/src/main/java/com/thankjava/wqq/core/request/aop/DoRequest.java index d8e51e5..94d058a 100644 --- a/src/main/java/com/thankjava/wqq/core/request/aop/DoRequest.java +++ b/src/main/java/com/thankjava/wqq/core/request/aop/DoRequest.java @@ -2,6 +2,8 @@ import java.lang.reflect.Method; +import com.thankjava.toolkit3d.http.async.entity.AsyncResponse; +import com.thankjava.toolkit3d.http.async.entity.AsyncResponseCallback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,7 +29,7 @@ public AopParam doRequest(AopParam aopParam) { aopParam.setInvokeProxyMethod(false); // 获取被代理的函数的参数列 - CallBackListener listener = (CallBackListener) aopParam.getParams()[0]; + final CallBackListener listener = (CallBackListener) aopParam.getParams()[0]; // 执行buildRequestParams 得到请求的参数体 Object proxyInstance = aopParam.getProxyInstance(); @@ -36,9 +38,28 @@ public AopParam doRequest(AopParam aopParam) { AsyncRequest asyncRequest = (AsyncRequest) ReflectHelper.invokeMethod(proxyInstance, method); if (listener != null) { + // 如果传递了listener 则通过listener的方式回调返回 try { - listener.onListener(new ActionListener((asyncHttpClient.syncRequestWithSession(asyncRequest)))); + + asyncHttpClient.asyncRequestWithSession(asyncRequest, new AsyncResponseCallback() { + + @Override + public void completed(AsyncResponse asyncResponse) { + listener.onListener(new ActionListener(asyncResponse)); + } + + @Override + public void failed(Exception e) { + listener.onListener(new ActionListener(null)); + } + + @Override + public void cancelled() { + listener.onListener(new ActionListener(null)); + } + + }); } catch (Throwable e) { logger.error("http request error", e); listener.onListener(new ActionListener()); @@ -52,6 +73,7 @@ public AopParam doRequest(AopParam aopParam) { aopParam.setResult(null); logger.error("http request error", e); } + } // 通过普通的方式返回结果 diff --git a/src/main/java/com/thankjava/wqq/core/request/api/BaseHttpService.java b/src/main/java/com/thankjava/wqq/core/request/api/BaseHttpService.java index 9975632..a9cdc3d 100644 --- a/src/main/java/com/thankjava/wqq/core/request/api/BaseHttpService.java +++ b/src/main/java/com/thankjava/wqq/core/request/api/BaseHttpService.java @@ -4,8 +4,8 @@ import com.thankjava.toolkit3d.http.async.AsyncHttpClient; import com.thankjava.toolkit3d.http.async.AsyncHttpClientBuilder; +import com.thankjava.toolkit3d.http.async.consts.CookieCheckLevel; import com.thankjava.toolkit3d.http.async.entity.AsyncRequest; -import com.thankjava.toolkit3d.http.async.entity.CookieCheckLevel; import com.thankjava.wqq.consts.ConstsParams; import com.thankjava.wqq.core.request.RequestBuilder; import com.thankjava.wqq.entity.Session;