Skip to content

Commit

Permalink
主要修正了 #1 号问题:缓存的 Session 不起作用的问题(说白了还是未提供 Cookie 的问题);尝试修正新加入的群成员发消息时…
Browse files Browse the repository at this point in the history
…,日志输出时取不到人名的问题;另外,针对问题 #7 号问题做了优化:把空 Content 当 XML 数据解析时不再报异常。
  • Loading branch information
moontide committed May 16, 2017
1 parent 5729aa6 commit b223f89
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 64 deletions.
23 changes: 18 additions & 5 deletions src/net_maclife_wechat_http_BotApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public static Configuration GetConfig ()
fMediaFilesDirectory.mkdirs ();
}

public static String sSessionCacheFileName = cacheDirectory + File.separator + "wechat-session-cache.json";
public static String sCookiesCacheFileName = cacheDirectory + File.separator + "wechat-cookie-cache.json";

static ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
static ScriptEngine public_jse = scriptEngineManager.getEngineByName("JavaScript");
Expand Down Expand Up @@ -840,7 +842,7 @@ public static JsonNode MakeFullGetRoomContactRequestJsonNode (String sUserID, St
return on;
}

public static JsonNode WebWeChatGetRoomContacts (String sUserID, String sSessionID, String sSessionKey, String sPassTicket, List<String> listRoomAccounts) throws JsonProcessingException, IOException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException
public static JsonNode WebWeChatGetRoomsContacts (String sUserID, String sSessionID, String sSessionKey, String sPassTicket, List<String> listRoomAccounts) throws JsonProcessingException, IOException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException
{
logger.info ("获取 " + listRoomAccounts.size () + " 个聊天室的联系人 …");
String sURL = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact?type=ex&r=" + System.currentTimeMillis () + "&lang=zh_CN&pass_ticket=" + sPassTicket;
Expand Down Expand Up @@ -1002,14 +1004,14 @@ else if (StringUtils.isNotEmpty (sNickName))
}

/**
* 查找
* 搜索并返回符合条件的第一个联系人,如果没有搜到符合条件的联系人,则返回 <code>null</code>。
* @param jsonMemberList
* @param sEncryptedAccountInThisSession
* @param sAlias
* @param sRemarkName
* @param sDisplayName
* @param sNickName
* @return
* @return 返回符合条件的第一个联系人,如果没有搜到符合条件的联系人,则返回 <code>null</code>
*/
public static JsonNode SearchForSingleContact (JsonNode jsonMemberList, String sEncryptedAccountInThisSession, String sAlias, String sRemarkName, String sDisplayName, String sNickName)
{
Expand Down Expand Up @@ -1964,7 +1966,7 @@ public static String GetJSONText (JsonNode node, String sFieldName, String sDefa
{
if (node==null || node.get (sFieldName)==null)
return sDefault;
return node.get (sFieldName).asText ();
return node.get (sFieldName).asText (sDefault);
}
public static String GetJSONText (JsonNode node, String sFieldName)
{
Expand All @@ -1975,13 +1977,24 @@ public static int GetJSONInt (JsonNode node, String sFieldName, int nDefault)
{
if (node==null || node.get (sFieldName)==null)
return nDefault;
return node.get (sFieldName).asInt ();
return node.get (sFieldName).asInt (nDefault);
}
public static int GetJSONInt (JsonNode node, String sFieldName)
{
return GetJSONInt (node, sFieldName, -1);
}

public static long GetJSONLong (JsonNode node, String sFieldName, long nDefault)
{
if (node==null || node.get (sFieldName)==null)
return nDefault;
return node.get (sFieldName).asLong (nDefault);
}
public static long GetJSONLong (JsonNode node, String sFieldName)
{
return GetJSONLong (node, sFieldName, -1L);
}


public static String GetXMLValue (Element element, String sFirstChildElementName, String sDefault)
{
Expand Down
Loading

0 comments on commit b223f89

Please sign in to comment.