JFinal Weixin 1.2 主要添加了对多公众号账户的支持,并对原有代码进行小幅重构,具体变化如下:
改进内容: 添加 ApiConfigKit,便于将 ApiConfig 对象与当前线程进行绑定,方便在各处通过 ApiConfigKit.getApiConfig() 进行获取 原有 ApiCofig 对象中的所有属性与方法去掉 static 关键字 WeixinController 更名为 MsgController,WeixinInterceptor 更名为 MsgInterceptor 添加 ApiController、ApiInterceptor 所有对 ApiConfig 静态方法有依赖的地方改为:ApiConfigKit.getApiConfig() 获取对象后再获取属性值,以便支持多公众号账户 demo重构:DemoController 更名为 WeixinMsgController,ApiController更名为WeixinApiController WeixinConfig 中的路由配置 "/weixin" 改为 "/msg"
升级步骤: 引入新版本 jar 包 jfinal-weixin-1.2-bin-with-src.jar 原来继承自 WeixinController 的类改为继承 MsgController 需要使用 ApiConfig 的自定义 controller 需要继承自 ApiController 去掉YourJFinalConfig 中原来对 ApiConfig 的配置,改而实现控制中的 getApiConfig() 方法 原来对 ApiConfig 静态方法的依赖改为通过 ApiConfigKit.getApiConfig() 获取对象后再获取相关属性 使用 ApiConfigKit.setDevMode(true) 输出消息交互时的xml与json
多公众号支持的建议方案: 创建数据库表 api_config(weixinId, token, appId, appSecret, encodingAesKey, messageEncrypt) 多公众号的微信服务器 url 格式设置为:http://域名/msg?weixinId=123,其中 weixinId 对应 api_config 数据库表中的 weixinId 在 MsgController 继承类中的 getApiConfig() 中动态获取并返回相应的 ApiConfig 对象
1 2 3 4 5 6 7 | public ApiConfig getApiConfig() {
Record r = Db.findFrist( "select * from api_config where weixinId=? limit 1" ,
getPara( "weixinId" ));
return new ApiConfig(r.get( "token" ), r.get( "appId" ),
r.get( "appSecret" ), r.get( "encodingAesKey" ),
r.get( "messageEncrypt" ));
}
|
One More Thing,JFinal 官方微信又一大波美女来袭,扫描下方二维码可立即查看,我们只看美女 ^_^ |