|
@@ -2,8 +2,10 @@ package com.zskk.controller;
|
|
|
|
|
|
import java.security.AlgorithmParameters;
|
|
|
import java.security.Key;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
@@ -19,7 +21,6 @@ import com.jfinal.plugin.redis.Redis;
|
|
|
import com.jfinal.weixin.sdk.api.ApiConfigKit;
|
|
|
import com.jfinal.weixin.sdk.api.ApiResult;
|
|
|
import com.jfinal.weixin.sdk.cache.IAccessTokenCache;
|
|
|
-import com.jfinal.weixin.sdk.encrypt.WxaBizDataCrypt;
|
|
|
import com.jfinal.weixin.sdk.utils.Charsets;
|
|
|
import com.jfinal.wxaapp.api.WxaUserApi;
|
|
|
import com.jfinal.wxaapp.jfinal.WxaController;
|
|
@@ -81,7 +82,9 @@ public class WxaUserApiController extends WxaController {
|
|
|
if (doctors != null) {
|
|
|
doctors.setPassword("");
|
|
|
String tokenKey = "TOKEN_WXA_" + StrKit.getRandomUUID();
|
|
|
- Redis.use("pc").setex(tokenKey, 7200, doctors.toJson());
|
|
|
+ List<Doctors> doctors2 = new ArrayList<Doctors>(1);
|
|
|
+ doctors2.add(doctors);
|
|
|
+ Redis.use("pc").setex(tokenKey, 7200, doctors2);
|
|
|
loginBean.setDoctorBean(doctors);
|
|
|
loginBean.setToken(tokenKey);
|
|
|
}
|
|
@@ -271,37 +274,14 @@ public class WxaUserApiController extends WxaController {
|
|
|
doctorsWechat.setDoctorId(doctors.getId());
|
|
|
doctorsWechat.update();
|
|
|
LoginBean loginBean = new LoginBean();
|
|
|
- loginBean.setSessionId(sessionId);
|
|
|
+ doctors.setPassword("");
|
|
|
+ String tokenKey = "TOKEN_WXA_" + StrKit.getRandomUUID();
|
|
|
+ List<Doctors> doctors2 = new ArrayList<Doctors>(1);
|
|
|
+ doctors2.add(doctors);
|
|
|
+ Redis.use("pc").setex(tokenKey, 7200, doctors2);
|
|
|
loginBean.setDoctorBean(doctors);
|
|
|
+ loginBean.setToken(tokenKey);
|
|
|
renderJson(new ResultBean(loginBean));
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- public String decrypt(String encryptedData, String ivStr, String sessionKey) {
|
|
|
- byte[] bizData = Base64Kit.decode(encryptedData);
|
|
|
- byte[] keyByte = Base64Kit.decode(sessionKey);
|
|
|
- byte[] ivByte = Base64Kit.decode(ivStr);
|
|
|
- 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解密失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
}
|