|
@@ -1,16 +1,18 @@
|
|
|
package com.sooka.service.impl;
|
|
|
|
|
|
import com.sooka.enums.ResultEnum;
|
|
|
+import com.sooka.mapper.AuthCNMDMapper;
|
|
|
import com.sooka.model.ResultModel;
|
|
|
import com.sooka.model.db.IntDetailed;
|
|
|
+import com.sooka.model.db.IntDetailed_SP;
|
|
|
import com.sooka.service.AuthService;
|
|
|
import com.sooka.mapper.AuthMapper;
|
|
|
-import com.sooka.utils.DateUtils;
|
|
|
import com.sooka.utils.SecretKeyUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import tk.mybatis.mapper.entity.Example;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -19,14 +21,16 @@ import java.util.Objects;
|
|
|
@Service
|
|
|
public class AuthServiceImpl implements AuthService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private AuthMapper authMapper;
|
|
|
+ @Resource
|
|
|
+ private AuthCNMDMapper authCNMDMapper;
|
|
|
+// @Autowired
|
|
|
+// private AuthMapper authMapper;
|
|
|
|
|
|
@Override
|
|
|
public ResultModel auth(String secretKey, String intCode) {
|
|
|
-
|
|
|
- Example userExample = new Example(IntDetailed.class);
|
|
|
- Example.Criteria criteria = userExample.createCriteria();
|
|
|
+ System.out.println("进入 com.sooka.service.impl");
|
|
|
+// Example userExample = new Example(IntDetailed.class);
|
|
|
+// Example.Criteria criteria = userExample.createCriteria();
|
|
|
|
|
|
// 小于等于
|
|
|
// 原授权码到期验证
|
|
@@ -37,9 +41,16 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// criteria.andGreaterThanOrEqualTo("endAt", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
|
|
|
|
|
|
// 等于
|
|
|
- criteria.andEqualTo("secretKey", secretKey);
|
|
|
+// criteria.andEqualTo("secretKey", secretKey);
|
|
|
+
|
|
|
+// List<IntDetailed> list = authMapper.selectByExample(userExample);
|
|
|
+
|
|
|
+ IntDetailed_SP intDetailedParam = new IntDetailed_SP();
|
|
|
+ intDetailedParam.setSecretKey(secretKey);
|
|
|
+ System.out.println("start querying...");
|
|
|
+ List<IntDetailed_SP> list = authCNMDMapper.selectIntDetailedList(intDetailedParam);
|
|
|
+ System.out.println("query finished. list.size=" + list.size());
|
|
|
|
|
|
- List<IntDetailed> list = authMapper.selectByExample(userExample);
|
|
|
|
|
|
// 原授权码到期验证
|
|
|
// if (list == null || list.size() != 1) {
|
|
@@ -49,12 +60,28 @@ public class AuthServiceImpl implements AuthService {
|
|
|
|
|
|
// 新授权码到期验证
|
|
|
boolean isAuthExpires;
|
|
|
- IntDetailed intDetailed;
|
|
|
+ IntDetailed_SP intDetailed;
|
|
|
+ if(list == null){
|
|
|
+ System.out.println("无此密钥" + secretKey);
|
|
|
+ }else if(list.size() == 0){
|
|
|
+ System.out.println("存在0个密钥" + secretKey);
|
|
|
+ }else if(list.size() > 1){
|
|
|
+ System.out.println("存在多个异常密钥" + secretKey);
|
|
|
+ }else if(list.size() == 1){
|
|
|
+ System.out.println("存在1个密钥 secretKey=" + list.get(0).getSecretKey());
|
|
|
+ }
|
|
|
if (list != null && list.size() == 1) {
|
|
|
intDetailed = list.get(0);
|
|
|
if(intDetailed.getRecordId() != null){ // 新接口解析密钥判断授权时效
|
|
|
// 解密后的明文是:123/政数局/2022-10-20 - 2022-10-29/b29c94d72ee74c6d94b573d90020ea59
|
|
|
- String duration = SecretKeyUtil.AESDncode("3fc674da58", intDetailed.getSecretKey().split("/")[2]);
|
|
|
+// String duration = SecretKeyUtil.AESDncode("3fc674da58", intDetailed.getSecretKey().split("/")[2]);
|
|
|
+ String secret_key = intDetailed.getSecretKey();
|
|
|
+ System.out.println("secret_key=" + secret_key);
|
|
|
+ String secret_content = SecretKeyUtil.AESDncode("3fc674da58", secret_key);
|
|
|
+ System.out.println("secret_content=" + secret_content);
|
|
|
+ String duration = secret_content.split("/")[2];
|
|
|
+// String duration = intDetailed.getSecretContent().split("/")[2];
|
|
|
+ System.out.println("duration=" + duration);
|
|
|
// 2022-10-20 - 2022-10-29
|
|
|
String startTime = duration.split(" - ")[0];
|
|
|
String endTime = duration.split(" - ")[1];
|
|
@@ -71,6 +98,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
System.out.println("旧接口按照原密钥接收数据,授权长期有效");
|
|
|
}
|
|
|
}else { // 授权失效或无此密钥及存在多个异常密钥,提示授权码到期请重新申请
|
|
|
+ String a ="1HjlUwOjkNCuvi+E8+r+4oYWPV1lDMF6l8E7GovGe9h4GtK4nDBXQKirD57TTku+08MHkHsS04X8xpKGQTrNOxG5LfweCxtHbmoUczwF9Y8=";
|
|
|
intDetailed = null;
|
|
|
isAuthExpires = true;
|
|
|
System.out.println("授权失效或无此密钥及存在多个异常密钥,提示授权码到期请重新申请");
|
|
@@ -79,7 +107,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
return ResultModel.error(ResultEnum.ERROR_AUTH_EXPIRES);
|
|
|
}
|
|
|
|
|
|
- if (!Objects.equals(intCode, intDetailed.getIntCode())) {
|
|
|
+ if (!Objects.equals(intCode, intDetailed.getCode()) && !Objects.equals(intCode, intDetailed.getCodeSp())) {// 旧秘钥验证 && 新秘钥验证
|
|
|
return ResultModel.error(ResultEnum.ERROR_INT_SECRET_KEY_MISMATCH);
|
|
|
}
|
|
|
|