Sfoglia il codice sorgente

增加微信支付功能,增加post、get请求功能,增加河南省电子胶片平台公众号支持,优化部分代码

刘韬 5 anni fa
parent
commit
4e11ad63d4

+ 8 - 8
PacsOnline_Wechat_Patient/pom.xml

@@ -24,17 +24,17 @@
 		<dependency>
 			<groupId>com.jfinal</groupId>
 			<artifactId>jfinal-weixin</artifactId>
-			<version>2.3</version>
+			<version>2.4</version>
 		</dependency>
 		<dependency>
 			<groupId>com.jfinal</groupId>
 			<artifactId>jfinal</artifactId>
-			<version>3.7</version>
+			<version>4.3</version>
 		</dependency>
 		<dependency>
 			<groupId>com.alibaba</groupId>
 			<artifactId>druid</artifactId>
-			<version>1.1.15</version>
+			<version>1.1.19</version>
 		</dependency>
 		<dependency>
 			<groupId>log4j</groupId>
@@ -44,17 +44,17 @@
 		<dependency>
 			<groupId>com.alibaba</groupId>
 			<artifactId>fastjson</artifactId>
-			<version>1.2.56</version>
+			<version>1.2.58</version>
 		</dependency>
 		<dependency>
 			<groupId>com.squareup.okhttp3</groupId>
 			<artifactId>okhttp</artifactId>
-			<version>3.14.0</version>
+			<version>4.0.1</version>
 		</dependency>
 		<dependency>
 			<groupId>mysql</groupId>
 			<artifactId>mysql-connector-java</artifactId>
-			<version>8.0.15</version>
+			<version>8.0.16</version>
 		</dependency>
 		<dependency>
 			<groupId>redis.clients</groupId>
@@ -80,12 +80,12 @@
 		<plugins>
 			<plugin>
 				<artifactId>maven-war-plugin</artifactId>
-				<version>3.2.2</version>
+				<version>3.2.3</version>
 			</plugin>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-compiler-plugin</artifactId>
-				<version>3.8.0</version>
+				<version>3.8.1</version>
 				<configuration>
 					<source>${jdk.version}</source>
 					<target>${jdk.version}</target>

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

@@ -25,6 +25,7 @@ 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.WeixinPayController;
 import com.zskk.model._MappingKit;
 import com.zskk.controller.WebBridgeController;
 
@@ -67,6 +68,8 @@ public class ZskkConfig extends JFinalConfig {
 		me.add("/msg", WeixinMsgController.class);
 		me.add("/api", WeixinApiController.class, "/api");
 		me.add("/web", WebBridgeController.class);
+		me.add("/pay", WeixinPayController.class, "/pay");
+
 	}
 
 	public void configPlugin(Plugins me) {
@@ -146,13 +149,21 @@ public class ZskkConfig extends JFinalConfig {
 		ac_ln.setEncryptMessage(Boolean.FALSE);
 		ApiConfigKit.putApiConfig(ac_ln);
 
+		// 河南省电子胶片平台
+		ApiConfig ac_hn = new ApiConfig();
+		ac_hn.setToken(PropKit.get("token_hn"));
+		ac_hn.setAppId(PropKit.get("appId_hn"));
+		ac_hn.setAppSecret(PropKit.get("appSecret_hn"));
+		ac_hn.setEncryptMessage(Boolean.FALSE);
+		ApiConfigKit.putApiConfig(ac_hn);
+
 		// ceshi
-		ApiConfig ac_cs = new ApiConfig();
-		ac_cs.setToken(PropKit.get("token_cs"));
-		ac_cs.setAppId(PropKit.get("appId_cs"));
-		ac_cs.setAppSecret(PropKit.get("appSecret_cs"));
-		ac_ln.setEncryptMessage(Boolean.FALSE);
-		ApiConfigKit.putApiConfig(ac_cs);
+//		ApiConfig ac_cs = new ApiConfig();
+//		ac_cs.setToken(PropKit.get("token_cs"));
+//		ac_cs.setAppId(PropKit.get("appId_cs"));
+//		ac_cs.setAppSecret(PropKit.get("appSecret_cs"));
+//		ac_ln.setEncryptMessage(Boolean.FALSE);
+//		ApiConfigKit.putApiConfig(ac_cs);
 
 		/**
 		 * 1.9 新增LocalTestTokenCache用于本地和线上同时使用一套appId时避免本地将线上AccessToken冲掉

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

@@ -74,6 +74,11 @@ public class WeixinApiController extends ApiController {
                 "\t    \"name\": \"添加绑定\",\n" +
                 "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/addBinding?appId=" + ApiConfigKit.getApiConfig().getAppId() +"\",\n" +
                 "\t    \"type\": \"view\"\n" +
+                "        },\n" +
+                "        {\n" +
+                "\t    \"name\": \"远程诊断\",\n" +
+                "\t    \"url\": \"http://wechat.pacsonline.cn/wx_patient/web/examList?appId=" + ApiConfigKit.getApiConfig().getAppId() +"\",\n" +
+                "\t    \"type\": \"view\"\n" +
                 "        }\n" +
                 "    ]\n" +
                 "        },\n" +

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

@@ -113,8 +113,8 @@ public class WeixinMsgController extends MsgControllerAdapter {
         if (InFollowEvent.EVENT_INFOLLOW_SUBSCRIBE.equals(inFollowEvent.getEvent()))
         {
             log.debug("关注:" + inFollowEvent.getFromUserName());
-            User findUserWechats = User.dao.findFirst("select * from user where wx_openid = ?",inFollowEvent.getFromUserName());
-			if (findUserWechats == null) {
+            User findUser = User.dao.findFirst("select * from user where wx_openid = ?",inFollowEvent.getFromUserName());
+			if (findUser == null) {
 				UserService aService = ServiceFactory.getService(UserService.class);
 				User users = aService.createWxUserByGH(inFollowEvent.getFromUserName(), inFollowEvent.getToUserName());
 				
@@ -127,8 +127,8 @@ public class WeixinMsgController extends MsgControllerAdapter {
 				list.add(articles1);
 				CustomServiceApi.sendNews(inFollowEvent.getFromUserName(), list);
 			}else {
-				findUserWechats.setSubscribeStatus(2);
-				findUserWechats.update();
+				findUser.setSubscribeStatus(2);
+				findUser.update();
 				OutTextMsg outMsgs = new OutTextMsg(inFollowEvent);
 				outMsgs.setContent("欢迎关注中世康恺电子胶片平台!\n使用微信或者本公众号内的\"扫一扫\",扫描报告上的二维码,即可查看电子影像和报告");
 				render(outMsgs);
@@ -138,9 +138,9 @@ public class WeixinMsgController extends MsgControllerAdapter {
         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();
+            User findUser = User.dao.findFirst("select * from user where wx_openid = ?",inFollowEvent.getFromUserName());
+            findUser.setSubscribeStatus(1);
+            findUser.update();
         }
     }
 
@@ -150,7 +150,7 @@ public class WeixinMsgController extends MsgControllerAdapter {
         if (InQrCodeEvent.EVENT_INQRCODE_SUBSCRIBE.equals(inQrCodeEvent.getEvent()))
         {
             log.debug("扫码未关注:" + inQrCodeEvent.getFromUserName());
-			User findUserWechats = User.dao.findFirst("select * from user where wx_openid = ?",inQrCodeEvent.getFromUserName());
+			User findUser = User.dao.findFirst("select * from user where wx_openid = ?",inQrCodeEvent.getFromUserName());
 			String rid = inQrCodeEvent.getEventKey();
 			String[] arr = rid.split("_");
 			Exams exams = Exams.dao.findById(arr[2]);
@@ -158,12 +158,12 @@ public class WeixinMsgController extends MsgControllerAdapter {
 				renderNull();
 			}
 			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.createWxUserByGH(inQrCodeEvent.getFromUserName(), inQrCodeEvent.getToUserName());
+			if (findUser == null) {
+				UserService uService = ServiceFactory.getService(UserService.class);
+                User users = uService.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);
+					uService.bindUserReport(users.getId(), exams);
 				}
 
 				List<Articles> listgz = new ArrayList<Articles>();
@@ -185,14 +185,14 @@ public class WeixinMsgController extends MsgControllerAdapter {
 				CustomServiceApi.sendNews(inQrCodeEvent.getFromUserName(), list);
 				renderNull();
 			}else {
-				UserService aService = ServiceFactory.getService(UserService.class);
+				UserService uService = ServiceFactory.getService(UserService.class);
 
-				findUserWechats.setSubscribeStatus(2);
-				findUserWechats.update();
+				findUser.setSubscribeStatus(2);
+				findUser.update();
 				
-				UserBind userBind = UserBind.dao.findFirst("select * from user_bind where user_id=? and exam_id=?",findUserWechats.getId(),exams.getId());
+				UserBind userBind = UserBind.dao.findFirst("select * from user_bind where user_id=? and exam_id=?",findUser.getId(),exams.getId());
 				if (userBind == null) {
-					aService.bindUserReport(findUserWechats.getId(), exams);
+					uService.bindUserReport(findUser.getId(), exams);
 				}
 				CustomServiceApi.sendText(inQrCodeEvent.getFromUserName(), "欢迎关注中世康恺电子胶片平台!\n使用微信-\"扫一扫\",扫描报告上的二维码,即可查看电子影像和报告");
 
@@ -213,20 +213,20 @@ public class WeixinMsgController extends MsgControllerAdapter {
             log.debug("扫码已关注:" + inQrCodeEvent.getFromUserName());
             String rid = inQrCodeEvent.getEventKey();
 			String[] arr = rid.split("_");
-			User userWechats = User.dao.findFirst("select * from user where wx_openid = ?",inQrCodeEvent.getFromUserName());
+			User user = User.dao.findFirst("select * from user where wx_openid = ?",inQrCodeEvent.getFromUserName());
 			
 			UserService uService = ServiceFactory.getService(UserService.class);
 
-			if (userWechats == null) {
-				userWechats = uService.createWxUserByGH(inQrCodeEvent.getFromUserName(), inQrCodeEvent.getToUserName());
+			if (user == null) {
+				user = uService.createWxUserByGH(inQrCodeEvent.getFromUserName(), inQrCodeEvent.getToUserName());
 			}
 			
 			Exams exams = Exams.dao.findById(arr[1]);
 
-			UserBind userBind = UserBind.dao.findFirst("select * from user_bind where user_id=? and exam_id=?",userWechats.getId(),exams.getId());
+			UserBind userBind = UserBind.dao.findFirst("select * from user_bind where user_id=? and exam_id=?",user.getId(),exams.getId());
 			
 			if (userBind == null) {
-				uService.bindUserReport(userWechats.getId(), exams);
+				uService.bindUserReport(user.getId(), exams);
 			}
 			
 			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());

+ 7 - 0
PacsOnline_Wechat_Patient/src/main/java/com/zskk/controller/WeixinPayController.java

@@ -0,0 +1,7 @@
+package com.zskk.controller;
+
+import com.jfinal.weixin.sdk.jfinal.ApiController;
+
+public class WeixinPayController extends ApiController {
+
+}

+ 30 - 29
PacsOnline_Wechat_Patient/src/main/java/com/zskk/service/UserService.java

@@ -8,16 +8,18 @@ import com.zskk.model.Exams;
 import com.zskk.model.User;
 import com.zskk.model.UserBind;
 
-import okhttp3.Call;
+import okhttp3.MediaType;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
+import okhttp3.RequestBody;
 import okhttp3.Response;
 
 public class UserService {
 
+	private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
+
 	private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
 
-	private static final String CAHR_CODE = "UTF-8";
 
 	/**
 	 * 创建微信用户
@@ -186,34 +188,33 @@ public class UserService {
 		return UUID.randomUUID().toString();
 	}
 	
-	public static void main(String[] args) {
-		Request request = new Request.Builder()
-		        .url("http://wechat.pacsonline.cn/wx_patient/api/getQrcode?reportId=7e7a4cc7c93b4d2b")
-		        .get()//默认就是GET请求,可以不写
+	private static String run(String url) throws IOException {
+		    Request request = new Request.Builder()
+		        .url(url)
 		        .build();
-		Call call = OKHTTP_CLIENT.newCall(request);
-        //同步execute
-        //同步请求
-        //同步是耗时的
-        //同步execute需要开启子线程
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    Response response = call.execute();
-                    if (response.isSuccessful()) {
-                        String string = response.body().string();
-                        //调用者只需要实现provide方法就能拿到这个String了
-						System.out.println(string);
-                    }else {
-						System.out.println("");
-
-					}
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        }).start();
+
+		    try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
+		      return response.body().string();
+		    }
+		  }
+	
+
+	private static String post(String url, String json) throws IOException {
+	    RequestBody body = RequestBody.create(json, JSON_CODE);
+	    Request request = new Request.Builder()
+	        .url(url)
+	        .post(body)
+	        .build();
+	    try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
+	      return response.body().string();
+	    }
+	  }  
+	
+	public static void main(String[] args) throws IOException {
+//		        .url("http://wechat.pacsonline.cn/wx_patient/api/getQrcode?reportId=7e7a4cc7c93b4d2b")
+
+	    String response = run("http://www.baidu.com");
+	    System.out.println(response);
 		
 	}
 }

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

@@ -10,7 +10,7 @@ appId_zskk2    = wx6a54bf0e98ecd2c7
 appSecret_zskk2= f4b4e2b054d84157565ace97a43275e8
 token_zskk2    = zhongshikangkai2019
 
-Wechat-ZhongShiKangKaiDianZiJiaoPianPingTai
+#Wechat-ZhongShiKangKaiDianZiJiaoPianPingTai
 appId_zskk    = wx1f3dc2c37dce641b
 appSecret_zskk= 013c469bbd9e892a693f3375fdf4537e
 token_zskk    = zhongshikangkai2019
@@ -28,4 +28,9 @@ token_ln    = zhongshikangkai2019
 #Wechat-ceshi
 appId_cs    = wxee1c68f8944d357b
 appSecret_cs= 1bc0128b6bbb3907c3bcf4a1704f2a1f
-token_cs    = zhongshikangkai2019
+token_cs    = zhongshikangkai2019
+
+#Wechat-HeNanShengDianZiJiaoPianPingTai
+appId_hn    = wx02945ec1b2af52a8
+appSecret_hn= e81b284cdc4c173e588844db190cae3c
+token_hn    = zhongshikangkai2018