diff --git a/demo/.classpath b/demo/.classpath index 7e9d298..60df8fd 100644 --- a/demo/.classpath +++ b/demo/.classpath @@ -29,7 +29,7 @@ - + diff --git a/demo/.project b/demo/.project index 33e63d4..8f1a57c 100644 --- a/demo/.project +++ b/demo/.project @@ -21,12 +21,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/demo/.settings/org.eclipse.wst.common.component b/demo/.settings/org.eclipse.wst.common.component index 2f6df10..2b260b4 100644 --- a/demo/.settings/org.eclipse.wst.common.component +++ b/demo/.settings/org.eclipse.wst.common.component @@ -4,7 +4,6 @@ - diff --git a/demo/pom.xml b/demo/pom.xml index 22953af..da4a51a 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -40,5 +40,17 @@ demo + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + diff --git a/demo/src/main/java/wxtools/demo/servlet/DemoServlet.java b/demo/src/main/java/wxtools/demo/servlet/DemoServlet.java index 245c80a..b2ece33 100644 --- a/demo/src/main/java/wxtools/demo/servlet/DemoServlet.java +++ b/demo/src/main/java/wxtools/demo/servlet/DemoServlet.java @@ -40,11 +40,14 @@ public class DemoServlet extends HttpServlet { private static final long serialVersionUID = 1L; private WxConfigStorage config; private WxService service; + private WxMessageRouter router = null;//理论上,路由器只有一个。所以只初始化一次。 + //之前是有错误的。之前把router放进doPost里,会导致每个请求多初始化一次,线程池多初始化一次。 public DemoServlet() { config = WxInMemoryConfigStorage.getInstance(); service = WxServiceImpl.getInstance(); service.setWxConfigStorage(config); + router = new WxMessageRouter(WxServiceImpl.getInstance()); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -56,8 +59,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t if(WxServiceImpl.getInstance().checkSignature(signature, timestamp, nonce, echostr)){ out.print(echostr); } - - } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -73,7 +74,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) String XMLMessage = XStreamTransformer.toXml(WxXmlMessage.class, wx); System.out.println("消息(xml):\n "+XMLMessage); - WxMessageRouter router = new WxMessageRouter(WxServiceImpl.getInstance()); + //路由器在整个程序中只有一个。 router.rule().msgType(WxConsts.XML_MSG_TEXT).async(false).matcher(new DemoMatcher()).interceptor(new DemoInterceptor()).handler(new DemoMessageHandler()).end(); xmlOutMsg = router.route(wx); if(xmlOutMsg!=null) diff --git a/demo/src/main/webapp/WEB-INF/lib/wx-tools-1.0.0.jar b/demo/src/main/webapp/WEB-INF/lib/wx-tools-1.0.1.jar similarity index 86% rename from demo/src/main/webapp/WEB-INF/lib/wx-tools-1.0.0.jar rename to demo/src/main/webapp/WEB-INF/lib/wx-tools-1.0.1.jar index a7c553b..8a661d7 100644 Binary files a/demo/src/main/webapp/WEB-INF/lib/wx-tools-1.0.0.jar and b/demo/src/main/webapp/WEB-INF/lib/wx-tools-1.0.1.jar differ diff --git a/demo/src/main/webapp/WEB-INF/web.xml b/demo/src/main/webapp/WEB-INF/web.xml index fc591b6..39104d7 100644 --- a/demo/src/main/webapp/WEB-INF/web.xml +++ b/demo/src/main/webapp/WEB-INF/web.xml @@ -1,5 +1,9 @@ - + demo DemoInitListener diff --git a/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.properties b/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.properties index 1821a31..574a338 100644 --- a/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.properties +++ b/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Sun Jun 19 10:26:39 CST 2016 +#Sun Jul 10 14:49:35 CST 2016 version=1 groupId=wxtools.demo m2e.projectName=demo diff --git a/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.xml b/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.xml index 22953af..da4a51a 100644 --- a/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.xml +++ b/demo/target/m2e-wtp/web-resources/META-INF/maven/wxtools.demo/demo/pom.xml @@ -40,5 +40,17 @@ demo + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + diff --git a/java/src/main/java/com/soecode/wxtools/api/WxMessageInMemoryDuplicateChecker.java b/java/src/main/java/com/soecode/wxtools/api/WxMessageInMemoryDuplicateChecker.java index ce2894e..1f15add 100644 --- a/java/src/main/java/com/soecode/wxtools/api/WxMessageInMemoryDuplicateChecker.java +++ b/java/src/main/java/com/soecode/wxtools/api/WxMessageInMemoryDuplicateChecker.java @@ -6,7 +6,7 @@ /** *
- * 默认消息重复检查器
+ * 默认消息重试检查器
  * 将每个消息id保存在内存里,每隔5秒清理已经过期的消息id,每个消息id的过期时间是15秒
  * 
* @author antgan @@ -74,7 +74,7 @@ public void run() { Long now = System.currentTimeMillis(); for (Map.Entry entry : msgId2Timestamp.entrySet()) { if (now - entry.getValue() > timeToLive) { - msgId2Timestamp.entrySet().remove(entry); + msgId2Timestamp.entrySet().remove(entry); } } } diff --git a/java/src/main/java/com/soecode/wxtools/api/WxMessageRouter.java b/java/src/main/java/com/soecode/wxtools/api/WxMessageRouter.java index 0354314..4e7402f 100644 --- a/java/src/main/java/com/soecode/wxtools/api/WxMessageRouter.java +++ b/java/src/main/java/com/soecode/wxtools/api/WxMessageRouter.java @@ -115,6 +115,7 @@ public WxMessageRouterRule rule() { */ public WxXmlOutMessage route(final WxXmlMessage wxMessage) { if (isDuplicateMessage(wxMessage)) { + System.out.println("重复消息"); // 如果是重复消息,那么就不做处理 return null; } @@ -157,15 +158,15 @@ public void run() { } /** - * 验证是否重复消息 + * 验证重试消息 * @param wxMessage * @return */ protected boolean isDuplicateMessage(WxXmlMessage wxMessage) { String messageId = ""; if (wxMessage.getMsgId() == null) { - messageId = String.valueOf(wxMessage.getCreateTime()) + "-" - + wxMessage.getFromUserName() + "-" + messageId = String.valueOf(wxMessage.getToUserName()) + "-" + + wxMessage.getFromUserName() + "-"+wxMessage.getContent()+"-" + String.valueOf(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey()) + "-" + String.valueOf(wxMessage.getEvent() == null ? "" : wxMessage.getEvent()); } else { diff --git a/java/src/main/webapp/WEB-INF/web.xml b/java/src/main/webapp/WEB-INF/web.xml index 4760589..6038ef7 100644 --- a/java/src/main/webapp/WEB-INF/web.xml +++ b/java/src/main/webapp/WEB-INF/web.xml @@ -1,4 +1,5 @@ wx-tools + \ No newline at end of file diff --git a/java/target/classes/META-INF/maven/com.soecode.wx-tools/wx-tools/pom.properties b/java/target/classes/META-INF/maven/com.soecode.wx-tools/wx-tools/pom.properties index 4e514b6..255477f 100644 --- a/java/target/classes/META-INF/maven/com.soecode.wx-tools/wx-tools/pom.properties +++ b/java/target/classes/META-INF/maven/com.soecode.wx-tools/wx-tools/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Sun Jun 19 10:26:42 CST 2016 +#Sun Jul 10 14:49:38 CST 2016 version=1.0-SNAPSHOT groupId=com.soecode.wx-tools m2e.projectName=wx-tools diff --git a/lib/wx-tools-1.0.0.jar b/lib/wx-tools-1.0.1.jar similarity index 86% rename from lib/wx-tools-1.0.0.jar rename to lib/wx-tools-1.0.1.jar index a7c553b..8a661d7 100644 Binary files a/lib/wx-tools-1.0.0.jar and b/lib/wx-tools-1.0.1.jar differ