|
@@ -0,0 +1,154 @@
|
|
|
+/**
|
|
|
+ * Copyright (c) 2017-2019, lt 北京中世康恺科技有限公司 (www.pacsonline.cn).
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
+ */
|
|
|
+
|
|
|
+package com.zskk.common;
|
|
|
+
|
|
|
+import com.jfinal.config.Constants;
|
|
|
+import com.jfinal.config.Handlers;
|
|
|
+import com.jfinal.config.Interceptors;
|
|
|
+import com.jfinal.config.JFinalConfig;
|
|
|
+import com.jfinal.config.Plugins;
|
|
|
+import com.jfinal.config.Routes;
|
|
|
+import com.jfinal.kit.PropKit;
|
|
|
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
+import com.jfinal.plugin.druid.DruidPlugin;
|
|
|
+import com.jfinal.plugin.redis.RedisPlugin;
|
|
|
+import com.jfinal.plugin.redis.serializer.JdkSerializer;
|
|
|
+import com.jfinal.template.Engine;
|
|
|
+import com.jfinal.weixin.sdk.api.ApiConfig;
|
|
|
+import com.jfinal.weixin.sdk.api.ApiConfigKit;
|
|
|
+import com.jfinal.weixin.sdk.cache.RedisAccessTokenCache;
|
|
|
+import com.jfinal.wxaapp.WxaConfig;
|
|
|
+import com.jfinal.wxaapp.WxaConfigKit;
|
|
|
+
|
|
|
+
|
|
|
+public class ZskkConfig extends JFinalConfig {
|
|
|
+ // 本地开发模式
|
|
|
+ private boolean isLocalDev = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如果生产环境配置文件存在,则优先加载该配置,否则加载开发环境配置文件
|
|
|
+ *
|
|
|
+ * @param pro 生产环境配置文件
|
|
|
+ * @param dev 开发环境配置文件
|
|
|
+ */
|
|
|
+ public void loadProp(String pro, String dev) {
|
|
|
+ try {
|
|
|
+ PropKit.use(pro);
|
|
|
+ } catch (Exception e) {
|
|
|
+ PropKit.use(dev);
|
|
|
+ isLocalDev = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void configConstant(Constants me) {
|
|
|
+ loadProp("config.properties", "a_little_config.txt");
|
|
|
+ me.setDevMode(PropKit.getBoolean("devMode", false));
|
|
|
+
|
|
|
+ // ApiConfigKit 设为开发模式可以在开发阶段输出请求交互的 xml 与 json 数据
|
|
|
+ ApiConfigKit.setDevMode(me.getDevMode());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void configRoute(Routes me) {
|
|
|
+ /**
|
|
|
+ * jfinal 3.6 新添加的配置项,如果有控制器继承了 MsgController 就必须 要添加下面的配置,该配置才能将超类
|
|
|
+ * MsgController 中的 index() 方法 映射为 action
|
|
|
+ *
|
|
|
+ * 使用 jfinal 3.6 之前的版本不必理会这项配置
|
|
|
+ */
|
|
|
+ me.setMappingSuperClass(true);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void configPlugin(Plugins me) {
|
|
|
+
|
|
|
+ DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
|
|
|
+ PropKit.get("password").trim());
|
|
|
+ me.add(druidPlugin);
|
|
|
+
|
|
|
+ ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
|
|
|
+ me.add(arp);
|
|
|
+
|
|
|
+ // 所有配置在 MappingKit 中搞定
|
|
|
+// _MappingKit.mapping(arp);
|
|
|
+
|
|
|
+ // 使用redis分布accessToken
|
|
|
+ RedisPlugin redisPlugin = new RedisPlugin("weixin_doctor", "10.46.159.65", 6379, 2000, "Zskk_2019", 2);
|
|
|
+ redisPlugin.setSerializer(JdkSerializer.me); // 需要使用fst高性能序列化的用户请删除这一行(Fst jar依赖请查看WIKI)
|
|
|
+ me.add(redisPlugin);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void configInterceptor(Interceptors me) {
|
|
|
+ // 设置默认的 appId 规则,默认值为appId,可采用url挂参数 ?appId=xxx 切换多公众号
|
|
|
+// ApiInterceptor.setAppIdParser(new AppIdParser.DefaultParameterAppIdParser("appId")); 默认无需设置
|
|
|
+// MsgInterceptor.setAppIdParser(new AppIdParser.DefaultParameterAppIdParser("appId")); 默认无需设置
|
|
|
+ }
|
|
|
+
|
|
|
+ public void configHandler(Handlers me) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStart() {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ super.onStart();
|
|
|
+ // 支持redis存储access_token、js_ticket,需要先启动RedisPlugin
|
|
|
+ ApiConfigKit.setAccessTokenCache(new RedisAccessTokenCache("weixin_patient"));
|
|
|
+ // 中世康恺电子胶片平台
|
|
|
+ ApiConfig ac_zskk = new ApiConfig();
|
|
|
+ // 配置微信 API 相关参数
|
|
|
+ ac_zskk.setToken(PropKit.get("token_zskk"));
|
|
|
+ ac_zskk.setAppId(PropKit.get("appId_zskk"));
|
|
|
+ ac_zskk.setAppSecret(PropKit.get("appSecret_zskk"));
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否对消息进行加密,对应于微信平台的消息加解密方式: 1:true进行加密且必须配置 encodingAesKey
|
|
|
+ * 2:false采用明文模式,同时也支持混合模式
|
|
|
+ */
|
|
|
+ ac_zskk.setEncryptMessage(Boolean.FALSE);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多个公众号时,重复调用ApiConfigKit.putApiConfig(ac)依次添加即可,第一个添加的是默认。
|
|
|
+ */
|
|
|
+
|
|
|
+ ApiConfigKit.putApiConfig(ac_zskk);
|
|
|
+
|
|
|
+ WxaConfig wc = new WxaConfig();
|
|
|
+ wc.setAppId(PropKit.get("appId_xtzd"));
|
|
|
+ wc.setAppSecret(PropKit.get("appSecret_xtzd"));
|
|
|
+ WxaConfigKit.setWxaConfig(wc);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 1.9 新增LocalTestTokenCache用于本地和线上同时使用一套appId时避免本地将线上AccessToken冲掉
|
|
|
+ *
|
|
|
+ * 设计初衷:https://www.oschina.net/question/2702126_2237352
|
|
|
+ *
|
|
|
+ * 注意: 1. 上线时应保证此处isLocalDev为false,或者注释掉该不分代码!
|
|
|
+ *
|
|
|
+ * 2. 为了安全起见,此处可以自己添加密钥之类的参数,例如:
|
|
|
+ * http://localhost/weixin/api/getToken?secret=xxxx
|
|
|
+ * 然后在WeixinApiController#getToken()方法中判断secret
|
|
|
+ *
|
|
|
+ * @see WeixinApiController#getToken()
|
|
|
+ */
|
|
|
+// if (isLocalDev) {
|
|
|
+// String onLineTokenUrl = "http://localhost/weixin/api/getToken";
|
|
|
+// ApiConfigKit.setAccessTokenCache(new LocalTestTokenCache(onLineTokenUrl));
|
|
|
+// }
|
|
|
+// ServiceFactory.init();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// public static void main(String[] args) {
|
|
|
+// JFinal.start("src/main/webapp", 10000, "/", 5);
|
|
|
+// }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void configEngine(Engine engine) {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|