发布于 2014-10-21 04:31:54 | 201 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

JFinal 基于Java极速WEB+ORM 框架

JFinal 是基于 Java 语言的极速 WEB + ORM 框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥有ruby、python、php等动态语言的开发效率!为您节约更多时间


JFinal Weixin 是基于 JFinal 的微信公众号极速 SDK,只需参考 Demo 代码即可进行极速开发。

1、WeixinConfig

public class WeixinConfig extends JFinalConfig {
  public void configConstant(Constants me) {
    loadPropertyFile("a_little_config.txt");
    me.setDevMode(getPropertyToBoolean("devMode", false));
		
    // 配置微信 API 相关常量
    ApiConfig.setDevMode(me.getDevMode());
    ApiConfig.setUrl(getProperty("url"));
    ApiConfig.setToken(getProperty("token"));
    ApiConfig.setAppId(getProperty("appId"));
    ApiConfig.setAppSecret(getProperty("appSecret"));
  }
	
  public void configRoute(Routes me) {
    me.add("/weixin", DemoController.class);
    me.add("/api", ApiController.class, "/api");
  }
	
  public void configPlugin(Plugins me) {}
  public void configInterceptor(Interceptors me) {}
  public void configHandler(Handlers me) {}
}

通过 ApiConfig 提供 Weixin 公众平台所需的相关配置,并在configRoute 方法配置路由。

2、DemoController

public class DemoController extends WeixinController {
  protected void processInTextMsg(InTextMsg inTextMsg) {
   String msgContent = inTextMsg.getContent().trim();
   // 帮助提示
   if ("help".equalsIgnoreCase(msgContent)) {
     OutTextMsg outMsg = new OutTextMsg(inTextMsg);
     outMsg.setContent(helpStr);
     render(outMsg);
   }	
   else if ("美女".equalsIgnoreCase(msgContent)) {
     OutNewsMsg outMsg = new OutNewsMsg(inTextMsg);
     outMsg.addNews("秀色可餐", "JFinal Weixin 极速开发就是这么爽,有木有 ^_^", "http://mmbiz.qpic.cn/mmbiz/zz3Q6WSrzq2GJLC60ECD7rE7n1cvKWRNFvOyib4KGdic3N5APUWf4ia3LLPxJrtyIYRx93aPNkDtib3ADvdaBXmZJg/0", "http://mp.weixin.qq.com/s?__biz=MjM5ODAwOTU3Mg==&mid=200987822&idx=1&sn=7eb2918275fb0fa7b520768854fb7b80#rd");
     render(outMsg);
   }
   // 其它文本消息直接返回原值 + 帮助提示
   else {
     OutTextMsg outMsg = new OutTextMsg(inTextMsg);
     outMsg.setContent("t文本消息已成功接收,内容为: " + inTextMsg.getContent() + "nn" + helpStr);
     render(outMsg);
   }
  }

  protected void processInImageMsg(InImageMsg inImageMsg) {
    OutImageMsg outMsg = new OutImageMsg(inImageMsg);
    // 将刚发过来的图片再发回去
    outMsg.setMediaId(inImageMsg.getMediaId());
    render(outMsg);
  }
  
  // 其她自动接收并解析消息的便利方法省略
}

DemoController 通过继承自 WeixinController 便拥有了接收消息和发送消息的便利方法。

3、ApiController

public class ApiController extends Controller {
  public void index() {
    render("/api/index.html");
  }
	
  /**
  * 获取公众号菜单
  */
  public void getMenu() {
    ApiResult apiResult = MenuApi.getMenu();
    if (apiResult.isSucceed())
      renderText(apiResult.getJson());
    else
      renderText(apiResult.getErrorMsg());
    }
	
    /**
    * 获取公众号关注用户
    */
    public void getFollowers() {
      ApiResult apiResult = UserApi.getFollows();
      renderText(apiResult.getJson());
    }
}

通过调用 MenuApi、UserApi 等 Api 的相关方法即可获取封装成 ApiResult 对象的结果,使用 render 系列方法即可快捷输出结果。

4、更多支持

JFinal Weixin 官方网站:http://www.jfinal.com 

关注官方微信号马上体验 demo 功能:



历史版本 :
JFinal 3.3 发布,天下武功,唯快不破
Jboot 1.0-beta7 发布,基于 JFinal 的微服务框架
JFinal 3.2 发布,星星之火已成燎原之势
JFinal 3.1 发布,没有繁琐、没有复杂,只有妙不可言
JFinal 3.0 发布,重新定义模板引擎
jfinal cms v4.1.5 发布,祝大家新年快乐
jfinal cms v4.1.2 发布,加入博客模板
JFinal 2.2 发布,用 JFinal 开发,就这么定了!
Jflyfox 2.8 更新发布,jfinal+beetl 博客
Jflyfox 2.7 更新发布,jfinal+beetl博客
JFinal 2.1 最终版发布,用JFinal开发,就这么定了!
JFinal 2.1 发布,用 JFinal 开发,就这么定了!
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务