为微信开发者提供快速接入方案、未依赖任何第三方mvc框架,支持所用java web 框架接入。
Maven引用
<dependency> <groupId>com.ofsoft</groupId> <artifactId>of-weixin-api</artifactId> <version>0.0.1-RELEASES</version> </dependency>
文档地址: https://gitee.com/oufu/of-weixin-api/wikis
Spring mvc
@Controller public class WeiXinAction extends MessageController { //入口 @RequestMapping(value = ”/wx/index”) public void index(HttpServletRequest request, HttpServletResponse response) { Dispatcher.doDispatch(request, response, this); }
@Override public MessageResponse textTypeMsg(MessageRequest params) { TextMessage msg = new TextMessage(); msg.setContent(params.getParam("Content")); return msg; }
}
Jfinal
@Action(path = ”/wx”) public class WeixinController extends BaseController { //入口 public void index() { Dispatcher.doDispatch(getRequest(), getResponse(),new DefaultController()); renderNull(); }
Servlet 配置
@WebServlet(name = “coreInit”, loadOnStartup = 1, urlPatterns = { ”/wx/sing.html” }) public class Init extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void init(ServletConfig config) throws ServletException { // 设置配置信息 // AppConfig.setConfig(appid, appSecret, token); AppConfig.getInstance().init(new DefaultController()); } //入口 @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Dispatcher.doDispatch(request, response); }
} 4.自定义类继承MessageController 实现自己需求的方法
public class DefaultController extends MessageController {
@Override public MessageResponse textTypeMsg(MessageRequest params) { TextMessage msg = new TextMessage(); msg.setContent("测试"); return msg; }
作者博客 http://blog.csdn.net/oufua 欢迎大家完善!