This commit is contained in:
jinyu 2016-06-08 15:23:36 +08:00
parent f24c594def
commit 57daea99a8
4 changed files with 28 additions and 22 deletions

View File

@ -81,9 +81,11 @@ public class RedisCacheStorager<T extends Cacheable> implements
jedis = jedisPool.getResource();
byte[] key = cacheKey.getBytes(Consts.UTF_8);
byte[] value = SerializationUtils.serialize(cache);
jedis.set(key, value);
if (cache.getExpires() > 0) {
jedis.expire(key, (int) (cache.getExpires() - CUTMS) / 1000);
jedis.setex(key, (int) (cache.getExpires() - CUTMS) / 1000,
value);
} else {
jedis.set(key, value);
}
jedis.sadd(ALLKEY, cacheKey);
} finally {

View File

@ -68,9 +68,11 @@ public class RedisClusterCacheStorager<T extends Cacheable> implements
public void caching(String cacheKey, T cache) {
byte[] key = cacheKey.getBytes(Consts.UTF_8);
byte[] value = SerializationUtils.serialize(cache);
jedisCluster.set(key, value);
if (cache.getExpires() > 0) {
jedisCluster.expire(key, (int) (cache.getExpires() - CUTMS) / 1000);
jedisCluster.setex(key, (int) (cache.getExpires() - CUTMS) / 1000,
value);
} else {
jedisCluster.set(key, value);
}
jedisCluster.sadd(ALLKEY, cacheKey);
}

View File

@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.util.ServerToolkits;
/**
* 微信消息
*
*
* @className MessageTransferHandler
* @author jinyu(foxinmy@gmail.com)
* @date 2015年5月17日
@ -49,18 +49,19 @@ public class MessageTransferHandler extends DefaultHandler {
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
nodeNames.add(localName.toLowerCase());
if (localName.equalsIgnoreCase("fromUserName")) {
nodeNames.add(localName);
localName = localName.toLowerCase();
if (localName.equals("fromusername")) {
fromUserName = content;
} else if (localName.equalsIgnoreCase("toUserName")) {
} else if (localName.equals("tousername")) {
toUserName = content;
} else if (localName.equalsIgnoreCase("msgType")) {
} else if (localName.equals("msgtype")) {
msgType = content.toLowerCase();
} else if (localName.equalsIgnoreCase("event")) {
} else if (localName.equals("event")) {
eventType = content.toLowerCase();
} else if (localName.startsWith("agent") // 应用信息
|| localName.startsWith("suite") // 套件信息
|| localName.equalsIgnoreCase("batchJob")) { // 批量任务
|| localName.equals("batchjob")) { // 批量任务
isQY = true;
}
}
@ -75,9 +76,10 @@ public class MessageTransferHandler extends DefaultHandler {
if (isQY) {
return AccountType.QY;
}
if (ServerToolkits.isBlank(msgType) && ServerToolkits.isBlank(eventType)) {
if (ServerToolkits.isBlank(msgType)
&& ServerToolkits.isBlank(eventType)) {
return null;
}
}
return AccountType.MP;
}

View File

@ -25,7 +25,7 @@ import com.foxinmy.weixin4j.startup.WeixinServerBootstrap;
/**
* 服务启动测试类
*
*
* @className MessageServerStartup
* @author jinyu(foxinmy@gmail.com)
* @date 2015年5月7日
@ -43,7 +43,7 @@ public class MessageServerStartup {
/**
* 调试输出用户发来的消息
*
*
* @throws WeixinException
*/
public void test1() throws WeixinException {
@ -51,13 +51,13 @@ public class MessageServerStartup {
new WeixinServerBootstrap(token).addHandler(DebugMessageHandler.global)
.startup();
// 密文模式
new WeixinServerBootstrap(weixinId, token, aesKey).addHandler(
DebugMessageHandler.global).startup();
// new WeixinServerBootstrap(weixinId, token, aesKey).addHandler(
// DebugMessageHandler.global).startup();
}
/**
* 针对特定消息类型
*
*
* @throws WeixinException
*/
public void test2() throws WeixinException {
@ -85,7 +85,7 @@ public class MessageServerStartup {
/**
* 多种消息类型处理
*
*
* @throws WeixinException
*/
public void test3() throws WeixinException {
@ -105,7 +105,7 @@ public class MessageServerStartup {
/**
* 扫描包添加handler
*
*
* @throws WeixinException
*/
public void test4() throws WeixinException {
@ -121,7 +121,7 @@ public class MessageServerStartup {
/**
* 拦截器应用
*
*
* @throws WeixinException
*/
public void test5() throws WeixinException {
@ -162,7 +162,7 @@ public class MessageServerStartup {
/**
* main方法入口
*
*
* @param args
* @throws Exception
*/