刘韬 %!s(int64=6) %!d(string=hai) anos
pai
achega
03782fa7b7

+ 6 - 0
PacsOnline_Wechat_Patient/pom.xml

@@ -61,6 +61,12 @@
 			<artifactId>jedis</artifactId>
 			<version>2.10.2</version>
 		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>javax.servlet-api</artifactId>
+			<version>4.0.1</version>
+			<scope>provided</scope>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 113 - 107
PacsOnline_Wechat_Patient/src/main/java/com/zskk/common/ZskkConfig.java

@@ -12,7 +12,6 @@ import com.jfinal.config.Interceptors;
 import com.jfinal.config.JFinalConfig;
 import com.jfinal.config.Plugins;
 import com.jfinal.config.Routes;
-import com.jfinal.core.JFinal;
 import com.jfinal.kit.PropKit;
 import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
 import com.jfinal.plugin.druid.DruidPlugin;
@@ -22,129 +21,136 @@ 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.zskk.service.ServiceFactory;
 import com.zskk.controller.WeixinApiController;
 import com.zskk.controller.WeixinMsgController;
+import com.zskk.controller.WeixinWebController;
 
 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);
-        
-        me.add("/msg", WeixinMsgController.class);
-        me.add("/api", WeixinApiController.class, "/api");
-//        me.add("/pay", WeixinPayController.class);
-//        me.add("/wxa/user", WxaUserApiController.class);
-//        me.add("/subscribemsg", SubscribeMsgController.class);
-    }
-	
-    public void configPlugin(Plugins me) {
-
-		DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
+	// 本地开发模式
+	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);
+
+		me.add("/msg", WeixinMsgController.class);
+		me.add("/api", WeixinApiController.class, "/api");
+        me.add("/web", WeixinWebController.class);
+	}
+
+	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);
 
 //         使用redis分布accessToken
-         RedisPlugin redisPlugin = new RedisPlugin("weixin_patient", "127.0.0.1", 6379);
-         redisPlugin.setSerializer(JdkSerializer.me); // 需要使用fst高性能序列化的用户请删除这一行(Fst jar依赖请查看WIKI)
-         me.add(redisPlugin);
-    }
+		RedisPlugin redisPlugin = new RedisPlugin("weixin_patient", "127.0.0.1", 6379);
+		redisPlugin.setSerializer(JdkSerializer.me); // 需要使用fst高性能序列化的用户请删除这一行(Fst jar依赖请查看WIKI)
+		me.add(redisPlugin);
+	}
 
-    public void configInterceptor(Interceptors me) {
-        // 设置默认的 appId 规则,默认值为appId,可采用url挂参数 ?appId=xxx 切换多公众号
+	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) {
-
-    }
-
-    public void afterJFinalStart() {
-        // 1.5 之后支持redis存储access_token、js_ticket,需要先启动RedisPlugin
-//        ApiConfigKit.setAccessTokenCache(new RedisAccessTokenCache());
-        // 1.6新增的2种初始化
-//        ApiConfigKit.setAccessTokenCache(new RedisAccessTokenCache(Redis.use("weixin")));
-        ApiConfigKit.setAccessTokenCache(new RedisAccessTokenCache("weixin_patient"));
-
-        ApiConfig ac = new ApiConfig();
-//        // 配置微信 API 相关参数
-        ac.setToken(PropKit.get("token"));
-        ac.setAppId(PropKit.get("appId"));
-        ac.setAppSecret(PropKit.get("appSecret"));
-//
-//        /**
-//         *  是否对消息进行加密,对应于微信平台的消息加解密方式:
-//         *  1:true进行加密且必须配置 encodingAesKey
-//         *  2:false采用明文模式,同时也支持混合模式
-//         */
-        ac.setEncryptMessage(Boolean.FALSE);
-//        ac.setEncodingAesKey(PropKit.get("encodingAesKey", "setting it in config file"));
-//
-//        /**
-//         * 多个公众号时,重复调用ApiConfigKit.putApiConfig(ac)依次添加即可,第一个添加的是默认。
-//         */
-        ApiConfigKit.putApiConfig(ac);
-        
-        /**
-         * 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));
-//        }
-    }
-//
+	}
+
+	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 = new ApiConfig();
+		// 配置微信 API 相关参数
+		ac.setToken(PropKit.get("token"));
+		ac.setAppId(PropKit.get("appId"));
+		ac.setAppSecret(PropKit.get("appSecret"));
+
+		/**
+		 * 是否对消息进行加密,对应于微信平台的消息加解密方式: 1:true进行加密且必须配置 encodingAesKey
+		 * 2:false采用明文模式,同时也支持混合模式
+		 */
+		ac.setEncryptMessage(Boolean.FALSE);
+
+		/**
+		 * 多个公众号时,重复调用ApiConfigKit.putApiConfig(ac)依次添加即可,第一个添加的是默认。
+		 */
+		ApiConfigKit.putApiConfig(ac);
+
+		ApiConfig ac2 = new ApiConfig();
+//     配置微信 API 相关参数
+		ac2.setToken(PropKit.get("token"));
+		ac2.setAppId("wxee1c68f8944d357b");
+		ac2.setAppSecret("1bc0128b6bbb3907c3bcf4a1704f2a1f");
+		ac2.setEncryptMessage(Boolean.FALSE);
+		ApiConfigKit.putApiConfig(ac2);
+
+		/**
+		 * 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", 80, "/", 5);
 //    }
 
 	@Override
 	public void configEngine(Engine engine) {
-		
+
 	}
 }

+ 1 - 1
PacsOnline_Wechat_Patient/src/main/java/com/zskk/controller/WeixinApiController.java

@@ -73,7 +73,7 @@ public class WeixinApiController extends ApiController {
                 "        },\n" +
                 "        {\n" +
                 "\t    \"name\": \"关于我们\",\n" +
-                "\t    \"url\": \"http://www.pacsonline.cn\",\n" +
+                "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/aboutUs\",\n" +
                 "\t    \"type\": \"view\"\n" +
                 "        }\n" +
                 "    ]\n" +

+ 77 - 0
PacsOnline_Wechat_Patient/src/main/java/com/zskk/controller/WeixinWebController.java

@@ -0,0 +1,77 @@
+package com.zskk.controller;
+
+import java.net.URLEncoder;
+import java.util.List;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.PropKit;
+import com.jfinal.plugin.redis.Redis;
+
+public class WeixinWebController extends Controller {
+
+	private static String WEB_BASR_URL = "http://wechat.client.pacsonline.cn/#";
+	
+	public void addBinding() {
+		this.process(WEB_BASR_URL+"bind");
+	}
+	
+	public void examList() {
+		this.process(WEB_BASR_URL+"/reportList");
+	}
+
+	public void aboutUs() {
+		this.redirect("http://wechat.pacsonline.cn/pacs_online/html/aboutAs_zskk.html");
+	}
+	
+	private void process(String toUrl) {
+		try {
+			String encodeUrl = URLEncoder.encode(toUrl, "UTF-8");
+			Object sessionObj = this.getRequest().getSession().getAttribute("pwpInfo");
+			if (sessionObj == null) {
+				String code = this.getPara("code");
+				if (code == null) {
+					this.redirectToWX();
+					return;
+				}
+//				WeixinService wService = ServiceFactory.getService(WeixinService.class);
+//				String openId = wService.getOpenId(code);
+//				UserWechats userWechats = UserWechats.dao.findById(openId);
+//				if (userWechats == null) {
+//					AccountService aService = ServiceFactory.getService(AccountService.class);
+//	                aService.createWxUser(openId);
+//	                userWechats = UserWechats.dao.findById(openId);
+//				}
+//				Users users = Users.dao.findById(userWechats.getUid());
+//				this.getRequest().getSession().setAttribute("pwpInfo", userWechats);
+
+				String uidStr = toUrl.contains("?") ? "&uid=" : "?uid=";
+//				this.redirect(toUrl + uidStr + userWechats.getUid());
+			} else {
+//				UserWechats userWechats = (UserWechats) sessionObj;
+//				Users users = Users.dao.findById(userWechats.getUid());
+//				this.getRequest().getSession().setAttribute("pwpInfo", userWechats);
+
+				String uidStr = toUrl.contains("?") ? "&uid=" : "?uid=";
+//				this.redirect(toUrl + uidStr + userWechats.getUid());
+			}
+		} catch (Exception e) {
+			// nothing
+		}
+		
+	}
+
+	// 跳转到微信认证
+	public void redirectToWX() {
+//		String url = getRequest().getRequestURL().toString();
+//		if (getPara("type") !=null) {
+//			url = url + "?type=" + getPara("type");
+//		}
+//		try {
+//			url = URLEncoder.encode(url, "UTF-8");
+//		} catch (Exception e) {
+//			// nothing
+//		}
+//		String redirect = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo#wechat_redirect";
+//		redirect(String.format(redirect, PropKit.get("appId"), url));
+	}
+	
+}

+ 32 - 0
PacsOnline_Wechat_Patient/src/main/java/com/zskk/service/ServiceFactory.java

@@ -0,0 +1,32 @@
+package com.zskk.service;
+
+import java.util.HashMap;
+import java.util.Map;
+import com.jfinal.aop.Duang;
+
+/**
+ * Service的工厂方法
+ * 使用工厂方法的主要目的是 为了AOP
+ * @author yht
+ *
+ */
+public class ServiceFactory {
+	private static final Map<Class<?>, Object> CLASS_MAP = new HashMap<Class<?>, Object>();
+	
+	/**
+	 * 初始化 创建Service
+	 */
+	public static void init(){
+		CLASS_MAP.put(ThreadPoolService.class, 	        Duang.duang(ThreadPoolService.class));
+//		CLASS_MAP.put(WeixinService.class, 	            Duang.duang(WeixinService .class));
+//		CLASS_MAP.put(AccountService.class, 	        Duang.duang(AccountService.class));
+//		CLASS_MAP.put(SmsService.class, 				Duang.duang(SmsService.class));
+//		CLASS_MAP.put(PayService.class, 				Duang.duang(PayService.class));
+
+	}
+	
+	@SuppressWarnings("unchecked")
+	public static <T> T getService(Class<T> c){
+		return (T)CLASS_MAP.get(c);
+	}
+}

+ 60 - 0
PacsOnline_Wechat_Patient/src/main/java/com/zskk/service/ThreadPoolService.java

@@ -0,0 +1,60 @@
+package com.zskk.service;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 线程池服务
+ * @author yht
+ *
+ */
+public class ThreadPoolService {
+	private static ExecutorService POOLS = null;
+	private static ScheduledExecutorService TIMER_POOLS = null;
+	public ThreadPoolService(){
+		POOLS		= Executors.newCachedThreadPool();
+		TIMER_POOLS = Executors.newScheduledThreadPool(1);
+	}
+
+	/**
+	 * 执行
+	 * @param run
+	 */
+	public void execute(Runnable run){
+		POOLS.execute(()->{
+			try{
+				run.run();
+			}catch(Exception e){
+//				LogUtil.sysError(e.getMessage(), e);
+			}
+		});
+	}
+	
+	/**
+	 * 提交任务
+	 * @param callable
+	 * @return
+	 */
+	public <T> Future<T>  submit(Callable<T> callable){
+		return POOLS.submit(callable);
+	}
+	
+	/**
+	 * 循环任务
+	 * @param call
+	 * @param delay
+	 */
+	public void schedule(Runnable call, long delay){
+		TIMER_POOLS.scheduleAtFixedRate(()->{
+			try{
+				call.run();
+			}catch(Exception e){
+//				LogUtil.sysError(e.getMessage(), e);
+			}
+		}, 0, delay, TimeUnit.MINUTES);
+	}
+}