diff --git a/pom.xml b/pom.xml
index 0f67578..d6bd0fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,7 +79,12 @@
javase
3.3.3
-
+
+
+ org.projectlombok
+ lombok
+ 1.16.20
+
diff --git a/src/main/java/com/hotlcc/wechat4j/Wechat.java b/src/main/java/com/hotlcc/wechat4j/Wechat.java
index 4f2ba46..b88a36a 100644
--- a/src/main/java/com/hotlcc/wechat4j/Wechat.java
+++ b/src/main/java/com/hotlcc/wechat4j/Wechat.java
@@ -28,8 +28,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -183,24 +182,24 @@ public class Wechat {
/**
* 获取uuid(登录时)
*
- * @param ps
+ * @param pw
* @param time
* @return
*/
- private String getWxUuid(PrintStream ps, int time) {
- ps.print("尝试正常方式获取uuid...");
- ps.flush();
+ private String getWxUuid(PrintWriter pw, int time) {
+ pw.print("尝试正常方式获取uuid...");
+ pw.flush();
for (int i = 0; i <= time; i++) {
if (i > 0) {
- ps.print("\t第" + i + "次尝试...");
- ps.flush();
+ pw.print("\t第" + i + "次尝试...");
+ pw.flush();
}
JSONObject result = webWeixinApi.getWxUuid(httpClient);
if (result == null) {
- ps.println("\t失败:出现异常");
- ps.flush();
+ pw.println("\t失败:出现异常");
+ pw.flush();
return null;
}
@@ -208,23 +207,23 @@ public class Wechat {
String uuid = result.getString("uuid");
if (!"200".equals(code)) {
String msg = result.getString("msg");
- ps.println("\t失败:" + msg);
- ps.flush();
+ pw.println("\t失败:" + msg);
+ pw.flush();
return null;
}
if (StringUtil.isEmpty(uuid)) {
- ps.print("\t失败");
+ pw.print("\t失败");
if (i == 0 && time > 0) {
- ps.print(",将重复尝试" + time + "次");
+ pw.print(",将重复尝试" + time + "次");
}
- ps.println();
- ps.flush();
+ pw.println();
+ pw.flush();
continue;
}
- ps.println("\t成功,值为:" + uuid);
- ps.flush();
+ pw.println("\t成功,值为:" + uuid);
+ pw.flush();
return uuid;
}
return null;
@@ -235,35 +234,35 @@ public class Wechat {
*
* @return
*/
- private boolean getAndShowQRCode(PrintStream ps, String uuid, int time) {
- ps.print("获取二维码...");
- ps.flush();
+ private boolean getAndShowQRCode(PrintWriter pw, String uuid, int time) {
+ pw.print("获取二维码...");
+ pw.flush();
for (int i = 0; i <= time; i++) {
if (i > 0) {
- ps.print("\t第" + i + "次尝试...");
- ps.flush();
+ pw.print("\t第" + i + "次尝试...");
+ pw.flush();
}
byte[] data = webWeixinApi.getQR(httpClient, uuid);
if (data == null || data.length <= 0) {
- ps.print("\t失败");
+ pw.print("\t失败");
if (i == 0 && time > 0) {
- ps.print(",将重新获取uuid并重复尝试" + time + "次");
+ pw.print(",将重新获取uuid并重复尝试" + time + "次");
}
- ps.println();
- ps.flush();
- getWxUuid(ps, 0);
+ pw.println();
+ pw.flush();
+ getWxUuid(pw, 0);
CommonUtil.threadSleep(2000);
continue;
}
- ps.println("\t成功,请扫描二维码:");
- ps.flush();
- ps.println(QRCodeUtil.toCharMatrix(data));
- ps.flush();
+ pw.println("\t成功,请扫描二维码:");
+ pw.flush();
+ pw.println(QRCodeUtil.toCharMatrix(data));
+ pw.flush();
QRCodeUtil.openQRCodeImage(data);
return true;
}
@@ -276,39 +275,39 @@ public class Wechat {
*
* @return
*/
- private JSONObject waitForConfirm(PrintStream ps, String uuid) {
- ps.print("等待手机端扫码...");
- ps.flush();
+ private JSONObject waitForConfirm(PrintWriter pw, String uuid) {
+ pw.print("等待手机端扫码...");
+ pw.flush();
boolean flag = false;
while (true) {
JSONObject result = webWeixinApi.getRedirectUri(httpClient, LoginTipEnum.TIP_0, uuid);
if (result == null) {
- ps.println("\t失败:出现异常");
- ps.flush();
+ pw.println("\t失败:出现异常");
+ pw.flush();
return null;
}
String code = result.getString("code");
if ("408".equals(code)) {
- ps.print(".");
- ps.flush();
+ pw.print(".");
+ pw.flush();
continue;
} else if ("400".equals(code)) {
- ps.println("\t失败,二维码失效");
- ps.flush();
+ pw.println("\t失败,二维码失效");
+ pw.flush();
return null;
} else if ("201".equals(code)) {
if (!flag) {
- ps.println();
- ps.print("请确认登录...");
- ps.flush();
+ pw.println();
+ pw.print("请确认登录...");
+ pw.flush();
flag = true;
}
continue;
} else if ("200".equals(code)) {
- ps.println("\t成功,认证完成");
- ps.flush();
+ pw.println("\t成功,认证完成");
+ pw.flush();
return result;
} else {
return null;
@@ -319,21 +318,21 @@ public class Wechat {
/**
* 获取登录认证码(登录时)
*/
- private boolean getLoginCode(PrintStream ps, String redirectUri) {
- ps.print("获取登录认证码...");
- ps.flush();
+ private boolean getLoginCode(PrintWriter pw, String redirectUri) {
+ pw.print("获取登录认证码...");
+ pw.flush();
JSONObject result = webWeixinApi.getLoginCode(httpClient, redirectUri);
if (result == null) {
- ps.println("\t失败:出现异常");
- ps.flush();
+ pw.println("\t失败:出现异常");
+ pw.flush();
return false;
}
String ret = result.getString("ret");
if (!"0".equals(ret)) {
- ps.println("\t失败:错误的返回码(" + ret + ")");
- ps.flush();
+ pw.println("\t失败:错误的返回码(" + ret + ")");
+ pw.flush();
return false;
}
@@ -342,8 +341,8 @@ public class Wechat {
skey = result.getString("skey");
wxuin = result.getString("wxuin");
- ps.println("\t成功");
- ps.flush();
+ pw.println("\t成功");
+ pw.flush();
return true;
}
@@ -351,37 +350,37 @@ public class Wechat {
/**
* push方式获取uuid(登录时)
*
- * @param ps
+ * @param pw
* @param wxuin
* @return
*/
- private String getWxUuid(PrintStream ps, String wxuin) {
- ps.print("尝试push方式获取uuid...");
- ps.flush();
+ private String getWxUuid(PrintWriter pw, String wxuin) {
+ pw.print("尝试push方式获取uuid...");
+ pw.flush();
JSONObject result = webWeixinApi.pushLogin(httpClient, urlVersion, wxuin);
if (result == null) {
- ps.println("\t失败:出现异常");
- ps.flush();
+ pw.println("\t失败:出现异常");
+ pw.flush();
return null;
}
String ret = result.getString("ret");
if (!"0".equals(ret)) {
- ps.println("\t失败:错误的返回码(" + ret + ")");
- ps.flush();
+ pw.println("\t失败:错误的返回码(" + ret + ")");
+ pw.flush();
return null;
}
String uuid = result.getString("uuid");
if (StringUtil.isEmpty(uuid)) {
- ps.println("\t失败:空值");
- ps.flush();
+ pw.println("\t失败:空值");
+ pw.flush();
return null;
}
- ps.println("\t成功,值为:" + uuid);
- ps.flush();
+ pw.println("\t成功,值为:" + uuid);
+ pw.flush();
return uuid;
}
@@ -418,30 +417,30 @@ public class Wechat {
*
* @return
*/
- private boolean wxInitWithRetry(PrintStream ps, int time) {
- ps.print("正在初始化数据...");
- ps.flush();
+ private boolean wxInitWithRetry(PrintWriter pw, int time) {
+ pw.print("正在初始化数据...");
+ pw.flush();
for (int i = 0; i <= time; i++) {
if (i > 0) {
- ps.print("\t第" + i + "次尝试...");
- ps.flush();
+ pw.print("\t第" + i + "次尝试...");
+ pw.flush();
}
if (!wxInit()) {
- ps.print("\t失败");
+ pw.print("\t失败");
if (i == 0 && time > 0) {
- ps.print(",将重复尝试" + time + "次");
+ pw.print(",将重复尝试" + time + "次");
}
- ps.println();
- ps.flush();
+ pw.println();
+ pw.flush();
CommonUtil.threadSleep(2000);
continue;
}
- ps.println("\t成功");
- ps.flush();
+ pw.println("\t成功");
+ pw.flush();
return true;
}
@@ -480,18 +479,15 @@ public class Wechat {
/**
* 自动登录
*/
- public boolean autoLogin(OutputStream os, boolean tryPushLogin) {
+ public boolean autoLogin(PrintWriter pw, boolean tryPushLogin) {
// 0、获取消息打印流
- PrintStream ps = null;
- if (os != null) {
- ps = new PrintStream(os);
- } else {
- ps = System.out;
+ if (pw == null) {
+ pw = new PrintWriter(System.out);
}
// 1、判断是否已经登录
if (isOnline) {
- ps.println("当前已是登录状态,无需登录");
+ pw.println("当前已是登录状态,无需登录");
return true;
}
@@ -502,45 +498,45 @@ public class Wechat {
// 2.1、获取uuid
String uuid = null;
if (tryPushLogin && StringUtil.isNotEmpty(wxuin)) {
- uuid = getWxUuid(ps, wxuin);
+ uuid = getWxUuid(pw, wxuin);
}
if (StringUtil.isEmpty(uuid)) {
- uuid = getWxUuid(ps, time);
+ uuid = getWxUuid(pw, time);
}
if (StringUtil.isEmpty(uuid)) {
- ps.println("无法获取uuid,登录不成功");
- ps.flush();
+ pw.println("无法获取uuid,登录不成功");
+ pw.flush();
return false;
}
// 2.2、获取并显示二维码
- if (!getAndShowQRCode(ps, uuid, time)) {
- ps.println("无法获取二维码,登录不成功");
- ps.flush();
+ if (!getAndShowQRCode(pw, uuid, time)) {
+ pw.println("无法获取二维码,登录不成功");
+ pw.flush();
return false;
}
// 2.3、等待确认
- result = waitForConfirm(ps, uuid);
+ result = waitForConfirm(pw, uuid);
if (result == null) {
- ps.println("手机端认证失败,登录不成功");
- ps.flush();
+ pw.println("手机端认证失败,登录不成功");
+ pw.flush();
return false;
}
urlVersion = result.getString("urlVersion");
// 2.4、获取登录认证码
- if (!getLoginCode(ps, result.getString("redirectUri"))) {
- ps.println("无法获取登录认证码,登录不成功");
- ps.flush();
+ if (!getLoginCode(pw, result.getString("redirectUri"))) {
+ pw.println("无法获取登录认证码,登录不成功");
+ pw.flush();
return false;
}
// 3、初始化数据
- if (!wxInitWithRetry(ps, time)) {
- ps.println("初始化数据失败,请重新登录");
- ps.flush();
+ if (!wxInitWithRetry(pw, time)) {
+ pw.println("初始化数据失败,请重新登录");
+ pw.flush();
return false;
}
- ps.println("微信登录成功,欢迎你:" + getLoginUserNickName(false));
- ps.flush();
+ pw.println("微信登录成功,欢迎你:" + getLoginUserNickName(false));
+ pw.flush();
try {
isOnlineLock.lock();
@@ -569,17 +565,21 @@ public class Wechat {
* 退出登录
*/
public void logout(boolean clearAllLoginInfo) {
- try {
- isOnlineLock.lock();
+ if (isOnline) {
+ try {
+ isOnlineLock.lock();
- webWeixinApi.logout(httpClient, urlVersion, new BaseRequest(wxsid, skey, wxuin));
- isOnline = false;
+ if (isOnline) {
+ webWeixinApi.logout(httpClient, urlVersion, new BaseRequest(wxsid, skey, wxuin));
+ isOnline = false;
- if (clearAllLoginInfo) {
- clearAllLoginInfo();
+ if (clearAllLoginInfo) {
+ clearAllLoginInfo();
+ }
+ }
+ } finally {
+ isOnlineLock.unlock();
}
- } finally {
- isOnlineLock.unlock();
}
}
@@ -640,7 +640,6 @@ public class Wechat {
long start = System.currentTimeMillis();
try {
- //API调用异常导致退出
JSONObject result = webWeixinApi.syncCheck(httpClient, urlVersion, new BaseRequest(wxsid, skey, wxuin), getSyncKeyList(false));
logger.debug("微信同步监听心跳返回数据:{}", result);
if (result == null) {
@@ -743,7 +742,7 @@ public class Wechat {
try {
SelectorEnum e = SelectorEnum.valueOf(selector);
if (e == null) {
- logger.warn("Cannot process selector for error selector {}", selector);
+ logger.warn("Cannot process unknow selector {}", selector);
return;
}
@@ -755,6 +754,8 @@ public class Wechat {
break;
case SELECTOR_4:
break;
+ case SELECTOR_6:
+ break;
case SELECTOR_7:
break;
default:
@@ -813,36 +814,24 @@ public class Wechat {
*/
private void processNewMsg(JSONArray AddMsgList) {
try {
- if (AddMsgList != null && !AddMsgList.isEmpty()) {
- int len = AddMsgList.size();
- logger.debug("收到{}条新消息", len);
- for (int i = 0; i < len; i++) {
- JSONObject AddMsg = AddMsgList.getJSONObject(i);
- processNewMsg(AddMsg);
- }
- }
- } catch (Exception e) {
- logger.error("Execute processNewMsg error.", e);
- }
- }
-
- private void processNewMsg(JSONObject AddMsg) {
- try {
- ReceivedMsg msg = ReceivedMsg.valueOf(AddMsg);
- processNewMsg(msg);
- } catch (Exception e) {
- logger.error("Execute processNewMsg error.", e);
- }
- }
-
- private void processNewMsg(ReceivedMsg msg) {
- try {
- if (receivedMsgHandlers == null) {
+ if (AddMsgList == null || AddMsgList.isEmpty()) {
return;
}
- for (ReceivedMsgHandler handler : receivedMsgHandlers) {
- if (handler != null) {
- processNewMsg(msg, handler);
+
+ int len = AddMsgList.size();
+ logger.debug("收到{}条新消息", len);
+
+ if (receivedMsgHandlers == null || receivedMsgHandlers.isEmpty()) {
+ logger.warn("收到{}条新消息,但没有配置消息处理器", len);
+ return;
+ }
+
+ List receivedMsgList = ReceivedMsg.valueOf(AddMsgList);
+ for (ReceivedMsg receivedMsg : receivedMsgList) {
+ for (ReceivedMsgHandler handler : receivedMsgHandlers) {
+ if (handler != null) {
+ processNewMsg(receivedMsg, handler);
+ }
}
}
} catch (Exception e) {
@@ -852,11 +841,9 @@ public class Wechat {
private void processNewMsg(ReceivedMsg msg, ReceivedMsgHandler handler) {
try {
- if (handler != null) {
- handler.handleAllType(wechat, msg);
- }
+ handler.handleAllType(wechat, msg);
} catch (Exception e) {
-
+ logger.error("Execute processNewMsg error.", e);
}
}
}
@@ -897,6 +884,10 @@ public class Wechat {
return loginUser;
}
+ public UserInfo getLoginUser() {
+ return getLoginUser(false);
+ }
+
/**
* 获取登录用户名
*
@@ -910,6 +901,10 @@ public class Wechat {
return loginUser.getUserName();
}
+ public String getLoginUserName() {
+ return getLoginUserName(false);
+ }
+
/**
* 获取登录用户的昵称
*
@@ -923,6 +918,10 @@ public class Wechat {
return loginUser.getNickName();
}
+ public String getLoginUserNickName() {
+ return getLoginUserNickName(false);
+ }
+
/**
* 获取SyncKey
*
@@ -1011,15 +1010,19 @@ public class Wechat {
return contactList;
}
+ public List getContactList() {
+ return getContactList(false);
+ }
+
/**
* 根据UserName获取联系人信息
*
* @param update
- * @param UserName
+ * @param userName
* @return
*/
- public UserInfo getContactByUserName(boolean update, String UserName) {
- if (StringUtil.isEmpty(UserName)) {
+ public UserInfo getContactByUserName(boolean update, String userName) {
+ if (StringUtil.isEmpty(userName)) {
return null;
}
@@ -1033,7 +1036,7 @@ public class Wechat {
continue;
}
- if (UserName.equals(userInfo.getUserName())) {
+ if (userName.equals(userInfo.getUserName())) {
return userInfo;
}
}
@@ -1041,15 +1044,19 @@ public class Wechat {
return null;
}
+ public UserInfo getContactByUserName(String userName) {
+ return getContactByUserName(false, userName);
+ }
+
/**
* 根据NickName获取联系人信息
*
* @param update
- * @param NickName
+ * @param nickName
* @return
*/
- public UserInfo getContactByNickName(boolean update, String NickName) {
- if (StringUtil.isEmpty(NickName)) {
+ public UserInfo getContactByNickName(boolean update, String nickName) {
+ if (StringUtil.isEmpty(nickName)) {
return null;
}
@@ -1063,7 +1070,7 @@ public class Wechat {
continue;
}
- if (NickName.equals(userInfo.getNickName())) {
+ if (nickName.equals(userInfo.getNickName())) {
return userInfo;
}
}
@@ -1071,15 +1078,19 @@ public class Wechat {
return null;
}
+ public UserInfo getContactByNickName(String nickName) {
+ return getContactByNickName(false, nickName);
+ }
+
/**
* 根据RemarkName获取联系人信息
*
* @param update
- * @param RemarkName
+ * @param remarkName
* @return
*/
- public UserInfo getContactByRemarkName(boolean update, String RemarkName) {
- if (StringUtil.isEmpty(RemarkName)) {
+ public UserInfo getContactByRemarkName(boolean update, String remarkName) {
+ if (StringUtil.isEmpty(remarkName)) {
return null;
}
@@ -1093,7 +1104,7 @@ public class Wechat {
continue;
}
- if (RemarkName.equals(userInfo.getRemarkName())) {
+ if (remarkName.equals(userInfo.getRemarkName())) {
return userInfo;
}
}
@@ -1101,6 +1112,10 @@ public class Wechat {
return null;
}
+ public UserInfo getContactByRemarkName(String remarkName) {
+ return getContactByRemarkName(false, remarkName);
+ }
+
/**
* 发送文本消息
*
diff --git a/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java b/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java
index 52dccee..e6ecc81 100644
--- a/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java
+++ b/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java
@@ -81,7 +81,7 @@ public class WebWeixinApi {
JSONObject result = new JSONObject();
result.put("code", code);
if (!"200".equals(code)) {
- result.put("msg", "返回code错误,请确认appid是否有效");
+ result.put("msg", "错误代码(" + code + "),请确认appid是否有效");
return result;
}
@@ -405,8 +405,8 @@ public class WebWeixinApi {
.render();
HttpGet httpGet = new HttpGet(url);
- RequestConfig config = RequestConfig.custom().
- setRedirectsEnabled(false)
+ RequestConfig config = RequestConfig.custom()
+ .setRedirectsEnabled(false)
.build();
httpGet.setConfig(config);
diff --git a/src/main/java/com/hotlcc/wechat4j/enums/SelectorEnum.java b/src/main/java/com/hotlcc/wechat4j/enums/SelectorEnum.java
index d994def..fe75108 100644
--- a/src/main/java/com/hotlcc/wechat4j/enums/SelectorEnum.java
+++ b/src/main/java/com/hotlcc/wechat4j/enums/SelectorEnum.java
@@ -4,6 +4,7 @@ public enum SelectorEnum {
SELECTOR_0(0, "正常"),
SELECTOR_2(2, "有新消息"),
SELECTOR_4(4, "目前发现修改了联系人备注会出现"),
+ SELECTOR_6(6, "目前不知道代表什么"),
SELECTOR_7(7, "手机操作了微信");
private int code;
diff --git a/src/main/java/com/hotlcc/wechat4j/model/AppInfo.java b/src/main/java/com/hotlcc/wechat4j/model/AppInfo.java
index 4a1649b..780f828 100644
--- a/src/main/java/com/hotlcc/wechat4j/model/AppInfo.java
+++ b/src/main/java/com/hotlcc/wechat4j/model/AppInfo.java
@@ -3,10 +3,12 @@ package com.hotlcc.wechat4j.model;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
+@Getter
public final class AppInfo {
private AppInfo() {
}
@@ -16,14 +18,6 @@ public final class AppInfo {
@JSONField(name = "AppID")
private String appID;
- public Integer getType() {
- return type;
- }
-
- public String getAppID() {
- return appID;
- }
-
public static AppInfo valueOf(JSONObject info) {
if (info == null) {
return null;
diff --git a/src/main/java/com/hotlcc/wechat4j/model/BaseRequest.java b/src/main/java/com/hotlcc/wechat4j/model/BaseRequest.java
index 9a609b0..9f77c74 100644
--- a/src/main/java/com/hotlcc/wechat4j/model/BaseRequest.java
+++ b/src/main/java/com/hotlcc/wechat4j/model/BaseRequest.java
@@ -2,10 +2,14 @@ package com.hotlcc.wechat4j.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.hotlcc.wechat4j.util.WechatUtil;
+import lombok.Getter;
+import lombok.Setter;
/**
* 基本请求模型
*/
+@Getter
+@Setter
public class BaseRequest {
public BaseRequest() {
}
@@ -29,36 +33,4 @@ public class BaseRequest {
private String skey;
@JSONField(name = "Uin")
private String uin;
-
- public String getDeviceID() {
- return deviceID;
- }
-
- public void setDeviceID(String deviceID) {
- deviceID = deviceID;
- }
-
- public String getSid() {
- return sid;
- }
-
- public void setSid(String sid) {
- sid = sid;
- }
-
- public String getSkey() {
- return skey;
- }
-
- public void setSkey(String skey) {
- skey = skey;
- }
-
- public String getUin() {
- return uin;
- }
-
- public void setUin(String uin) {
- uin = uin;
- }
}
diff --git a/src/main/java/com/hotlcc/wechat4j/model/ReceivedMsg.java b/src/main/java/com/hotlcc/wechat4j/model/ReceivedMsg.java
index 3a83100..d5d56be 100644
--- a/src/main/java/com/hotlcc/wechat4j/model/ReceivedMsg.java
+++ b/src/main/java/com/hotlcc/wechat4j/model/ReceivedMsg.java
@@ -3,10 +3,12 @@ package com.hotlcc.wechat4j.model;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
+@Getter
public final class ReceivedMsg {
private ReceivedMsg() {
}
@@ -68,118 +70,6 @@ public final class ReceivedMsg {
@JSONField(name = "FileSize")
private String fileSize;
- public Integer getSubMsgType() {
- return subMsgType;
- }
-
- public Long getVoiceLength() {
- return voiceLength;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public Long getImgHeight() {
- return imgHeight;
- }
-
- public String getToUserName() {
- return toUserName;
- }
-
- public Long getHasProductId() {
- return hasProductId;
- }
-
- public Integer getImgStatus() {
- return imgStatus;
- }
-
- public String getUrl() {
- return url;
- }
-
- public Integer getImgWidth() {
- return imgWidth;
- }
-
- public Integer getForwardFlag() {
- return forwardFlag;
- }
-
- public Integer getStatus() {
- return status;
- }
-
- public String getTicket() {
- return ticket;
- }
-
- public com.hotlcc.wechat4j.model.RecommendInfo getRecommendInfo() {
- return recommendInfo;
- }
-
- public Long getCreateTime() {
- return createTime;
- }
-
- public Long getNewMsgId() {
- return newMsgId;
- }
-
- public Integer getMsgType() {
- return msgType;
- }
-
- public String getEncryFileName() {
- return encryFileName;
- }
-
- public String getMsgId() {
- return msgId;
- }
-
- public Integer getStatusNotifyCode() {
- return statusNotifyCode;
- }
-
- public AppInfo getAppInfo() {
- return appInfo;
- }
-
- public Integer getAppMsgType() {
- return appMsgType;
- }
-
- public Long getPlayLength() {
- return playLength;
- }
-
- public String getMediaId() {
- return mediaId;
- }
-
- public String getContent() {
- return content;
- }
-
- public String getStatusNotifyUserName() {
- return statusNotifyUserName;
- }
-
- public String getFromUserName() {
- return fromUserName;
- }
-
- public String getOriContent() {
- return oriContent;
- }
-
- public String getFileSize() {
- return fileSize;
- }
-
public static ReceivedMsg valueOf(JSONObject msg) {
if (msg == null) {
return null;
diff --git a/src/main/java/com/hotlcc/wechat4j/model/RecommendInfo.java b/src/main/java/com/hotlcc/wechat4j/model/RecommendInfo.java
index 1cf5296..bbc177d 100644
--- a/src/main/java/com/hotlcc/wechat4j/model/RecommendInfo.java
+++ b/src/main/java/com/hotlcc/wechat4j/model/RecommendInfo.java
@@ -3,10 +3,12 @@ package com.hotlcc.wechat4j.model;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
+@Getter
public final class RecommendInfo {
private RecommendInfo() {
}
@@ -40,62 +42,6 @@ public final class RecommendInfo {
@JSONField(name = "VerifyFlag")
private Integer verifyFlag;
- public String getTicket() {
- return ticket;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public Integer getSex() {
- return sex;
- }
-
- public Integer getAttrStatus() {
- return attrStatus;
- }
-
- public String getCity() {
- return city;
- }
-
- public String getNickName() {
- return nickName;
- }
-
- public Integer getScene() {
- return scene;
- }
-
- public String getProvince() {
- return province;
- }
-
- public String getContent() {
- return content;
- }
-
- public String getAlias() {
- return alias;
- }
-
- public String getSignature() {
- return signature;
- }
-
- public Integer getOpCode() {
- return opCode;
- }
-
- public Long getQQNum() {
- return qqNum;
- }
-
- public Integer getVerifyFlag() {
- return verifyFlag;
- }
-
public static RecommendInfo valueOf(JSONObject info) {
if (info == null) {
return null;
diff --git a/src/main/java/com/hotlcc/wechat4j/model/UserInfo.java b/src/main/java/com/hotlcc/wechat4j/model/UserInfo.java
index 8f716a5..6eba56a 100644
--- a/src/main/java/com/hotlcc/wechat4j/model/UserInfo.java
+++ b/src/main/java/com/hotlcc/wechat4j/model/UserInfo.java
@@ -3,6 +3,7 @@ package com.hotlcc.wechat4j.model;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@@ -10,6 +11,7 @@ import java.util.List;
/**
* 微信用户信息
*/
+@Getter
public final class UserInfo {
private UserInfo() {
}
@@ -77,130 +79,6 @@ public final class UserInfo {
@JSONField(name = "UserName")
private String userName;
- public Long getUin() {
- return uin;
- }
-
- public String getNickName() {
- return nickName;
- }
-
- public String getHeadImgUrl() {
- return headImgUrl;
- }
-
- public Integer getContactFlag() {
- return contactFlag;
- }
-
- public Integer getMemberCount() {
- return memberCount;
- }
-
- public List getMemberList() {
- return memberList;
- }
-
- public String getRemarkName() {
- return remarkName;
- }
-
- public Integer getHideInputBarFlag() {
- return hideInputBarFlag;
- }
-
- public Integer getSex() {
- return sex;
- }
-
- public String getSignature() {
- return signature;
- }
-
- public Integer getVerifyFlag() {
- return verifyFlag;
- }
-
- public Long getOwnerUin() {
- return ownerUin;
- }
-
- public String getPYInitial() {
- return pyInitial;
- }
-
- public String getPYQuanPin() {
- return pyQuanPin;
- }
-
- public String getRemarkPYInitial() {
- return remarkPYInitial;
- }
-
- public String getRemarkPYQuanPin() {
- return remarkPYQuanPin;
- }
-
- public Integer getStarFriend() {
- return starFriend;
- }
-
- public Integer getAppAccountFlag() {
- return appAccountFlag;
- }
-
- public Integer getStatues() {
- return statues;
- }
-
- public Integer getAttrStatus() {
- return attrStatus;
- }
-
- public String getProvince() {
- return province;
- }
-
- public String getCity() {
- return city;
- }
-
- public String getAlias() {
- return alias;
- }
-
- public Integer getSnsFlag() {
- return snsFlag;
- }
-
- public Integer getUniFriend() {
- return uniFriend;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public Long getChatRoomId() {
- return chatRoomId;
- }
-
- public String getKeyWord() {
- return keyWord;
- }
-
- public String getEncryChatRoomId() {
- return encryChatRoomId;
- }
-
- public Integer getIsOwner() {
- return isOwner;
- }
-
- public String getUserName() {
- return userName;
- }
-
public static UserInfo valueOf(JSONObject info) {
if (info == null) {
return null;
diff --git a/src/main/java/com/hotlcc/wechat4j/model/WxMessage.java b/src/main/java/com/hotlcc/wechat4j/model/WxMessage.java
index 8f275a6..05db641 100644
--- a/src/main/java/com/hotlcc/wechat4j/model/WxMessage.java
+++ b/src/main/java/com/hotlcc/wechat4j/model/WxMessage.java
@@ -1,10 +1,14 @@
package com.hotlcc.wechat4j.model;
import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Getter;
+import lombok.Setter;
/**
* 要发送的消息
*/
+@Getter
+@Setter
public class WxMessage {
@JSONField(name = "ClientMsgId")
private String clientMsgId;
@@ -18,52 +22,4 @@ public class WxMessage {
private String toUserName;
@JSONField(name = "Type")
private Integer type;
-
- public String getClientMsgId() {
- return clientMsgId;
- }
-
- public void setClientMsgId(String clientMsgId) {
- this.clientMsgId = clientMsgId;
- }
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public String getFromUserName() {
- return fromUserName;
- }
-
- public void setFromUserName(String fromUserName) {
- this.fromUserName = fromUserName;
- }
-
- public String getLocalID() {
- return localID;
- }
-
- public void setLocalID(String localID) {
- this.localID = localID;
- }
-
- public String getToUserName() {
- return toUserName;
- }
-
- public void setToUserName(String toUserName) {
- this.toUserName = toUserName;
- }
-
- public Integer getType() {
- return type;
- }
-
- public void setType(Integer type) {
- this.type = type;
- }
}
diff --git a/src/main/java/com/hotlcc/wechat4j/util/PropertiesUtil.java b/src/main/java/com/hotlcc/wechat4j/util/PropertiesUtil.java
index c1aaa4c..b0a2830 100644
--- a/src/main/java/com/hotlcc/wechat4j/util/PropertiesUtil.java
+++ b/src/main/java/com/hotlcc/wechat4j/util/PropertiesUtil.java
@@ -17,8 +17,8 @@ public final class PropertiesUtil {
static {
loadProperties(new String[]{
- "config/app.properties",
- "config/webwx-url.properties"
+ "META-INF/wechat4j/app.properties",
+ "META-INF/wechat4j/webwx-url.properties"
});
}
diff --git a/src/main/resources/config/app.properties b/src/main/resources/META-INF/wechat4j/app.properties
similarity index 100%
rename from src/main/resources/config/app.properties
rename to src/main/resources/META-INF/wechat4j/app.properties
diff --git a/src/main/resources/config/webwx-url.properties b/src/main/resources/META-INF/wechat4j/webwx-url.properties
similarity index 100%
rename from src/main/resources/config/webwx-url.properties
rename to src/main/resources/META-INF/wechat4j/webwx-url.properties
diff --git a/src/test/java/TestClass2.java b/src/test/java/TestClass2.java
index b6c6a4d..dbae62a 100644
--- a/src/test/java/TestClass2.java
+++ b/src/test/java/TestClass2.java
@@ -4,6 +4,7 @@ import com.hotlcc.wechat4j.api.WebWeixinApi;
import com.hotlcc.wechat4j.handler.ReceivedMsgHandler;
import com.hotlcc.wechat4j.model.ReceivedMsg;
import com.hotlcc.wechat4j.model.UserInfo;
+import com.sun.scenario.effect.GaussianShadow;
public class TestClass2 {
public static void main(String[] args) {
@@ -22,5 +23,9 @@ public class TestClass2 {
}
});
wechat.autoLogin();
+ UserInfo userInfo = wechat.getContactByNickName(false, "Allen");
+ System.out.println(JSONObject.toJSONString(userInfo));
+ wechat.sendText("aaa", userInfo.getUserName());
+ wechat.logout();
}
}