刘韬 5 éve
szülő
commit
5621dddef0

+ 29 - 31
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/controller/WxaUserApiController.java

@@ -190,7 +190,7 @@ public class WxaUserApiController extends WxaController {
 
 		String encryptedData = getPara("encryptedData");
 		String iv = getPara("iv");
-		String sessionId = getPara("sessionid");
+		String sessionId = getPara("wxa-sessionid");
 		// 参数空校验 不做演示
 		if (StrKit.isBlank(encryptedData) || StrKit.isBlank(iv)) {
 			renderJson(ErrorConstant.ERROR_WXA_SESSION_BLANK);
@@ -221,37 +221,35 @@ public class WxaUserApiController extends WxaController {
 
 		// 用户信息校验
 		WxaUserApi wxaUserApi = Duang.duang(WxaUserApi.class);
-		renderText(sessionKey+"      " +encryptedData+"     "+iv);
-		return;
 		// 服务端解密用户信息
-//		ApiResult apiResult = wxaUserApi.getUserInfo(sessionKey, encryptedData, iv);
-//
-//		if (!apiResult.isSucceed()) {
-//			ResultBean resultBean = new ResultBean(apiResult.getInt("errcode"), apiResult.getStr("errmsg"));
-//			renderJson(resultBean);
-//			return;
-//		}
-//		// 如果开发者拥有多个移动应用、网站应用、和公众帐号(包括小程序),可通过unionid来区分用户的唯一性
-//		// 同一用户,对同一个微信开放平台下的不同应用,unionid是相同的。
-//
-//		String phone = apiResult.getStr("purePhoneNumber");
-//		if (StrKit.isBlank(phone)) {
-//			renderJson(ErrorConstant.ERROR_PHONE_BLANK);
-//			return;
-//		}
-//
-//		Doctors doctors = Doctors.dao.findFirst("select * from doctors where phone=?", phone);
-//		if (doctors == null) {
-//			renderJson(ErrorConstant.ERROR_DOCTOR_NOT_FIND);
-//			return;
-//		}
-//		DoctorsWechat doctorsWechat = DoctorsWechat.dao.findFirst("select * from doctors_wechat where wxa_openid=?",sessionResult.get("openid"));
-//		doctorsWechat.setDoctorId(doctors.getId());
-//		doctorsWechat.update();
-//		LoginBean loginBean = new LoginBean();
-//		loginBean.setSessionId(sessionId);
-//		loginBean.setDoctorBean(doctors);
-//		renderJson(new ResultBean(loginBean));
+		ApiResult apiResult = wxaUserApi.getUserInfo(sessionKey, encryptedData, iv);
+
+		if (!apiResult.isSucceed()) {
+			ResultBean resultBean = new ResultBean(apiResult.getInt("errcode"), apiResult.getStr("errmsg"));
+			renderJson(resultBean);
+			return;
+		}
+		// 如果开发者拥有多个移动应用、网站应用、和公众帐号(包括小程序),可通过unionid来区分用户的唯一性
+		// 同一用户,对同一个微信开放平台下的不同应用,unionid是相同的。
+
+		String phone = apiResult.getStr("purePhoneNumber");
+		if (StrKit.isBlank(phone)) {
+			renderJson(ErrorConstant.ERROR_PHONE_BLANK);
+			return;
+		}
+
+		Doctors doctors = Doctors.dao.findFirst("select * from doctors where phone=?", phone);
+		if (doctors == null) {
+			renderJson(ErrorConstant.ERROR_DOCTOR_NOT_FIND);
+			return;
+		}
+		DoctorsWechat doctorsWechat = DoctorsWechat.dao.findFirst("select * from doctors_wechat where wxa_openid=?",sessionResult.get("openid"));
+		doctorsWechat.setDoctorId(doctors.getId());
+		doctorsWechat.update();
+		LoginBean loginBean = new LoginBean();
+		loginBean.setSessionId(sessionId);
+		loginBean.setDoctorBean(doctors);
+		renderJson(new ResultBean(loginBean));
 
 	}
 }

+ 29 - 0
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/service/ServiceFactory.java

@@ -0,0 +1,29 @@
+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(UserService.class, 	            Duang.duang(UserService .class));
+
+	}
+	
+	@SuppressWarnings("unchecked")
+	public static <T> T getService(Class<T> c){
+		return (T)CLASS_MAP.get(c);
+	}
+}

+ 60 - 0
PacsOnline_Wechat_Doctor/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);
+	}
+}

+ 72 - 0
PacsOnline_Wechat_Doctor/src/main/java/com/zskk/service/UserService.java

@@ -0,0 +1,72 @@
+package com.zskk.service;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.security.AlgorithmParameters;
+import java.security.Key;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+import com.alibaba.fastjson.JSON;
+import com.jfinal.kit.Base64Kit;
+import com.jfinal.kit.HashKit;
+import com.jfinal.weixin.sdk.utils.Charsets;
+
+import okhttp3.FormBody;
+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();
+
+	/**
+	 * 创建微信用户
+	 * 
+	 * @param openid
+	 */
+	public static String decrypt(String encryptedData, String ivStr) {
+        byte[] bizData = Base64Kit.decode("zY5mNzlVRTEhY2V5bAgjtjCKBKIPhlHu1ct/ThHNgbIL/ZyxZ+amvQ7JSFSRh2b1JC+VisPN9MP/yBfdFbcvhuLLM0kXQLKOqd4zRWi5+SXTdnHHYdoIp+z2zE4mk277iBrg+LRyaJEwdZ7OvgNBedrkn6mDANwQNb2kn1slkP13Z3MMtiUJlEn2GSKboHv+VOdnNAp3AfIpxGhc+ZIH4w==");
+        byte[] keyByte = Base64Kit.decode("9s89B/Ju7f9tSqifyPUboA==");
+        byte[] ivByte  = Base64Kit.decode("tg1xdcVOnjSwfott9Dz58A==");
+        try {
+            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
+            Key sKeySpec = new SecretKeySpec(keyByte, "AES");
+            // 初始化
+            AlgorithmParameters params = AlgorithmParameters.getInstance("AES");
+            params.init(new IvParameterSpec(ivByte));
+            cipher.init(Cipher.DECRYPT_MODE, sKeySpec, params);
+            byte[] original = cipher.doFinal(bizData);
+            // 去除补位字符
+            byte[] result = decode(original);
+            return new String(result, Charsets.UTF_8);
+        } catch (Exception e) {
+            throw new RuntimeException("aes解密失败");
+        }
+    }
+	
+	static byte[] decode(byte[] decrypted) {
+        int pad = (int) decrypted[decrypted.length - 1];
+        if (pad < 1 || pad > 32) {
+            pad = 0;
+        }
+        return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
+    }
+
+	public static void main(String[] args) throws IOException {
+		String aaaString=  decrypt("","");
+		System.out.println(aaaString);
+	}
+}