2
0
mirror of https://gitee.com/hotlcc/wechat4j.git synced 2025-06-08 11:34:07 +08:00

提交代码

This commit is contained in:
hotlcc 2018-07-24 09:50:23 +08:00
parent 4865ad6049
commit fb0d2dd95a

View File

@ -291,19 +291,8 @@ public class Wechat {
return false; return false;
} }
try { loginUser = result.getJSONObject("User");
loginUserLock.lock(); SyncKey = result.getJSONObject("SyncKey");
loginUser = result.getJSONObject("User");
} finally {
loginUserLock.unlock();
}
try {
SyncKeyLock.lock();
SyncKey = result.getJSONObject("SyncKey");
} finally {
SyncKeyLock.unlock();
}
return true; return true;
} }
@ -402,7 +391,7 @@ public class Wechat {
ps.flush(); ps.flush();
} }
ps.println("微信登录成功,欢迎你:" + getLoginUserNickName()); ps.println("微信登录成功,欢迎你:" + getLoginUserNickName(false));
ps.flush(); ps.flush();
return true; return true;
@ -432,47 +421,98 @@ public class Wechat {
*/ */
public JSONObject getLoginUser(boolean update) { public JSONObject getLoginUser(boolean update) {
if (loginUser == null || update) { if (loginUser == null || update) {
JSONObject result = webWeixinApi.webWeixinInit(httpClient, passTicket, wxsid, skey, wxuin);
if (result == null) {
return loginUser;
}
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
if (result == null) {
return loginUser;
}
int Ret = BaseResponse.getIntValue("Ret");
if (Ret != 0) {
return loginUser;
}
try { try {
loginUserLock.lock(); loginUserLock.lock();
if (loginUser == null || update) { if (loginUser == null || update) {
JSONObject result = webWeixinApi.webWeixinInit(httpClient, passTicket, wxsid, skey, wxuin);
if (result == null) {
return loginUser;
}
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
if (result == null) {
return loginUser;
}
int Ret = BaseResponse.getIntValue("Ret");
if (Ret != 0) {
return loginUser;
}
loginUser = result.getJSONObject("User"); loginUser = result.getJSONObject("User");
return loginUser;
} }
} finally { } finally {
loginUserLock.unlock(); loginUserLock.unlock();
} }
return loginUser;
} }
return loginUser; return loginUser;
} }
/**
* 获取登录用户名
*
* @return
*/
public String getLoginUserName(boolean update) {
JSONObject loginUser = getLoginUser(update);
if (loginUser == null) {
return null;
}
return loginUser.getString("UserName");
}
/** /**
* 获取登录用户的昵称 * 获取登录用户的昵称
* *
* @return * @return
*/ */
public String getLoginUserNickName() { public String getLoginUserNickName(boolean update) {
JSONObject loginUser = getLoginUser(false); JSONObject loginUser = getLoginUser(update);
if (loginUser == null) { if (loginUser == null) {
return null; return null;
} }
return loginUser.getString("NickName"); return loginUser.getString("NickName");
} }
/**
* 获取SyncKey
*
* @param update
* @return
*/
public JSONObject getSyncKey(boolean update) {
if (SyncKey == null || update) {
JSONObject result = webWeixinApi.webWeixinInit(httpClient, passTicket, wxsid, skey, wxuin);
if (result == null) {
return SyncKey;
}
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
if (result == null) {
return SyncKey;
}
int Ret = BaseResponse.getIntValue("Ret");
if (Ret != 0) {
return SyncKey;
}
try {
SyncKeyLock.lock();
if (SyncKey == null || update) {
SyncKey = result.getJSONObject("SyncKey");
}
} finally {
SyncKeyLock.unlock();
}
return SyncKey;
}
return SyncKey;
}
/** /**
* 获取联系人列表 * 获取联系人列表
* *
@ -481,33 +521,38 @@ public class Wechat {
*/ */
public JSONArray getContactList(boolean update) { public JSONArray getContactList(boolean update) {
if (ContactList == null || update) { if (ContactList == null || update) {
JSONObject result = webWeixinApi.getContact(httpClient, passTicket, skey);
if (result == null) {
return ContactList;
}
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
if (BaseResponse == null) {
return ContactList;
}
String Ret = BaseResponse.getString("Ret");
if (!"0".equals(Ret)) {
return ContactList;
}
try { try {
ContactListLock.lock(); ContactListLock.lock();
if (ContactList == null || update) { if (ContactList == null || update) {
JSONObject result = webWeixinApi.getContact(httpClient, passTicket, skey);
if (result == null) {
return ContactList;
}
JSONObject BaseResponse = result.getJSONObject("BaseResponse");
if (BaseResponse == null) {
return ContactList;
}
String Ret = BaseResponse.getString("Ret");
if (!"0".equals(Ret)) {
return ContactList;
}
ContactList = result.getJSONArray("MemberList"); ContactList = result.getJSONArray("MemberList");
return ContactList;
} }
} finally { } finally {
ContactListLock.unlock(); ContactListLock.unlock();
} }
return ContactList;
} }
return ContactList; return ContactList;
} }
public void test() { public void test() {
JSONObject result = webWeixinApi.getContact(httpClient, passTicket, skey); System.out.println(SyncKey);
JSONObject result = webWeixinApi.webWeixinInit(httpClient, passTicket, wxsid, skey, wxuin);
System.out.println(result); System.out.println(result);
} }
} }