Commit f787b905 authored by zhangzhenbang's avatar zhangzhenbang

试探性写了一两个接口

parent 635a5a1e
...@@ -11,4 +11,8 @@ public interface Const { ...@@ -11,4 +11,8 @@ public interface Const {
/* 人脸照片 单位K*/ /* 人脸照片 单位K*/
long FACE_IMG_SIZE = 30; long FACE_IMG_SIZE = 30;
/* 加解密公鑰 */
String KEY = "goubugoubawei";
} }
package com.yingxin.beijingvehicleflow.controller; package com.yingxin.beijingvehicleflow.controller;
import com.yingxin.beijingvehicleflow.constant.Const; import com.yingxin.beijingvehicleflow.constant.Const;
import com.yingxin.beijingvehicleflow.dto.EncodeData;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO; import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.dto.ReservationsDisplayDTO; import com.yingxin.beijingvehicleflow.dto.ReservationsDisplayDTO;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation; import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
...@@ -10,7 +11,9 @@ import com.yingxin.beijingvehicleflow.service.AuthService; ...@@ -10,7 +11,9 @@ import com.yingxin.beijingvehicleflow.service.AuthService;
import com.yingxin.beijingvehicleflow.service.IdentityInformationService; import com.yingxin.beijingvehicleflow.service.IdentityInformationService;
import com.yingxin.beijingvehicleflow.service.ReservationService; import com.yingxin.beijingvehicleflow.service.ReservationService;
import com.yingxin.beijingvehicleflow.util.AESUtil; import com.yingxin.beijingvehicleflow.util.AESUtil;
import com.yingxin.beijingvehicleflow.util.DesUtil;
import com.yingxin.beijingvehicleflow.util.PicUtils; import com.yingxin.beijingvehicleflow.util.PicUtils;
import net.sf.json.JSONException;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -142,8 +145,36 @@ public class IdentityInfoController { ...@@ -142,8 +145,36 @@ public class IdentityInfoController {
reservation.setAuthTime(sdf.format(date)); reservation.setAuthTime(sdf.format(date));
reservationInfoDTO.setReservation(reservation); reservationInfoDTO.setReservation(reservation);
return reservationService.isUpdateAuthInfoSucc(reservation)?Response.succ():Response.fail(); if (!reservationService.isUpdateAuthInfoSucc(reservation)) {
return Response.fail("UPDATE-FAILED","更新预约单认证信息失败");
}
EncodeData encodeData = new EncodeData(reservationInfoDTO);
return new Response<EncodeData>(true,"","", encodeData.encodeData());
}
@PostMapping("/identity/code")
public Response selectOneByEncodedId(@RequestBody String json) {
IdentityInformation info;
JSONObject datafterDecryptJson;
try {
JSONObject jsonObject = JSONObject.fromObject(json);
String encodedData = jsonObject.getString("encodedData");
String datafterDecryptStr = DesUtil.decrypt(Const.KEY, encodedData);
datafterDecryptJson = JSONObject.fromObject(datafterDecryptStr);
// String lastFourNumOfIdCard = resident.getrIdCard().substring(14);
// resident.setrIdCard(Constant.ID_CARD_14NUM_FLAG + lastFourNumOfIdCard);
} catch (JSONException e) {
LOGGER.error("解密查询接口Json解析异常", e);
return Response.fail("JSON-PARSE-ERROR","json解析异常");
}
catch (Exception e) {
LOGGER.error("解密查询接口异常", e);
return Response.fail("DECRYPT-ERROR","解密异常!");
}
return new Response<JSONObject>(true, "", "",datafterDecryptJson);
} }
} }
package com.yingxin.beijingvehicleflow.controller; package com.yingxin.beijingvehicleflow.controller;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO; import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.entity.Reservation; import com.yingxin.beijingvehicleflow.entity.Reservation;
import com.yingxin.beijingvehicleflow.response.Response; import com.yingxin.beijingvehicleflow.response.Response;
import com.yingxin.beijingvehicleflow.service.ReservationService; import com.yingxin.beijingvehicleflow.service.ReservationService;
...@@ -9,6 +10,8 @@ import org.slf4j.LoggerFactory; ...@@ -9,6 +10,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* description //TODO * description //TODO
* *
...@@ -37,7 +40,10 @@ public class ReservationController { ...@@ -37,7 +40,10 @@ public class ReservationController {
} }
@PostMapping("/reservations") @PostMapping("/reservations")
public Response selectReservatinsByIdentityId(@RequestBody Reservation reservation) { public Response selectNotVerifyReservatinsByIdentityId(@RequestBody IdentityInformation info) {
return null; List notVerifyReservationlist = reservationService.selectNotVerifyReservatinsByIdentityId(info);
return notVerifyReservationlist.size()==0?Response.succ():Response.fail();
} }
} }
package com.yingxin.beijingvehicleflow.dto; package com.yingxin.beijingvehicleflow.dto;
import com.yingxin.beijingvehicleflow.constant.Const;
import com.yingxin.beijingvehicleflow.util.DesUtil;
import lombok.Data;
import net.sf.json.JSONObject;
import java.util.HashMap;
/** /**
* description //TODO * description //TODO
* *
...@@ -8,6 +15,7 @@ package com.yingxin.beijingvehicleflow.dto; ...@@ -8,6 +15,7 @@ package com.yingxin.beijingvehicleflow.dto;
* @version 1.0 * @version 1.0
* @date 2020/2/24 * @date 2020/2/24
*/ */
@Data
public class EncodeData { public class EncodeData {
private ReservationInfoDTO data; private ReservationInfoDTO data;
...@@ -17,10 +25,15 @@ public class EncodeData { ...@@ -17,10 +25,15 @@ public class EncodeData {
this.data = data; this.data = data;
} }
// public EncodeData encodeData() { public EncodeData encodeData() {
// HashMap<String,Object> map = new HashMap<>(8);
// encodedData = DesUtil.encrypt(Constant.KEY, String.valueOf(resident.getrId())); map.put("authCoordinate", data.getReservation().getAuthCoordinate());
// map.put("authTime",data.getReservation().getAuthTime());
// return map.put("id",data.getReservation().getId());
// }
JSONObject jsonObject = JSONObject.fromObject(map);
encodedData = DesUtil.encrypt(Const.KEY, jsonObject.toString());
return this;
}
} }
package com.yingxin.beijingvehicleflow.mapper; package com.yingxin.beijingvehicleflow.mapper;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.entity.Reservation; import com.yingxin.beijingvehicleflow.entity.Reservation;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import java.util.List;
/** /**
* 数据库表单对应Mapper * 数据库表单对应Mapper
* *
...@@ -36,4 +40,6 @@ public interface ReservationMapper { ...@@ -36,4 +40,6 @@ public interface ReservationMapper {
@Update("update reservation set auth_coordinate=#{authCoordinate},auth_time=#{authTime} where id = #{id}") @Update("update reservation set auth_coordinate=#{authCoordinate},auth_time=#{authTime} where id = #{id}")
int updateAuthInfo(Reservation reservation); int updateAuthInfo(Reservation reservation);
@Select("select * from reservation where verify_state=0")
List<Reservation> selectNotVerifyReservatinsByIdentityId(IdentityInformation info);
} }
package com.yingxin.beijingvehicleflow.service; package com.yingxin.beijingvehicleflow.service;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO; import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.entity.Reservation; import com.yingxin.beijingvehicleflow.entity.Reservation;
import com.yingxin.beijingvehicleflow.response.Response; import com.yingxin.beijingvehicleflow.response.Response;
import java.util.List;
/** /**
* 预约表单相关服务 * 预约表单相关服务
* *
...@@ -18,4 +21,6 @@ public interface ReservationService { ...@@ -18,4 +21,6 @@ public interface ReservationService {
boolean isInsertReservationSucc(Reservation reservation); boolean isInsertReservationSucc(Reservation reservation);
boolean isUpdateAuthInfoSucc(Reservation reservation); boolean isUpdateAuthInfoSucc(Reservation reservation);
List<Reservation> selectNotVerifyReservatinsByIdentityId(IdentityInformation info);
} }
package com.yingxin.beijingvehicleflow.service.impl; package com.yingxin.beijingvehicleflow.service.impl;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO; import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.entity.Reservation; import com.yingxin.beijingvehicleflow.entity.Reservation;
import com.yingxin.beijingvehicleflow.mapper.ReservationMapper; import com.yingxin.beijingvehicleflow.mapper.ReservationMapper;
import com.yingxin.beijingvehicleflow.response.Response; import com.yingxin.beijingvehicleflow.response.Response;
...@@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* description //TODO * description //TODO
...@@ -76,4 +78,9 @@ public class ReservationServiceImpl implements ReservationService { ...@@ -76,4 +78,9 @@ public class ReservationServiceImpl implements ReservationService {
return false; return false;
} }
} }
@Override
public List<Reservation> selectNotVerifyReservatinsByIdentityId(IdentityInformation info) {
return reservationMapper.selectNotVerifyReservatinsByIdentityId(info);
}
} }
package com.yingxin.beijingvehicleflow.util;
import net.sf.json.JSONObject;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.security.Key;
import java.util.Base64;
/**
* @auther 李晓阳
* @email lixy@yingxininfo.net
* @date 2020/2/15 19:50
*/
public class DesUtil {
/**
* 偏移变量,固定占8位字节
*/
private final static String IV_PARAMETER = "12345678";
/**
* 密钥算法
*/
private static final String ALGORITHM = "DES";
/**
* 加密/解密算法-工作模式-填充模式
*/
private static final String CIPHER_ALGORITHM = "DES/CBC/PKCS5Padding";
/**
* 默认编码
*/
private static final String CHARSET = "utf-8";
/**
* 生成key
*
* @param password 密码
* @return 返回密钥对象
* @throws Exception
*/
private static Key generateKey(String password) throws Exception {
// 设置密钥参数
DESKeySpec dks = new DESKeySpec(password.getBytes(CHARSET));
//获得密钥工厂
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
return keyFactory.generateSecret(dks);
}
/**
* DES加密字符串
*
* @param password 加密密码,长度不能够小于8位
* @param data 待加密字符串
* @return 加密后内容
*/
public static String encrypt(String password, String data) {
if (password== null || password.length() < 8) {
throw new RuntimeException("加密失败,key不能小于8位");
}
if (data == null) {
return null;
}
try {
Key secretKey = generateKey(password);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
// AlgorithmParameterSpec加密算法的参数接口,IvParameterSpec是它的一个实现
//设置向量
IvParameterSpec iv = new IvParameterSpec(IV_PARAMETER.getBytes(CHARSET));
// 设置工作模式为加密模式,给出密钥和向量
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
byte[] bytes = cipher.doFinal(data.getBytes(CHARSET));
//JDK1.8及以上可直接使用Base64,JDK1.7及以下可以使用BASE64Encoder
return new String(Base64.getEncoder().encode(bytes));
} catch (Exception e) {
e.printStackTrace();
return data;
}
}
/**
* DES解密字符串
*
* @param password 解密密码,长度不能够小于8位
* @param data 待解密字符串
* @return 解密后内容
*/
public static String decrypt(String password, String data) {
if (password== null || password.length() < 8) {
throw new RuntimeException("加密失败,key不能小于8位");
}
if (data == null)
return null;
try {
Key secretKey = generateKey(password);
//得到加解密对象Cipher
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
//设置向量
IvParameterSpec iv = new IvParameterSpec(IV_PARAMETER.getBytes(CHARSET));
// 设置工作模式为解密模式,给出密钥和向量
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
return new String(cipher.doFinal(Base64.getDecoder().decode(data.getBytes(CHARSET))), CHARSET);
} catch (Exception e) {
e.printStackTrace();
return data;
}
}
public static String transformObjectToJsonString(Object object) {
return JSONObject.fromObject(object).toString();
}
// public static void main(String[] args) throws Exception {
// String password = "sjskslscscsclksc";
// String data = "{\"hello\":\"word\",\"what\":\"are you\"}";
//
// JSONObject jsonObject = JSONObject.fromObject(Response. fail());
// String jsonToString = jsonObject.toString();
//
// //加密
// String encodeData = DesUtil.encrypt(password,jsonToString);
// System.out.println("加密:" + encodeData);
// //解密
// String decodeData = DesUtil.decrypt(password,encodeData);
// System.out.println("解密:" + decodeData);
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment