Files
weixin-java-tools/README.md
2014-08-22 14:25:05 +08:00

49 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

weixin-tools
===========
微信java开发工具本项目提供了两个主要特性微信消息路由器、微信Java API
## 微信消息路由器
你可以使用``WxMessageRouter``来对微信推送过来的消息、事件进行路由,交给特定的``WxMessageHandler``处理。
使用方法:
```java
WxMessageRouter router = new WxMessageRouter();
router
.rule()
.msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
.interceptor(interceptor, ...).handler(handler, ...)
.end()
.rule()
// 另外一个匹配规则
.end()
;
// 将WxXmlMessage交给消息路由器
router.route(message);
```
1. 开发人员需实现自己的``WxMessageHandler``和``WxMessageInterceptor``
1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理
2. 默认情况下消息只会被处理一次,除非使用 ``WxMessageRouter#Rule#next()``
3. 规则的结束必须用``WxMessageRouter#Rule#end()``或者``WxMessageRouter#Rule#next()``,否则不会生效
## 微信Java API
使用``WxService``可以调用微信API。目前实现了以下功能其余功能以后陆续补充
1. 发送客服消息
1. 创建自定义菜单
1. 删除自定义菜单
1. 查询自定义菜单
1. 刷新access_token
## 如何执行单元测试
将 ``src/test/resources/test-config.sample.xml`` 改成 ``test-config.xml`` 设置appId, secret, accessToken(可选), openId
```bash
mvn clean test
```