From 2144e6c9f9f1607d0b90027c0a0cb59196fc2458 Mon Sep 17 00:00:00 2001 From: hotlcc Date: Tue, 24 Jul 2018 10:01:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/hotlcc/wechat4j/Wechat.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/main/java/com/hotlcc/wechat4j/Wechat.java b/src/main/java/com/hotlcc/wechat4j/Wechat.java index e200ace..a4ac8c8 100644 --- a/src/main/java/com/hotlcc/wechat4j/Wechat.java +++ b/src/main/java/com/hotlcc/wechat4j/Wechat.java @@ -550,6 +550,99 @@ public class Wechat { return ContactList; } + /** + * 根据UserName获取联系人信息 + * + * @param update + * @param UserName + * @return + */ + public JSONObject getContactByUserName(boolean update, String UserName) { + if (StringUtil.isEmpty(UserName)) { + return null; + } + + JSONArray list = getContactList(update); + if (list == null) { + return null; + } + + for (int i = 0, len = list.size(); i < len; i++) { + JSONObject c = list.getJSONObject(i); + if (c == null) { + continue; + } + + if (UserName.equals(c.getString("UserName"))) { + return c; + } + } + + return null; + } + + /** + * 根据NickName获取联系人信息 + * + * @param update + * @param NickName + * @return + */ + public JSONObject getContactByNickName(boolean update, String NickName) { + if (StringUtil.isEmpty(NickName)) { + return null; + } + + JSONArray list = getContactList(update); + if (list == null) { + return null; + } + + for (int i = 0, len = list.size(); i < len; i++) { + JSONObject c = list.getJSONObject(i); + if (c == null) { + continue; + } + + if (NickName.equals(c.getString("NickName"))) { + return c; + } + } + + return null; + } + + /** + * 根据RemarkName获取联系人信息 + * + * @param update + * @param RemarkName + * @return + */ + public JSONObject getContactByRemarkName(boolean update, String RemarkName) { + if (StringUtil.isEmpty(RemarkName)) { + return null; + } + + JSONArray list = getContactList(update); + if (list == null) { + return null; + } + + for (int i = 0, len = list.size(); i < len; i++) { + JSONObject c = list.getJSONObject(i); + if (c == null) { + continue; + } + + if (RemarkName.equals(c.getString("RemarkName"))) { + return c; + } + } + + return null; + } + public void test() { System.out.println(SyncKey); JSONObject result = webWeixinApi.webWeixinInit(httpClient, passTicket, wxsid, skey, wxuin);