微信开发 Java SDK,支持微信支付、开放平台、公众号、视频号、企业微信、小程序等的后端开发,记得关注公众号及时接受版本更新信息,以及加入微信群进行深入讨论
Go to file
2014-08-28 16:56:15 +08:00
src update 2014-08-28 15:07:52 +08:00
.gitignore ignore 2014-08-28 08:37:34 +08:00
LICENSE Initial commit 2014-08-18 16:11:26 +08:00
pom.xml 打包时同时打source和javadoc 2014-08-27 19:03:03 +08:00
README.md Update README.md 2014-08-28 16:56:15 +08:00

weixin-java-tools

微信java开发工具集本项目主要分为两大块微信消息路由器、微信Java API

特性列表:

  1. 不基于Servlet、和其他MVC框架仅作为工具使用提供更多的灵活性
  2. 详尽的单元测试代码可以拿来当example用
  3. 详尽的javadoc
  4. access token过期自动刷新的功能
  5. 微信服务端繁忙自动重试的功能
  6. 提供微信错误信息的异常处理机制

Quickstart

打包

如果你可以跳过单元测试直接打包:

mvn clean install -Dmaven.test.skip=true

如果你需要执行本项目的单元测试代码,那么你需要将 src/test/resources/test-config.sample.xml 改成 test-config.xml 并设置appId, secret, accessToken(可选), openId然后执行

mvn clean install

在你的maven项目中添加

<dependency>
  <groupId>chanjarster.weixin</groupId>
  <artifactId>weixin-java-tools</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

Hello World

WxConfigStorage config = new WxInMemoryConfigStorage();
config.setAppId(...); // 设置微信公众号的appid
config.setSecret(...); // 设置微信公众号的app secret
config.setToken(...); // 设置微信公众号的token

WxServiceImpl wxService = new WxServiceImpl();
wxService.setWxConfigStorage(config);

// 用户的openid在下面地址获得 
// https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=用户管理&form=获取关注者列表接口%20/user/get 
String openid = ...; 
WxCustomMessage message = WxCustomMessage.TEXT().toUser(openid).content("Hello World").build();
wxService.customMessageSend(message);