跨服务调用校验身份
This commit is contained in:
+30
-21
@@ -31,7 +31,7 @@ import com.jero.project.entity.PayWorkingGroup;
|
|||||||
import com.jero.project.entity.PayWorkingGroupSubItem;
|
import com.jero.project.entity.PayWorkingGroupSubItem;
|
||||||
import com.jero.project.mapper.PayCommonProjectMapper;
|
import com.jero.project.mapper.PayCommonProjectMapper;
|
||||||
import com.jero.project.mapper.PayWorkingGroupSubItemMapper;
|
import com.jero.project.mapper.PayWorkingGroupSubItemMapper;
|
||||||
import com.jero.util.standardsUtil;
|
import com.jero.util.AuthenticationUtils;
|
||||||
import io.lettuce.core.dynamic.annotation.Param;
|
import io.lettuce.core.dynamic.annotation.Param;
|
||||||
import org.apache.commons.beanutils.PropertyUtils;
|
import org.apache.commons.beanutils.PropertyUtils;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
@@ -73,11 +73,13 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
|
|||||||
private PayMemberProjectSubitemMapper payMemberProjectSubitemMapper;
|
private PayMemberProjectSubitemMapper payMemberProjectSubitemMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TbMemberProjectSubitemMapper tbMemberProjectSubitemMapper;
|
private TbMemberProjectSubitemMapper tbMemberProjectSubitemMapper;
|
||||||
|
@Resource
|
||||||
|
private AuthenticationUtils authenticationUtils;
|
||||||
|
|
||||||
@Value("${jero.path.upload}")
|
@Value("${jero.path.upload}")
|
||||||
private String upLoadPath;
|
private String upLoadPath;
|
||||||
@Value("${standards.url}")
|
@Value("${standards.url}")
|
||||||
private static String url;
|
private String url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 到账开票主列表
|
* 到账开票主列表
|
||||||
@@ -86,16 +88,6 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<PayCommonProject> mainList(Page page, PayCommonProject payCommonProject){
|
public List<PayCommonProject> mainList(Page page, PayCommonProject payCommonProject){
|
||||||
//从标协项目获取公钥
|
|
||||||
// String publicKey = HttpUtil.get("http://localhost:8080/api/authenticationUtils/getPublicKey");
|
|
||||||
|
|
||||||
HashMap<String, Object> paramMap = new HashMap<>();
|
|
||||||
|
|
||||||
paramMap.put("token", standardsUtil.encryptByRsaPriKey().get("token"));
|
|
||||||
paramMap.put("publicKey", standardsUtil.encryptByRsaPriKey().get("publicKey"));
|
|
||||||
|
|
||||||
String result3= HttpUtil.get("http://localhost:8080/api/paymentInfo/incomingPaymentCheck", paramMap);
|
|
||||||
|
|
||||||
return payPaymentRecordMapper.mainList(page, payCommonProject);
|
return payPaymentRecordMapper.mainList(page, payCommonProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +97,6 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
|
|||||||
* @param payPaymentRecord
|
* @param payPaymentRecord
|
||||||
*/
|
*/
|
||||||
public Result<?> addPhase(PayPaymentRecord payPaymentRecord){
|
public Result<?> addPhase(PayPaymentRecord payPaymentRecord){
|
||||||
//来款记录表新增
|
|
||||||
insertPayPaymentRecord(payPaymentRecord);
|
|
||||||
|
|
||||||
BigDecimal receivableAmount;
|
BigDecimal receivableAmount;
|
||||||
Boolean isAdd;
|
Boolean isAdd;
|
||||||
@@ -195,14 +185,17 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
|
|||||||
member.setPaidAmount(newPaidAmount);
|
member.setPaidAmount(newPaidAmount);
|
||||||
member.setInAccount(inAccount);
|
member.setInAccount(inAccount);
|
||||||
payMemberProjectSubitemMapper.updateById(member);
|
payMemberProjectSubitemMapper.updateById(member);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
return Result.error("到账金额大于当前欠款金额,不可提交!");
|
return Result.error("到账金额大于当前欠款金额,不可提交!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//标协会员
|
//标协会员
|
||||||
case PayIncomeContractCommon.PROJECT_TYPE5:
|
case PayIncomeContractCommon.PROJECT_TYPE5:
|
||||||
TbMemberProjectSubitem tbMember = tbMemberProjectSubitemMapper.selectById(payPaymentRecord.getProjectId());
|
//标协类型条件校验
|
||||||
|
type5AddCheck(payPaymentRecord);
|
||||||
|
|
||||||
|
TbMemberProjectSubitem tbMember = tbMemberProjectSubitemMapper.selectById(payPaymentRecord.getProjectId());
|
||||||
receivableAmount = tbMember.getAmountReceivable();//应收
|
receivableAmount = tbMember.getAmountReceivable();//应收
|
||||||
paidAmount=tbMember.getPaidAmount();//实收
|
paidAmount=tbMember.getPaidAmount();//实收
|
||||||
|
|
||||||
@@ -216,19 +209,21 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
|
|||||||
tbMember.setPaidAmount(newPaidAmount);
|
tbMember.setPaidAmount(newPaidAmount);
|
||||||
tbMember.setInAccount(inAccount);
|
tbMember.setInAccount(inAccount);
|
||||||
tbMemberProjectSubitemMapper.updateById(tbMember);
|
tbMemberProjectSubitemMapper.updateById(tbMember);
|
||||||
|
|
||||||
|
sendToStandards();
|
||||||
}else{
|
}else{
|
||||||
return Result.error("到账金额大于当前欠款金额,不可提交!");
|
return Result.error("到账金额大于当前欠款金额,不可提交!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:break;
|
default:break;
|
||||||
}
|
}
|
||||||
|
//插入来款记录表
|
||||||
|
payPaymentRecordMapper.insert(payPaymentRecord);
|
||||||
return Result.OK("添加成功!");
|
return Result.OK("添加成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//来款记录表新增
|
//标协类型新增时条件校验
|
||||||
private void insertPayPaymentRecord(PayPaymentRecord payPaymentRecord){
|
private void type5AddCheck(PayPaymentRecord payPaymentRecord){
|
||||||
//如果是标协会员类型,只能新增一次
|
|
||||||
if(PayIncomeContractCommon.PROJECT_TYPE5.equals(String.valueOf(payPaymentRecord.getProjectType()))){
|
|
||||||
|
|
||||||
LambdaQueryWrapper<PayPaymentRecord> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<PayPaymentRecord> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(PayPaymentRecord::getProjectId, payPaymentRecord.getProjectId());
|
wrapper.eq(PayPaymentRecord::getProjectId, payPaymentRecord.getProjectId());
|
||||||
@@ -249,8 +244,7 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
|
|||||||
if(aRInsert.compareTo(debtInsert) != 0){
|
if(aRInsert.compareTo(debtInsert) != 0){
|
||||||
throw new JeroBootException("标协会员项目,到账金额不等于欠款金额。");
|
throw new JeroBootException("标协会员项目,到账金额不等于欠款金额。");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
payPaymentRecordMapper.insert(payPaymentRecord);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -328,6 +322,21 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标协会员来款推送到标协项目
|
||||||
|
*/
|
||||||
|
private void sendToStandards(){
|
||||||
|
//获取公钥并使用公钥加密token
|
||||||
|
Map<String, String> map = authenticationUtils.encryptByRsaPriKey();
|
||||||
|
|
||||||
|
HashMap<String, Object> paramMap = new HashMap<>();
|
||||||
|
|
||||||
|
paramMap.put("token", map.get("token"));
|
||||||
|
paramMap.put("publicKey", map.get("publicKey"));
|
||||||
|
|
||||||
|
String result3= HttpUtil.get(url+"/paymentInfo/incomingPaymentCheck", paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出
|
* 导出
|
||||||
* @param request
|
* @param request
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.jero.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.crypto.asymmetric.KeyType;
|
||||||
|
import cn.hutool.crypto.asymmetric.RSA;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import com.jero.common.util.RestUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跨服务调用时验证身份
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class AuthenticationUtils {
|
||||||
|
|
||||||
|
@Value("${standards.url}")
|
||||||
|
private String URL;
|
||||||
|
|
||||||
|
@Value("${standards.token}")
|
||||||
|
private String APPLICATION_TOKEN;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取公钥并使用公钥加密token
|
||||||
|
*/
|
||||||
|
public Map<String,String> encryptByRsaPriKey() {
|
||||||
|
|
||||||
|
Map<String,String> map= new HashMap<>();
|
||||||
|
//从标协项目获取公钥
|
||||||
|
String publicKey=HttpUtil.get(URL+"/authenticationUtils/getPublicKey");
|
||||||
|
|
||||||
|
RSA rsa = new RSA(null,publicKey);
|
||||||
|
|
||||||
|
byte[] token = rsa.encrypt(StrUtil.bytes(APPLICATION_TOKEN, CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||||
|
String tokenStr = Base64.getEncoder().encodeToString(token);
|
||||||
|
|
||||||
|
map.put("publicKey",publicKey);
|
||||||
|
map.put("token",tokenStr);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
package com.jero.util;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.crypto.asymmetric.KeyType;
|
|
||||||
import cn.hutool.crypto.asymmetric.RSA;
|
|
||||||
import cn.hutool.http.HttpUtil;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.jero.common.exception.JeroBootException;
|
|
||||||
import com.jero.common.util.RestUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.security.Key;
|
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author liJiaRao
|
|
||||||
* @date 2021-09-10 9:58
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class standardsUtil {
|
|
||||||
@Value("${standards.url}")
|
|
||||||
private static String url;
|
|
||||||
@Value("${standards.token}")
|
|
||||||
private static String token;
|
|
||||||
|
|
||||||
|
|
||||||
/** */
|
|
||||||
/**
|
|
||||||
* 加密算法RSA
|
|
||||||
*/
|
|
||||||
public static final String KEY_ALGORITHM = "RSA";
|
|
||||||
|
|
||||||
/** */
|
|
||||||
/**
|
|
||||||
* RSA最大加密明文大小
|
|
||||||
*/
|
|
||||||
private static final int MAX_ENCRYPT_BLOCK = 117;
|
|
||||||
|
|
||||||
|
|
||||||
public static String getRSAPublicKey(){
|
|
||||||
JSONObject jsonObject = RestUtil.get(url + "/commonUtils/getRSAPublicKey");
|
|
||||||
if (jsonObject.getBoolean("success")) {
|
|
||||||
return jsonObject.getString("result");
|
|
||||||
}else {
|
|
||||||
throw new JeroBootException("调用会员系统出错");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 公钥加密
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param data 源数据
|
|
||||||
* @param publicKey 公钥(BASE64编码)
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception {
|
|
||||||
byte[] keyBytes = Base64.decodeBase64(publicKey);
|
|
||||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
|
|
||||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
|
||||||
Key publicK = keyFactory.generatePublic(x509KeySpec);
|
|
||||||
// 对数据加密
|
|
||||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicK);
|
|
||||||
int inputLen = data.length;
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
int offSet = 0;
|
|
||||||
byte[] cache;
|
|
||||||
int i = 0;
|
|
||||||
// 对数据分段加密
|
|
||||||
while (inputLen - offSet > 0) {
|
|
||||||
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
|
|
||||||
cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
|
|
||||||
} else {
|
|
||||||
cache = cipher.doFinal(data, offSet, inputLen - offSet);
|
|
||||||
}
|
|
||||||
out.write(cache, 0, cache.length);
|
|
||||||
i++;
|
|
||||||
offSet = i * MAX_ENCRYPT_BLOCK;
|
|
||||||
}
|
|
||||||
byte[] encryptedData = out.toByteArray();
|
|
||||||
out.close();
|
|
||||||
return encryptedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用公钥加密token
|
|
||||||
*/
|
|
||||||
public static Map<String,String> encryptByRsaPriKey() {
|
|
||||||
Map<String,String> map= new HashMap<String,String>();
|
|
||||||
try {
|
|
||||||
//从标协项目获取公钥
|
|
||||||
String publicKey=HttpUtil.get("http://localhost:8080/api/authenticationUtils/getPublicKey");
|
|
||||||
|
|
||||||
String token= Base64.encodeBase64String(encryptByPublicKey("abc".getBytes(), publicKey));
|
|
||||||
|
|
||||||
map.put("publicKey",publicKey);
|
|
||||||
map.put("token",token);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.error("使用公钥加密token失败",e);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
server:
|
server:
|
||||||
port: 8081
|
port: 8080
|
||||||
tomcat:
|
tomcat:
|
||||||
max-swallow-size: -1
|
max-swallow-size: -1
|
||||||
error:
|
error:
|
||||||
@@ -308,6 +308,8 @@ huaWeiSms:
|
|||||||
appSecret: eGt7RfKNia8cK4Z3Vnw5QE4Uy108
|
appSecret: eGt7RfKNia8cK4Z3Vnw5QE4Uy108
|
||||||
# 短信开关
|
# 短信开关
|
||||||
open: false
|
open: false
|
||||||
|
|
||||||
|
#标协项目
|
||||||
standards:
|
standards:
|
||||||
url: http://loaclhots:8080/api
|
url: http://localhost:8081/api
|
||||||
token: Aa123456!!
|
token: Aa123456!!
|
||||||
Reference in New Issue
Block a user