mirror of
https://gitee.com/hotlcc/wechat4j.git
synced 2025-06-08 11:34:07 +08:00
提交代码:代码规范性调整
This commit is contained in:
parent
4eebb0ab10
commit
cf228920ee
@ -35,7 +35,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
@SuppressWarnings({"Duplicates", "unused"})
|
||||
public class Wechat {
|
||||
private static Logger logger = LoggerFactory.getLogger(Wechat.class);
|
||||
|
||||
@ -82,6 +82,12 @@ public class Wechat {
|
||||
this.webWeixinApi = webWeixinApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Cookie
|
||||
*
|
||||
* @param name key
|
||||
* @return Cookie
|
||||
*/
|
||||
private Cookie getCookie(String name) {
|
||||
List<Cookie> cookies = cookieStore.getCookies();
|
||||
if (cookies == null) {
|
||||
@ -95,6 +101,12 @@ public class Wechat {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Cookie值
|
||||
*
|
||||
* @param name key
|
||||
* @return Cookie值
|
||||
*/
|
||||
public String getCookieValue(String name) {
|
||||
Cookie cookie = getCookie(name);
|
||||
if (cookie == null) {
|
||||
@ -103,6 +115,11 @@ public class Wechat {
|
||||
return cookie.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加退出事件处理器
|
||||
*
|
||||
* @param handler 退出事件处理器
|
||||
*/
|
||||
public void addExitEventHandler(ExitEventHandler handler) {
|
||||
if (handler == null) {
|
||||
return;
|
||||
@ -114,6 +131,11 @@ public class Wechat {
|
||||
exitEventHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加退出事件处理器
|
||||
*
|
||||
* @param handlers 退出事件处理器
|
||||
*/
|
||||
public void addExitEventHandler(Collection<ExitEventHandler> handlers) {
|
||||
if (handlers == null || handlers.isEmpty()) {
|
||||
return;
|
||||
@ -126,6 +148,11 @@ public class Wechat {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加接收消息处理器
|
||||
*
|
||||
* @param handler 接收消息处理器
|
||||
*/
|
||||
public void addReceivedMsgHandler(ReceivedMsgHandler handler) {
|
||||
if (handler == null) {
|
||||
return;
|
||||
@ -136,6 +163,11 @@ public class Wechat {
|
||||
receivedMsgHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加接收消息处理器
|
||||
*
|
||||
* @param handlers 接收消息处理器
|
||||
*/
|
||||
public void addReceivedMsgHandler(Collection<ReceivedMsgHandler> handlers) {
|
||||
if (handlers == null || handlers.isEmpty()) {
|
||||
return;
|
||||
@ -148,6 +180,12 @@ public class Wechat {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建http客户端
|
||||
*
|
||||
* @param cookieStore Cookie保存
|
||||
* @return http客户端
|
||||
*/
|
||||
private HttpClient buildHttpClient(CookieStore cookieStore) {
|
||||
HttpRequestInterceptor interceptor = new HttpRequestInterceptor() {
|
||||
@Override
|
||||
@ -474,7 +512,7 @@ public class Wechat {
|
||||
return true;
|
||||
}
|
||||
|
||||
JSONObject result = null;
|
||||
JSONObject result;
|
||||
int time = PropertiesUtil.getIntValue("wechat4j.retry.time", 3);
|
||||
|
||||
// 2、登录
|
||||
@ -538,7 +576,7 @@ public class Wechat {
|
||||
/**
|
||||
* 自动登录
|
||||
*
|
||||
* @return
|
||||
* @return 成功状态
|
||||
*/
|
||||
public boolean autoLogin() {
|
||||
return autoLogin(null, false);
|
||||
@ -546,6 +584,8 @@ public class Wechat {
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*
|
||||
* @param clearAllLoginInfo 是否清除全部登录信息
|
||||
*/
|
||||
public void logout(boolean clearAllLoginInfo) {
|
||||
if (isOnline) {
|
||||
@ -599,7 +639,7 @@ public class Wechat {
|
||||
/**
|
||||
* 判断在线状态
|
||||
*
|
||||
* @return
|
||||
* @return 是否在线
|
||||
*/
|
||||
public boolean isOnline() {
|
||||
return isOnline;
|
||||
@ -673,6 +713,9 @@ public class Wechat {
|
||||
|
||||
/**
|
||||
* 处理退出事件
|
||||
*
|
||||
* @param type 退出类型
|
||||
* @param t 异常
|
||||
*/
|
||||
private void processExitEvent(ExitTypeEnum type, Throwable t) {
|
||||
try {
|
||||
@ -719,7 +762,7 @@ public class Wechat {
|
||||
/**
|
||||
* 处理selector值
|
||||
*
|
||||
* @param selector
|
||||
* @param selector selector值
|
||||
*/
|
||||
private void processSelector(int selector) {
|
||||
try {
|
||||
@ -751,8 +794,6 @@ public class Wechat {
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private void webWxSync() {
|
||||
try {
|
||||
@ -762,21 +803,21 @@ public class Wechat {
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
|
||||
if (BaseResponse == null) {
|
||||
JSONObject baseResponse = result.getJSONObject("BaseResponse");
|
||||
if (baseResponse == null) {
|
||||
logger.warn("同步接口返回数据格式错误");
|
||||
return;
|
||||
}
|
||||
|
||||
int Ret = BaseResponse.getIntValue("Ret");
|
||||
if (Ret != RetcodeEnum.RECODE_0.getCode()) {
|
||||
logger.warn("同步接口返回错误代码:{}", Ret);
|
||||
int ret = baseResponse.getIntValue("Ret");
|
||||
if (ret != RetcodeEnum.RECODE_0.getCode()) {
|
||||
logger.warn("同步接口返回错误代码:{}", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
//新消息处理
|
||||
JSONArray AddMsgList = result.getJSONArray("AddMsgList");
|
||||
processNewMsg(AddMsgList);
|
||||
JSONArray addMsgList = result.getJSONArray("AddMsgList");
|
||||
processNewMsg(addMsgList);
|
||||
|
||||
//更新SyncKey
|
||||
try {
|
||||
@ -793,15 +834,15 @@ public class Wechat {
|
||||
/**
|
||||
* 处理新消息
|
||||
*
|
||||
* @param AddMsgList
|
||||
* @param addMsgList 消息列表
|
||||
*/
|
||||
private void processNewMsg(JSONArray AddMsgList) {
|
||||
private void processNewMsg(JSONArray addMsgList) {
|
||||
try {
|
||||
if (AddMsgList == null || AddMsgList.isEmpty()) {
|
||||
if (addMsgList == null || addMsgList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int len = AddMsgList.size();
|
||||
int len = addMsgList.size();
|
||||
logger.debug("收到{}条新消息", len);
|
||||
|
||||
if (receivedMsgHandlers == null || receivedMsgHandlers.isEmpty()) {
|
||||
@ -809,7 +850,7 @@ public class Wechat {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ReceivedMsg> receivedMsgList = ReceivedMsg.valueOf(AddMsgList);
|
||||
List<ReceivedMsg> receivedMsgList = ReceivedMsg.valueOf(addMsgList);
|
||||
for (ReceivedMsg receivedMsg : receivedMsgList) {
|
||||
for (ReceivedMsgHandler handler : receivedMsgHandlers) {
|
||||
if (handler != null) {
|
||||
@ -834,7 +875,7 @@ public class Wechat {
|
||||
/**
|
||||
* 获取登录用户对象
|
||||
*
|
||||
* @return
|
||||
* @return 登录用户对象
|
||||
*/
|
||||
public UserInfo getLoginUser(boolean update) {
|
||||
if (loginUser == null || update) {
|
||||
@ -843,13 +884,13 @@ public class Wechat {
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
|
||||
if (result == null) {
|
||||
JSONObject baseResponse = result.getJSONObject("BaseResponse");
|
||||
if (baseResponse == null) {
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
int Ret = BaseResponse.getIntValue("Ret");
|
||||
if (Ret != 0) {
|
||||
int ret = baseResponse.getIntValue("Ret");
|
||||
if (ret != 0) {
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
@ -874,7 +915,7 @@ public class Wechat {
|
||||
/**
|
||||
* 获取登录用户名
|
||||
*
|
||||
* @return
|
||||
* @return 登录用户的用户名(加密的)
|
||||
*/
|
||||
public String getLoginUserName(boolean update) {
|
||||
UserInfo loginUser = getLoginUser(update);
|
||||
@ -891,7 +932,7 @@ public class Wechat {
|
||||
/**
|
||||
* 获取登录用户的昵称
|
||||
*
|
||||
* @return
|
||||
* @return 登录用户的昵称
|
||||
*/
|
||||
public String getLoginUserNickName(boolean update) {
|
||||
UserInfo loginUser = getLoginUser(update);
|
||||
@ -908,8 +949,8 @@ public class Wechat {
|
||||
/**
|
||||
* 获取SyncKey
|
||||
*
|
||||
* @param update
|
||||
* @return
|
||||
* @param update 是否强制更新
|
||||
* @return 返回数据
|
||||
*/
|
||||
private JSONObject getSyncKey(boolean update) {
|
||||
if (syncKey == null || update) {
|
||||
@ -918,13 +959,13 @@ public class Wechat {
|
||||
return syncKey;
|
||||
}
|
||||
|
||||
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
|
||||
if (result == null) {
|
||||
JSONObject baseResponse = result.getJSONObject("BaseResponse");
|
||||
if (baseResponse == null) {
|
||||
return syncKey;
|
||||
}
|
||||
|
||||
int Ret = BaseResponse.getIntValue("Ret");
|
||||
if (Ret != 0) {
|
||||
int ret = baseResponse.getIntValue("Ret");
|
||||
if (ret != 0) {
|
||||
return syncKey;
|
||||
}
|
||||
|
||||
@ -945,22 +986,22 @@ public class Wechat {
|
||||
/**
|
||||
* 获取SyncKey的List
|
||||
*
|
||||
* @param update
|
||||
* @return
|
||||
* @param update 是否强制更新
|
||||
* @return 返回数据
|
||||
*/
|
||||
private JSONArray getSyncKeyList(boolean update) {
|
||||
JSONObject SyncKey = getSyncKey(update);
|
||||
if (SyncKey == null) {
|
||||
JSONObject syncKey = getSyncKey(update);
|
||||
if (syncKey == null) {
|
||||
return null;
|
||||
}
|
||||
return SyncKey.getJSONArray("List");
|
||||
return syncKey.getJSONArray("List");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取联系人列表
|
||||
*
|
||||
* @param update
|
||||
* @return
|
||||
* @param update 是否强制更新
|
||||
* @return 返回数据
|
||||
*/
|
||||
public List<UserInfo> getContactList(boolean update) {
|
||||
if (contactList == null || update) {
|
||||
@ -969,13 +1010,13 @@ public class Wechat {
|
||||
return contactList;
|
||||
}
|
||||
|
||||
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
|
||||
if (BaseResponse == null) {
|
||||
JSONObject baseResponse = result.getJSONObject("BaseResponse");
|
||||
if (baseResponse == null) {
|
||||
return contactList;
|
||||
}
|
||||
|
||||
String Ret = BaseResponse.getString("Ret");
|
||||
if (!"0".equals(Ret)) {
|
||||
String ret = baseResponse.getString("Ret");
|
||||
if (!"0".equals(ret)) {
|
||||
return contactList;
|
||||
}
|
||||
|
||||
@ -1000,9 +1041,9 @@ public class Wechat {
|
||||
/**
|
||||
* 根据UserName获取联系人信息
|
||||
*
|
||||
* @param update
|
||||
* @param userName
|
||||
* @return
|
||||
* @param update 是否强制更新
|
||||
* @param userName 用户名(加密的)
|
||||
* @return 返回数据
|
||||
*/
|
||||
public UserInfo getContactByUserName(boolean update, String userName) {
|
||||
if (StringUtil.isEmpty(userName)) {
|
||||
@ -1034,9 +1075,9 @@ public class Wechat {
|
||||
/**
|
||||
* 根据NickName获取联系人信息
|
||||
*
|
||||
* @param update
|
||||
* @param nickName
|
||||
* @return
|
||||
* @param update 是否强制更新
|
||||
* @param nickName 昵称
|
||||
* @return 返回数据
|
||||
*/
|
||||
public UserInfo getContactByNickName(boolean update, String nickName) {
|
||||
if (StringUtil.isEmpty(nickName)) {
|
||||
@ -1068,9 +1109,9 @@ public class Wechat {
|
||||
/**
|
||||
* 根据RemarkName获取联系人信息
|
||||
*
|
||||
* @param update
|
||||
* @param remarkName
|
||||
* @return
|
||||
* @param update 是否强制更新
|
||||
* @param remarkName 备注名
|
||||
* @return 返回数据
|
||||
*/
|
||||
public UserInfo getContactByRemarkName(boolean update, String remarkName) {
|
||||
if (StringUtil.isEmpty(remarkName)) {
|
||||
@ -1102,9 +1143,9 @@ public class Wechat {
|
||||
/**
|
||||
* 发送文本消息
|
||||
*
|
||||
* @param userName
|
||||
* @param content
|
||||
* @return
|
||||
* @param userName 用户名(加密的)
|
||||
* @param content 文本消息内容
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendText(String userName, String content) {
|
||||
BaseRequest baseRequest = new BaseRequest(wxsid, skey, wxuin);
|
||||
@ -1123,17 +1164,15 @@ public class Wechat {
|
||||
}
|
||||
message.setType(MsgTypeEnum.TEXT_MSG.getCode());
|
||||
|
||||
JSONObject result = webWeixinApi.sendMsg(httpClient, urlVersion, passTicket, baseRequest, message);
|
||||
|
||||
return result;
|
||||
return webWeixinApi.sendMsg(httpClient, urlVersion, passTicket, baseRequest, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本消息(根据昵称)
|
||||
*
|
||||
* @param nickName
|
||||
* @param content
|
||||
* @return
|
||||
* @param nickName 昵称
|
||||
* @param content 文本消息内容
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendTextToNickName(String nickName, String content) {
|
||||
if (StringUtil.isEmpty(nickName)) {
|
||||
@ -1156,9 +1195,9 @@ public class Wechat {
|
||||
/**
|
||||
* 发送文本消息(根据备注名)
|
||||
*
|
||||
* @param remarkName
|
||||
* @param content
|
||||
* @return
|
||||
* @param remarkName 备注
|
||||
* @param content 文本消息内容
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendTextToRemarkName(String remarkName, String content) {
|
||||
if (StringUtil.isEmpty(remarkName)) {
|
||||
@ -1181,14 +1220,14 @@ public class Wechat {
|
||||
/**
|
||||
* 发送文本消息(根据多种名称)
|
||||
*
|
||||
* @param userName
|
||||
* @param nickName
|
||||
* @param remarkName
|
||||
* @param content
|
||||
* @return
|
||||
* @param userName 用户名(加密的)
|
||||
* @param nickName 昵称
|
||||
* @param remarkName 备注
|
||||
* @param content 文本消息内容
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendText(String userName, String nickName, String remarkName, String content) {
|
||||
UserInfo userInfo = null;
|
||||
UserInfo userInfo;
|
||||
|
||||
if (StringUtil.isNotEmpty(userName)) {
|
||||
return sendText(content, userName);
|
||||
@ -1214,11 +1253,11 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息
|
||||
*
|
||||
* @param userName
|
||||
* @param mediaData
|
||||
* @param mediaName
|
||||
* @param contentType
|
||||
* @return
|
||||
* @param userName 用户名(加密的)
|
||||
* @param mediaData 媒体文件数据
|
||||
* @param mediaName 媒体文件名
|
||||
* @param contentType 媒体文件类型
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImage(String userName, byte[] mediaData, String mediaName, ContentType contentType) {
|
||||
String loginUserName = getLoginUserName(false);
|
||||
@ -1231,17 +1270,17 @@ public class Wechat {
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
|
||||
if (BaseResponse == null) {
|
||||
JSONObject br = result.getJSONObject("BaseResponse");
|
||||
if (br == null) {
|
||||
return result;
|
||||
}
|
||||
int Ret = BaseResponse.getIntValue("Ret");
|
||||
if (Ret != 0) {
|
||||
int ret = br.getIntValue("Ret");
|
||||
if (ret != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String MediaId = result.getString("MediaId");
|
||||
if (StringUtil.isEmpty(MediaId)) {
|
||||
String mediaId = result.getString("MediaId");
|
||||
if (StringUtil.isEmpty(mediaId)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1252,7 +1291,7 @@ public class Wechat {
|
||||
message.setContent("");
|
||||
message.setFromUserName(loginUserName);
|
||||
message.setLocalID(msgId);
|
||||
message.setMediaId(MediaId);
|
||||
message.setMediaId(mediaId);
|
||||
message.setToUserName(toUserName);
|
||||
message.setType(MsgTypeEnum.IMAGE_MSG.getCode());
|
||||
result = webWeixinApi.sendImageMsg(httpClient, urlVersion, passTicket, baseRequest, message);
|
||||
@ -1263,9 +1302,9 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息
|
||||
*
|
||||
* @param userName
|
||||
* @param image
|
||||
* @return
|
||||
* @param userName 用户名(加密的)
|
||||
* @param image 图片文件
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImage(String userName, File image) {
|
||||
ContentType contentType = FileUtil.getContentBody(image);
|
||||
@ -1276,11 +1315,11 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息(根据昵称)
|
||||
*
|
||||
* @param nickName
|
||||
* @param mediaData
|
||||
* @param mediaName
|
||||
* @param contentType
|
||||
* @return
|
||||
* @param nickName 昵称
|
||||
* @param mediaData 媒体文件数据
|
||||
* @param mediaName 媒体文件名
|
||||
* @param contentType 媒体文件类型
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImageToNickName(String nickName, byte[] mediaData, String mediaName, ContentType contentType) {
|
||||
if (StringUtil.isEmpty(nickName)) {
|
||||
@ -1303,9 +1342,9 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息(根据昵称)
|
||||
*
|
||||
* @param nickName
|
||||
* @param image
|
||||
* @return
|
||||
* @param nickName 昵称
|
||||
* @param image 图片文件
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImageToNickName(String nickName, File image) {
|
||||
ContentType contentType = FileUtil.getContentBody(image);
|
||||
@ -1316,11 +1355,11 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息(根据备注名)
|
||||
*
|
||||
* @param remarkName
|
||||
* @param mediaData
|
||||
* @param mediaName
|
||||
* @param contentType
|
||||
* @return
|
||||
* @param remarkName 备注名
|
||||
* @param mediaData 媒体文件数据
|
||||
* @param mediaName 媒体文件名
|
||||
* @param contentType 媒体文件类型
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImageToRemarkName(String remarkName, byte[] mediaData, String mediaName, ContentType contentType) {
|
||||
if (StringUtil.isEmpty(remarkName)) {
|
||||
@ -1343,9 +1382,9 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息(根据备注名)
|
||||
*
|
||||
* @param remarkName
|
||||
* @param image
|
||||
* @return
|
||||
* @param remarkName 备注名
|
||||
* @param image 图片文件
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImageToRemarkName(String remarkName, File image) {
|
||||
ContentType contentType = FileUtil.getContentBody(image);
|
||||
@ -1356,17 +1395,17 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息(根据多种名称)
|
||||
*
|
||||
* @param userName
|
||||
* @param nickName
|
||||
* @param remarkName
|
||||
* @param mediaData
|
||||
* @param mediaName
|
||||
* @param contentType
|
||||
* @return
|
||||
* @param userName 用户名(加密的)
|
||||
* @param nickName 昵称
|
||||
* @param remarkName 备注名
|
||||
* @param mediaData 媒体文件数据
|
||||
* @param mediaName 媒体文件名
|
||||
* @param contentType 媒体文件类型
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImage(String userName, String nickName, String remarkName
|
||||
, byte[] mediaData, String mediaName, ContentType contentType) {
|
||||
UserInfo userInfo = null;
|
||||
UserInfo userInfo;
|
||||
|
||||
if (StringUtil.isNotEmpty(userName)) {
|
||||
return sendImage(userName, mediaData, mediaName, contentType);
|
||||
@ -1392,11 +1431,11 @@ public class Wechat {
|
||||
/**
|
||||
* 发送图片消息(根据多种名称)
|
||||
*
|
||||
* @param userName
|
||||
* @param nickName
|
||||
* @param remarkName
|
||||
* @param image
|
||||
* @return
|
||||
* @param userName 用户名(加密的)
|
||||
* @param nickName 昵称
|
||||
* @param remarkName 备注名
|
||||
* @param image 图片文件
|
||||
* @return 返回数据
|
||||
*/
|
||||
public JSONObject sendImage(String userName, String nickName, String remarkName, File image) {
|
||||
ContentType contentType = FileUtil.getContentBody(image);
|
||||
|
@ -6,20 +6,14 @@ package com.hotlcc.wechat4j.enums;
|
||||
* @author Allen
|
||||
*/
|
||||
public enum ExitTypeEnum {
|
||||
/**
|
||||
* 错误导致退出
|
||||
*/
|
||||
ERROR_EXIT,
|
||||
/**
|
||||
* 本次手动退出
|
||||
*/
|
||||
LOCAL_EXIT,
|
||||
/**
|
||||
* 远程操作退出
|
||||
*/
|
||||
REMOTE_EXIT;
|
||||
ERROR_EXIT("错误退出"),
|
||||
LOCAL_EXIT("本地退出"),
|
||||
REMOTE_EXIT("远程退出");
|
||||
|
||||
ExitTypeEnum() {
|
||||
private String desc;
|
||||
|
||||
ExitTypeEnum(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,20 +5,17 @@ package com.hotlcc.wechat4j.enums;
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public enum LoginTipEnum {
|
||||
/**
|
||||
* 扫码登录
|
||||
*/
|
||||
TIP_0(0),
|
||||
/**
|
||||
* 确认登录
|
||||
*/
|
||||
TIP_1(1);
|
||||
TIP_0(0, "扫码登录"),
|
||||
TIP_1(1, "确认登录");
|
||||
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
LoginTipEnum(int code) {
|
||||
LoginTipEnum(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
|
@ -3,8 +3,9 @@ package com.hotlcc.wechat4j.enums;
|
||||
/**
|
||||
* 消息类型enum
|
||||
*
|
||||
* @author https://gitee.com/hotlcc
|
||||
* @author Allen
|
||||
*/
|
||||
@SuppressWarnings({"unused"})
|
||||
public enum MsgTypeEnum {
|
||||
TEXT_MSG(1, "文本消息"),
|
||||
IMAGE_MSG(3, "图片消息"),
|
||||
|
@ -3,7 +3,7 @@ package com.hotlcc.wechat4j.enums;
|
||||
/**
|
||||
* 操作系统enum
|
||||
*
|
||||
* @author https://gitee.com/hotlcc
|
||||
* @author Allen
|
||||
*/
|
||||
public enum OperatingSystemEnum {
|
||||
DARWIN("darwin"),
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.hotlcc.wechat4j.enums;
|
||||
|
||||
/**
|
||||
* Ret代码
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public enum RetcodeEnum {
|
||||
RECODE_0(0, "正常"),
|
||||
RECODE_1100(1100, "失败/登出微信"),
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.hotlcc.wechat4j.enums;
|
||||
|
||||
/**
|
||||
* Selector代码
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public enum SelectorEnum {
|
||||
SELECTOR_0(0, "正常"),
|
||||
SELECTOR_2(2, "有新消息"),
|
||||
@ -15,10 +20,6 @@ public enum SelectorEnum {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static SelectorEnum valueOf(int code) {
|
||||
SelectorEnum[] es = values();
|
||||
for (SelectorEnum e : es) {
|
||||
|
@ -5,35 +5,37 @@ import com.hotlcc.wechat4j.enums.ExitTypeEnum;
|
||||
|
||||
/**
|
||||
* 退出事件处理器
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public interface ExitEventHandler {
|
||||
/**
|
||||
* 针对所有类型的退出事件
|
||||
*
|
||||
* @param wechat
|
||||
* @param type
|
||||
* @param t
|
||||
* @param wechat 微信客户端
|
||||
* @param type 退出类型
|
||||
* @param t 异常
|
||||
*/
|
||||
void handleAllType(Wechat wechat, ExitTypeEnum type, Throwable t);
|
||||
|
||||
/**
|
||||
* 针对错误导致的退出事件
|
||||
*
|
||||
* @param wechat
|
||||
* @param wechat 微信客户端
|
||||
*/
|
||||
void handleErrorExitEvent(Wechat wechat);
|
||||
|
||||
/**
|
||||
* 针对远程人为导致的退出事件
|
||||
*
|
||||
* @param wechat
|
||||
* @param wechat 微信客户端
|
||||
*/
|
||||
void handleRemoteExitEvent(Wechat wechat);
|
||||
|
||||
/**
|
||||
* 针对本地任务导致的退出事件
|
||||
*
|
||||
* @param wechat
|
||||
* @param wechat 微信客户端
|
||||
*/
|
||||
void handleLocalExitEvent(Wechat wechat);
|
||||
}
|
||||
|
@ -4,14 +4,16 @@ import com.hotlcc.wechat4j.Wechat;
|
||||
import com.hotlcc.wechat4j.model.ReceivedMsg;
|
||||
|
||||
/**
|
||||
* 接收消息处理器
|
||||
* 接收消息的消息处理器
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public interface ReceivedMsgHandler {
|
||||
/**
|
||||
* 处理所有类型的消息
|
||||
*
|
||||
* @param wechat
|
||||
* @param msg
|
||||
* @param wechat 微信客户端
|
||||
* @param msg 接收的消息
|
||||
*/
|
||||
void handleAllType(Wechat wechat, ReceivedMsg msg);
|
||||
}
|
||||
|
@ -1,15 +1,23 @@
|
||||
package com.hotlcc.wechat4j.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AppInfo
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public final class AppInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -25,10 +33,7 @@ public final class AppInfo implements Serializable {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.type = info.getInteger("Type");
|
||||
appInfo.appID = info.getString("AppID");
|
||||
return appInfo;
|
||||
return JSON.toJavaObject(info, AppInfo.class);
|
||||
}
|
||||
|
||||
public static List<AppInfo> valueOf(JSONArray infos) {
|
||||
|
@ -9,6 +9,8 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 基本请求模型
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -6,6 +6,8 @@ import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 媒体消息
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -1,15 +1,18 @@
|
||||
package com.hotlcc.wechat4j.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public final class ReceivedMsg implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -78,37 +81,7 @@ public final class ReceivedMsg implements Serializable {
|
||||
return null;
|
||||
}
|
||||
|
||||
ReceivedMsg receivedMsg = new ReceivedMsg();
|
||||
|
||||
receivedMsg.subMsgType = msg.getInteger("SubMsgType");
|
||||
receivedMsg.voiceLength = msg.getLong("VoiceLength");
|
||||
receivedMsg.fileName = msg.getString("FileName");
|
||||
receivedMsg.imgHeight = msg.getLong("ImgHeight");
|
||||
receivedMsg.toUserName = msg.getString("ToUserName");
|
||||
receivedMsg.hasProductId = msg.getLong("HasProductId");
|
||||
receivedMsg.imgStatus = msg.getInteger("ImgStatus");
|
||||
receivedMsg.url = msg.getString("Url");
|
||||
receivedMsg.imgWidth = msg.getInteger("ImgWidth");
|
||||
receivedMsg.forwardFlag = msg.getInteger("ForwardFlag");
|
||||
receivedMsg.status = msg.getInteger("Status");
|
||||
receivedMsg.ticket = msg.getString("Ticket");
|
||||
receivedMsg.recommendInfo = com.hotlcc.wechat4j.model.RecommendInfo.valueOf(msg.getJSONObject("RecommendInfo"));
|
||||
receivedMsg.createTime = msg.getLong("CreateTime");
|
||||
receivedMsg.newMsgId = msg.getLong("NewMsgId");
|
||||
receivedMsg.msgType = msg.getInteger("MsgType");
|
||||
receivedMsg.encryFileName = msg.getString("EncryFileName");
|
||||
receivedMsg.msgId = msg.getString("MsgId");
|
||||
receivedMsg.statusNotifyCode = msg.getInteger("StatusNotifyCode");
|
||||
receivedMsg.appInfo = com.hotlcc.wechat4j.model.AppInfo.valueOf(msg.getJSONObject("AppInfo"));
|
||||
receivedMsg.playLength = msg.getLong("PlayLength");
|
||||
receivedMsg.mediaId = msg.getString("MediaId");
|
||||
receivedMsg.content = msg.getString("Content");
|
||||
receivedMsg.statusNotifyUserName = msg.getString("StatusNotifyUserName");
|
||||
receivedMsg.fromUserName = msg.getString("FromUserName");
|
||||
receivedMsg.oriContent = msg.getString("OriContent");
|
||||
receivedMsg.fileSize = msg.getString("FileSize");
|
||||
|
||||
return receivedMsg;
|
||||
return JSON.toJavaObject(msg, ReceivedMsg.class);
|
||||
}
|
||||
|
||||
public static List<ReceivedMsg> valueOf(JSONArray msgs) {
|
||||
|
@ -1,15 +1,23 @@
|
||||
package com.hotlcc.wechat4j.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RecommendInfo
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public final class RecommendInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -50,24 +58,7 @@ public final class RecommendInfo implements Serializable {
|
||||
return null;
|
||||
}
|
||||
|
||||
RecommendInfo recommendInfo = new RecommendInfo();
|
||||
|
||||
recommendInfo.ticket = info.getString("Ticket");
|
||||
recommendInfo.userName = info.getString("UserName");
|
||||
recommendInfo.sex = info.getInteger("Sex");
|
||||
recommendInfo.attrStatus = info.getInteger("AttrStatus");
|
||||
recommendInfo.city = info.getString("City");
|
||||
recommendInfo.nickName = info.getString("NickName");
|
||||
recommendInfo.scene = info.getInteger("Scene");
|
||||
recommendInfo.province = info.getString("Province");
|
||||
recommendInfo.content = info.getString("Content");
|
||||
recommendInfo.alias = info.getString("Alias");
|
||||
recommendInfo.signature = info.getString("Signature");
|
||||
recommendInfo.opCode = info.getInteger("OpCode");
|
||||
recommendInfo.qqNum = info.getLong("QQNum");
|
||||
recommendInfo.verifyFlag = info.getInteger("VerifyFlag");
|
||||
|
||||
return recommendInfo;
|
||||
return JSON.toJavaObject(info, RecommendInfo.class);
|
||||
}
|
||||
|
||||
public static List<RecommendInfo> valueOf(JSONArray infos) {
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.hotlcc.wechat4j.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -11,8 +13,11 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 微信用户信息
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public final class UserInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ -87,41 +92,7 @@ public final class UserInfo implements Serializable {
|
||||
return null;
|
||||
}
|
||||
|
||||
UserInfo userInfo = new UserInfo();
|
||||
|
||||
userInfo.uin = info.getLong("Uin");
|
||||
userInfo.nickName = info.getString("NickName");
|
||||
userInfo.headImgUrl = info.getString("HeadImgUrl");
|
||||
userInfo.contactFlag = info.getInteger("ContactFlag");
|
||||
userInfo.memberCount = info.getInteger("MemberCount");
|
||||
userInfo.memberList = valueOf(info.getJSONArray("MemberList"));
|
||||
userInfo.remarkName = info.getString("RemarkName");
|
||||
userInfo.hideInputBarFlag = info.getInteger("HideInputBarFlag");
|
||||
userInfo.sex = info.getInteger("Sex");
|
||||
userInfo.signature = info.getString("Signature");
|
||||
userInfo.verifyFlag = info.getInteger("VerifyFlag");
|
||||
userInfo.ownerUin = info.getLong("OwnerUin");
|
||||
userInfo.pyInitial = info.getString("PYInitial");
|
||||
userInfo.pyQuanPin = info.getString("PYQuanPin");
|
||||
userInfo.remarkPYInitial = info.getString("RemarkPYInitial");
|
||||
userInfo.remarkPYQuanPin = info.getString("RemarkPYQuanPin");
|
||||
userInfo.starFriend = info.getInteger("StarFriend");
|
||||
userInfo.appAccountFlag = info.getInteger("AppAccountFlag");
|
||||
userInfo.statues = info.getInteger("Statues");
|
||||
userInfo.attrStatus = info.getInteger("AttrStatus");
|
||||
userInfo.province = info.getString("Province");
|
||||
userInfo.city = info.getString("City");
|
||||
userInfo.alias = info.getString("Alias");
|
||||
userInfo.snsFlag = info.getInteger("SnsFlag");
|
||||
userInfo.uniFriend = info.getInteger("UniFriend");
|
||||
userInfo.displayName = info.getString("DisplayName");
|
||||
userInfo.chatRoomId = info.getLong("ChatRoomId");
|
||||
userInfo.keyWord = info.getString("KeyWord");
|
||||
userInfo.encryChatRoomId = info.getString("EncryChatRoomId");
|
||||
userInfo.isOwner = info.getInteger("IsOwner");
|
||||
userInfo.userName = info.getString("UserName");
|
||||
|
||||
return userInfo;
|
||||
return JSON.toJavaObject(info, UserInfo.class);
|
||||
}
|
||||
|
||||
public static List<UserInfo> valueOf(JSONArray infos) {
|
||||
|
@ -8,6 +8,8 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 要发送的消息
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -3,12 +3,23 @@ package com.hotlcc.wechat4j.util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 通用工具类
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public final class CommonUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(CommonUtil.class);
|
||||
|
||||
private CommonUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 睡眠线程
|
||||
*
|
||||
* @param millis 时间
|
||||
* @param nanos nanos
|
||||
*/
|
||||
public static void threadSleep(long millis, int nanos) {
|
||||
try {
|
||||
Thread.sleep(millis, nanos);
|
||||
@ -17,6 +28,11 @@ public final class CommonUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 睡眠线程
|
||||
*
|
||||
* @param millis 时间
|
||||
*/
|
||||
public static void threadSleep(long millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
|
@ -12,6 +12,8 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 文件工具类
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public final class FileUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(FileUtil.class);
|
||||
@ -19,6 +21,12 @@ public final class FileUtil {
|
||||
private FileUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文件中获取二进制数据
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 二进制数据
|
||||
*/
|
||||
public static byte[] getBytes(File file) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("参数file不能为null");
|
||||
@ -62,6 +70,12 @@ public final class FileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的ContentType
|
||||
*
|
||||
* @param file 文件
|
||||
* @return ContentType
|
||||
*/
|
||||
public static ContentType getContentBody(File file) {
|
||||
String mimeType = new MimetypesFileTypeMap().getContentType(file);
|
||||
ContentType contentType = ContentType.parse(mimeType);
|
||||
|
@ -7,6 +7,11 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Properties工具类
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public final class PropertiesUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
|
||||
|
||||
|
@ -5,6 +5,11 @@ import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 字符串工具类
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public final class StringUtil {
|
||||
private StringUtil() {
|
||||
}
|
||||
|
@ -4,6 +4,11 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
|
||||
/**
|
||||
* 微信工具类
|
||||
*
|
||||
* @author Allen
|
||||
*/
|
||||
public final class WechatUtil {
|
||||
private WechatUtil() {
|
||||
}
|
||||
@ -14,7 +19,7 @@ public final class WechatUtil {
|
||||
/**
|
||||
* 创建一个设备ID
|
||||
*
|
||||
* @return
|
||||
* @return 设备ID
|
||||
*/
|
||||
public static String createDeviceID() {
|
||||
return "e" + RandomStringUtils.random(15, STRING_CHARS_1);
|
||||
@ -23,7 +28,7 @@ public final class WechatUtil {
|
||||
/**
|
||||
* 创建一个消息ID
|
||||
*
|
||||
* @return
|
||||
* @return 消息ID
|
||||
*/
|
||||
public static String createMsgId() {
|
||||
return System.currentTimeMillis() + RandomStringUtils.random(4, STRING_CHARS_2);
|
||||
@ -32,8 +37,8 @@ public final class WechatUtil {
|
||||
/**
|
||||
* 把SyncKeyList转为字符串格式
|
||||
*
|
||||
* @param SyncKeyList
|
||||
* @return
|
||||
* @param SyncKeyList SyncKeyList
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String syncKeyListToString(JSONArray SyncKeyList) {
|
||||
if (SyncKeyList == null) {
|
||||
@ -55,8 +60,8 @@ public final class WechatUtil {
|
||||
/**
|
||||
* 根据ContentType得到微信上传所需的mediatype
|
||||
*
|
||||
* @param contentType
|
||||
* @return
|
||||
* @param contentType contentType
|
||||
* @return 微信上传所需的mediatype
|
||||
*/
|
||||
public static String getMediatype(String contentType) {
|
||||
if (contentType == null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user