Browse Source

初始化

刘韬 6 years ago
parent
commit
ccae018247

+ 2 - 2
PacsOnline_Wechat_Patient/pom.xml

@@ -67,12 +67,12 @@
 			<version>4.0.1</version>
 			<scope>provided</scope>
 		</dependency>
-		<!-- <dependency>
+		<dependency>
     <groupId>com.jfinal</groupId>
     <artifactId>jetty-server</artifactId>
     <version>2019.3</version>
     <scope>provided</scope>
-</dependency> -->
+</dependency> 
 	</dependencies>
 
 	<build>

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

@@ -82,9 +82,9 @@ public class ZskkConfig extends JFinalConfig {
 		_MappingKit.mapping(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) {
@@ -102,7 +102,7 @@ public class ZskkConfig extends JFinalConfig {
 		// TODO Auto-generated method stub
 		super.onStart();
 		// 支持redis存储access_token、js_ticket,需要先启动RedisPlugin
-		ApiConfigKit.setAccessTokenCache(new RedisAccessTokenCache("weixin_patient"));
+//		ApiConfigKit.setAccessTokenCache(new RedisAccessTokenCache("weixin_patient"));
 		// 中世康恺电子胶片平台
 		ApiConfig ac_zskk = new ApiConfig();
 		// 配置微信 API 相关参数
@@ -167,9 +167,9 @@ public class ZskkConfig extends JFinalConfig {
 	}
 
 //
-//	public static void main(String[] args) {
-//		JFinal.start("src/main/webapp", 10000, "/", 5);
-//	}
+	public static void main(String[] args) {
+		JFinal.start("src/main/webapp", 10000, "/", 5);
+	}
 
 	@Override
 	public void configEngine(Engine engine) {

+ 6 - 15
PacsOnline_Wechat_Patient/src/main/java/com/zskk/controller/WebBridgeController.java

@@ -12,12 +12,6 @@ public class WebBridgeController extends ApiController {
 
 	private static String WEB_BASR_URL = "http://wechat.client.pacsonline.cn/#";
 	
-	public void testappid() {
-		String string = ApiConfigKit.getApiConfig().getAppId();
-		System.out.println(string);
-		renderText(string);
-	}
-	
 	public void addBinding() {
 		this.process(WEB_BASR_URL+"/bind");
 	}
@@ -37,20 +31,17 @@ public class WebBridgeController extends ApiController {
 			if (sessionObj == null) {
 				String code = this.getPara("code");
 				if (code == null) {
-					String url = wService.getCodeUrl("wxee1c68f8944d357b", getRequest().getRequestURL().toString());
-//					String url = wService.getCodeUrl("wx6a54bf0e98ecd2c7", getRequest().getRequestURL().toString());
-
+					String url = wService.getCodeUrl(ApiConfigKit.getApiConfig().getAppId(), getRequest().getRequestURL().toString());
 					this.redirect(url);
 					return;
 				}
-				SnsAccessToken snsAccessToken = wService.getWebAccessToken("wxee1c68f8944d357b", "1bc0128b6bbb3907c3bcf4a1704f2a1f", code);
-//				SnsAccessToken snsAccessToken = wService.getWebAccessToken("wx6a54bf0e98ecd2c7", "f4b4e2b054d84157565ace97a43275e8", code);
+				SnsAccessToken snsAccessToken = wService.getWebAccessToken(ApiConfigKit.getApiConfig().getAppId(), ApiConfigKit.getApiConfig().getAppSecret(), code);
 
 				UserService uService = ServiceFactory.getService(UserService.class);
 				User user = User.dao.findFirst("select * from user where wx_openid=?",snsAccessToken.getOpenid());
 
 				if (user == null && snsAccessToken.getOpenid() != null) {
-					user = uService.createWxUser(snsAccessToken.getOpenid());
+					user = uService.createWxUserByAppid(snsAccessToken.getOpenid(), ApiConfigKit.getApiConfig().getAppId());
 				}
 				if (user != null && user.getWxIcon().isEmpty()) {                     
 					wService.getWebWeixinUserInfo(snsAccessToken.getAccessToken(), snsAccessToken.getOpenid());
@@ -64,7 +55,7 @@ public class WebBridgeController extends ApiController {
 				User users = User.dao.findById(userWechats.getId());
 				String uidStr = toUrl.contains("?") ? "&openid=" : "?openid=";
 				if (users == null) {
-					userWechats = uService.createWxUser(userWechats.getWxOpenid());
+					userWechats = uService.createWxUserByAppid(userWechats.getWxOpenid(), ApiConfigKit.getApiConfig().getAppId());
 				}
 				User users2 = User.dao.findFirst("select * from user where wx_openid=?",userWechats.getWxOpenid());
 				if (users2 != null && users2.getWxIcon().isEmpty()) {
@@ -72,9 +63,9 @@ public class WebBridgeController extends ApiController {
 //					wService.getWebWeixinUserInfo(snsAccessToken.getAccessToken(), snsAccessToken.getOpenid());
 
 				}
-//				
+				
 				this.getRequest().getSession().setAttribute("pwpSessionObjtest8", users2);
-//
+
 				this.redirect(toUrl + uidStr + userWechats.getWxOpenid());
 
 				

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

@@ -10,6 +10,7 @@ import com.jfinal.weixin.sdk.api.ShorturlApi;
 import com.jfinal.weixin.sdk.api.TemplateMsgApi;
 import com.jfinal.weixin.sdk.api.UserApi;
 import com.jfinal.weixin.sdk.jfinal.ApiController;
+import com.zskk.model.Report;
 
 public class WeixinApiController extends ApiController {
 
@@ -61,12 +62,12 @@ public class WeixinApiController extends ApiController {
                 "            \"sub_button\": [\n" +
                 "        {\n" +
                 "\t    \"name\": \"我的检查列表\",\n" +
-                "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/examList\",\n" +
+                "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/examList?appId=" + ApiConfigKit.getApiConfig().getAppId() +"\",\n" +
                 "\t    \"type\": \"view\"\n" +
                 "        },\n" +
                 "        {\n" +
                 "\t    \"name\": \"添加绑定\",\n" +
-                "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/addBinding\",\n" +
+                "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/addBinding?appId=" + ApiConfigKit.getApiConfig().getAppId() +"\",\n" +
                 "\t    \"type\": \"view\"\n" +
                 "        }\n" +
                 "    ]\n" +
@@ -142,10 +143,22 @@ public class WeixinApiController extends ApiController {
     public void getQrcode()
     {
         String reportId = getPara("reportId");
-
-        String str = "{\"expire_seconds\": 2592000, \"action_name\": \"QR_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"ExamQR_" + reportId + "\"}}}";
-        ApiResult apiResult = QrcodeApi.create(str);
-        renderText(apiResult.getJson());
+		Report reports = Report.dao.findById(reportId);
+		if (reportId == null || reports == null) {
+			renderNull();
+		}
+		if (reports.getQrCode() == null || reports.getQrCode().isEmpty()) {		
+			String str = "{\"expire_seconds\": 2592000, \"action_name\": \"QR_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"ExamQR_" + reportId + "\"}}}";
+	        ApiResult apiResult = QrcodeApi.create(str);
+	        apiResult.getStr("url");
+			reports.setQrCode(apiResult.getStr("url"));
+			reports.update();
+	        renderText(apiResult.getJson());
+		}else {
+			//ApiResult qrresult = new ApiResult(reports.getQrCode());
+			renderText(reports.getQrCode());;
+		}
+        
 
 //        String str = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"123\"}}}";
 //        ApiResult apiResult = QrcodeApi.create(str);

+ 47 - 10
PacsOnline_Wechat_Patient/src/main/java/com/zskk/controller/WeixinMsgController.java

@@ -32,9 +32,23 @@ public class WeixinMsgController extends MsgControllerAdapter {
 
     @Override
     protected void processInTextMsg(InTextMsg inTextMsg) {
-        OutTextMsg outMsg = new OutTextMsg(inTextMsg);
-        outMsg.setContent("文本消息~"+inTextMsg.getToUserName());
-        render(outMsg);
+		String msgContent = inTextMsg.getContent().trim();
+
+    	if ("演示".equalsIgnoreCase(msgContent)) {
+			String toUrlString = String.format("http://wechat.client.pacsonline.cn/#/reportInfo/report?openid=%s&exam_id=%s&study_id=%s","test","8f0d2411134615e9","0c803a0934dfa1d8");
+
+			List<Articles> list = new ArrayList<Articles>();
+			Articles articles1 = new Articles();
+			articles1.setTitle("【演示】点击查看本次影像和报告");
+			articles1.setDescription("欢迎使用中世康恺PacsOnline!\n点击进入查看详情,您可以分享给家属或医生,日后还可以在“我的报告”中查看本次影像和报告");
+			articles1.setPicurl("http://work.pacsonline.cn/static/img/banner.e8ee043.png");
+			articles1.setUrl(toUrlString);
+			list.add(articles1);
+			CustomServiceApi.sendNews(inTextMsg.getFromUserName(), list);
+			renderNull();
+			}else {
+				renderNull();
+			}
     }
 
     @Override
@@ -94,14 +108,34 @@ public class WeixinMsgController extends MsgControllerAdapter {
         if (InFollowEvent.EVENT_INFOLLOW_SUBSCRIBE.equals(inFollowEvent.getEvent()))
         {
             log.debug("关注:" + inFollowEvent.getFromUserName());
-            OutTextMsg outMsg = new OutTextMsg(inFollowEvent);
-            outMsg.setContent("欢迎关注电子胶片平台");
-            render(outMsg);
+            User findUserWechats = User.dao.findFirst("select * from user where wx_openid = ?",inFollowEvent.getFromUserName());
+			if (findUserWechats == null) {
+				UserService aService = ServiceFactory.getService(UserService.class);
+				User users = aService.createWxUserByGH(inFollowEvent.getFromUserName(), inFollowEvent.getToUserName());
+				
+				List<Articles> list = new ArrayList<Articles>();
+				Articles articles1 = new Articles();
+				articles1.setTitle("欢迎关注中世康恺电子胶片平台,点此进入");
+				articles1.setDescription("点击页面绑定手机号或检查信息,立即查看电子胶片");
+				articles1.setUrl("http://wechat.client.pacsonline.cn/#/bind?openid=" + inFollowEvent.getFromUserName());
+				articles1.setPicurl("http://work.pacsonline.cn/static/img/banner.e8ee043.png");
+				list.add(articles1);
+				CustomServiceApi.sendNews(inFollowEvent.getFromUserName(), list);
+			}else {
+				findUserWechats.setSubscribeStatus(2);
+				findUserWechats.update();
+				OutTextMsg outMsgs = new OutTextMsg(inFollowEvent);
+				outMsgs.setContent("欢迎关注中世康恺电子胶片平台!\n使用微信或者本公众号内的“扫一扫”,扫描报告上的二维码,即可查看电子影像和报告");
+				render(outMsgs);
+			}
         }
         // 如果为取消关注事件,将无法接收到传回的信息
         if (InFollowEvent.EVENT_INFOLLOW_UNSUBSCRIBE.equals(inFollowEvent.getEvent()))
         {
             log.debug("取消关注:" + inFollowEvent.getFromUserName());
+            User findUserWechats = User.dao.findFirst("select * from user where wx_openid = ?",inFollowEvent.getFromUserName());
+			findUserWechats.setSubscribeStatus(1);
+			findUserWechats.update();
         }
     }
 
@@ -121,7 +155,7 @@ public class WeixinMsgController extends MsgControllerAdapter {
 			String toUrlString = String.format("http://wechat.client.pacsonline.cn/#/reportInfo/report?openid=%s&exam_id=%s&study_id=%s",inQrCodeEvent.getFromUserName(),exams.getId(),exams.getStudyId());
 			if (findUserWechats == null) {
 				UserService aService = ServiceFactory.getService(UserService.class);
-                User users = aService.createWxUser(inQrCodeEvent.getFromUserName());
+                User users = aService.createWxUserByGH(inQrCodeEvent.getFromUserName(), inQrCodeEvent.getToUserName());
 				UserBind userBind = UserBind.dao.findFirst("select * from user_bind where user_id=? and exam_id=?",users.getId(),exams.getId());
 				if (userBind == null) {
 					aService.bindUserReport(users.getId(), exams);
@@ -134,13 +168,16 @@ public class WeixinMsgController extends MsgControllerAdapter {
 				articles.setUrl("http://wechat.client.pacsonline.cn/#/bind?openid=" + inQrCodeEvent.getFromUserName());
 				articles.setPicurl("http://work.pacsonline.cn/static/img/banner.e8ee043.png");
 				listgz.add(articles);
+				CustomServiceApi.sendNews(inQrCodeEvent.getFromUserName(), listgz);
+				
+				List<Articles> list = new ArrayList<Articles>();
 				Articles articles1 = new Articles();
 				articles1.setTitle("点击查看本次影像和报告");
 				articles1.setDescription("欢迎使用中世康恺PacsOnline!\n点击进入查看详情,您可以分享给家属或医生,日后还可以在“我的报告”中查看本次影像和报告");
 				articles1.setUrl(toUrlString);
 				articles1.setPicurl("http://work.pacsonline.cn/static/img/banner.e8ee043.png");
-				listgz.add(articles1);
-				CustomServiceApi.sendNews(inQrCodeEvent.getFromUserName(), listgz);
+				list.add(articles1);
+				CustomServiceApi.sendNews(inQrCodeEvent.getFromUserName(), list);
 				renderNull();
 			}else {
 				UserService aService = ServiceFactory.getService(UserService.class);
@@ -176,7 +213,7 @@ public class WeixinMsgController extends MsgControllerAdapter {
 			UserService uService = ServiceFactory.getService(UserService.class);
 
 			if (userWechats == null) {
-				userWechats = uService.createWxUser(inQrCodeEvent.getFromUserName());
+				userWechats = uService.createWxUserByGH(inQrCodeEvent.getFromUserName(), inQrCodeEvent.getToUserName());
 			}
 			
 			Exams exams = Exams.dao.findById(arr[1]);

+ 65 - 9
PacsOnline_Wechat_Patient/src/main/java/com/zskk/service/UserService.java

@@ -11,35 +11,88 @@ import okhttp3.OkHttpClient;
 import okhttp3.Request;
 
 public class UserService {
-	
+
 	private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
 
 	private static final String CAHR_CODE = "UTF-8";
-	
-	//业务逻辑请求
+
+	// 业务逻辑请求
 	private static final String BASE_URL = PropKit.get("wx_base_url");
 
 	/**
 	 * 创建微信用户
+	 * 
 	 * @param openid
 	 */
-	public User createWxUser(String openid) {
+	public User createWxUserByGH(String openid, String gh) {
 		User user = new User();
 		user.setId(creatId());
 		user.setWxOpenid(openid);
-		user.setSource("测试微信");
+		switch (gh) {
+
+		case "gh_728267809f40":
+			user.setSource("测试微信");
+			break;
+
+		case "gh_c3ecc9e4d6e4":
+			user.setSource("黑龙江省电子胶片平台");
+			break;
+
+		case "gh_bb923a0a951e":
+			user.setSource("辽宁省电子胶片平台");
+			break;
+
+		default:
+			user.setSource("测试微信");
+			break;
+		}
 		user.setWxIcon("");
 		user.setSubscribeStatus(2);
 		user.setCreateAt(new Date());
 		user.save();
 		return user;
 	}
-	
+
 	/**
 	 * 创建微信用户
+	 * 
 	 * @param openid
 	 */
-	public UserBind bindUserReport (String uid,Exams exam) {
+	public User createWxUserByAppid(String openid, String appid) {
+		User user = new User();
+		user.setId(creatId());
+		user.setWxOpenid(openid);
+		switch (appid) {
+
+		case "wx6a54bf0e98ecd2c7":
+			user.setSource("测试微信");
+			break;
+
+		case "wxdeb75f5d7e5a2300":
+			user.setSource("黑龙江省电子胶片平台");
+			break;
+
+		case "wx2f0834870403c54e":
+			user.setSource("辽宁省电子胶片平台");
+			break;
+
+		default:
+			user.setSource("测试微信");
+			break;
+		}
+		user.setWxIcon("");
+		user.setSubscribeStatus(2);
+		user.setCreateAt(new Date());
+		user.save();
+		return user;
+	}
+
+	/**
+	 * 创建微信用户
+	 * 
+	 * @param openid
+	 */
+	public UserBind bindUserReport(String uid, Exams exam) {
 		UserBind userBind = new UserBind();
 		userBind.setUserId(uid);
 		userBind.setExamId(exam.getId());
@@ -50,6 +103,7 @@ public class UserService {
 		userBind.save();
 		return userBind;
 	}
+
 	/*
 	 * 获取用户信息
 	 */
@@ -67,7 +121,7 @@ public class UserService {
 //			account.update();
 //		}
 	}
-	
+
 	private String doGet(String url) {
 		Request request = new Request.Builder().url(url).build();
 
@@ -78,7 +132,7 @@ public class UserService {
 	/*
 	 * 发送模板消息
 	 */
-	public void sendTemplateMsg(String openid,String url,String event,String userName) {
+	public void sendTemplateMsg(String openid, String url, String event, String userName) {
 //		if (PropKit.getBoolean("devMode") == true) {
 //			ApiConfigKit.setThreadLocalApiConfig(getApiConfig());
 //			SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
@@ -111,9 +165,11 @@ public class UserService {
 //			System.out.println(result.getJson());
 //		}
 	}
+
 	private String creatId() {
 		return UUID.randomUUID().toString().replace("-", "");
 	}
+
 	private String create_timestamp() {
 		return Long.toString(System.currentTimeMillis() / 1000);
 	}

+ 2 - 2
PacsOnline_Wechat_Patient/src/main/resources/config.properties

@@ -18,12 +18,12 @@ token_zskk    = zhongshikangkai2019
 #Wechat-HeiLongJiangShengDianZiJiaoPianPingTai
 appId_hlj    = wxdeb75f5d7e5a2300
 appSecret_hlj= eda53ed6dfa269705c3ccc786e5fb01
-token_hlj    = zhongshikangkai2017
+token_hlj    = zhongshikangkai2019
 
 #Wechat-LiaoNingShengDianZiJiaoPianPingTai
 appId_ln    = wx2f0834870403c54e
 appSecret_ln= 8c680120506ede6e915d0a38d214b67f
-token_ln    = zhongshikangkai2017
+token_ln    = zhongshikangkai2019
 
 #Wechat-ceshi
 appId_cs    = wxee1c68f8944d357b