|
|
|
@ -1,18 +1,39 @@
|
|
|
|
|
package com.chinaunicom.mall.ebtp.extend.crypconfigure.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.base.service.impl.BaseServiceImpl;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.constant.CommonConstants;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.crypto.service.CrypServiceImpl;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.uniBss.constant.UniBssConstant;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBss;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBssAttached;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBssBody;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBssHead;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.uniBss.service.UniBssServiceImpl;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLog;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.extend.blockchain.service.IBlockChainLogService;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.extend.crypconfigure.dao.CrypConfigureMapper;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
|
|
|
|
|
import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import static com.chinaunicom.mall.ebtp.common.uniBss.service.UniBssServiceImpl.MD5min;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 对数据表 biz_bid_cryp_configure 操作的 serviceImpl
|
|
|
|
@ -21,6 +42,61 @@ import java.util.List;
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMapper,CrypConfigure> implements ICrypConfigureService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IBlockChainLogService iBlockChainLogService;
|
|
|
|
|
|
|
|
|
|
@Value("${mconfig.bss.app-id}")
|
|
|
|
|
private String app_id;
|
|
|
|
|
@Value("${mconfig.bss.app-secret}")
|
|
|
|
|
private String app_secret;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 调用天擎接口
|
|
|
|
|
* @param bean
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean callUniInterface(CrypBean bean){
|
|
|
|
|
BlockChainLog log = new BlockChainLog();
|
|
|
|
|
log.setId(PropertyUtils.getSnowflakeId());
|
|
|
|
|
//天擎地址
|
|
|
|
|
log.setInterfaceUrl(bean.getUrl());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//传入数据解密
|
|
|
|
|
String sign = getSignValue(bean.getObject());
|
|
|
|
|
|
|
|
|
|
Map<String, String> map = JSONArray.parseObject(JSONArray.toJSONString(bean.getObject()), Map.class);
|
|
|
|
|
map.put("sign", sign);
|
|
|
|
|
|
|
|
|
|
String json = getUniBss(map);
|
|
|
|
|
log.setResult("天擎接口调用,地址:"+bean.getUrl()+",参数:"+json);//日志
|
|
|
|
|
log.setParam(json);
|
|
|
|
|
|
|
|
|
|
String str = UniBssServiceImpl.uniBssHttpPost(bean.getUrl(), json);
|
|
|
|
|
UniBss uniBssRsp = JSONArray.parseObject(str, UniBss.class);
|
|
|
|
|
if (uniBssRsp != null && UniBssConstant.RESP_CODE_00000.equals(uniBssRsp.getUniBssHead().getRespCode())) {
|
|
|
|
|
log.setStatus(0);//成功
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
log.setStatus(1);//失败
|
|
|
|
|
|
|
|
|
|
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.assertStringNotNullByKey("天擎接口调用错误," +
|
|
|
|
|
"RESP_CODE:" + uniBssRsp.getUniBssHead().getRespCode() + "" +
|
|
|
|
|
"(" + UniBssConstant.getRESP_CODE_Map(uniBssRsp.getUniBssHead().getRespCode()) + ")。" +
|
|
|
|
|
"RESP_DESC:" + uniBssRsp.getUniBssHead().getRespDesc(), bean);
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.setStatus(1);
|
|
|
|
|
log.setResult(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.iBlockChainLogService.save(log);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 加密
|
|
|
|
|
* @param object
|
|
|
|
@ -31,30 +107,72 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
|
|
|
|
CrypBean bean = new CrypBean();
|
|
|
|
|
try{
|
|
|
|
|
bean.setObject(object);
|
|
|
|
|
//查询
|
|
|
|
|
LambdaQueryWrapper<CrypConfigure> query = Wrappers.lambdaQuery();
|
|
|
|
|
query.eq(CrypConfigure::getState,"1")
|
|
|
|
|
.eq(CrypConfigure::getDeleteFlag, CommonConstants.STATUS_NORMAL)
|
|
|
|
|
.eq(CrypConfigure::getType,"1")
|
|
|
|
|
.eq(CrypConfigure::getCCode,"pem_key");
|
|
|
|
|
|
|
|
|
|
List<CrypConfigure> list = this.list(query);
|
|
|
|
|
String signValue = getSignValue(bean.getObject());
|
|
|
|
|
|
|
|
|
|
CrypConfigure crypConfigure = list.get(0);
|
|
|
|
|
|
|
|
|
|
String signValue = CrypServiceImpl.signObject2(bean.getObject(),crypConfigure.getCValue());
|
|
|
|
|
|
|
|
|
|
bean.setSing(signValue);
|
|
|
|
|
bean.setSign(signValue);
|
|
|
|
|
|
|
|
|
|
return bean;
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("加密异常:"+e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取加密签名
|
|
|
|
|
* @param object
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String getSignValue(Object object){
|
|
|
|
|
//查询
|
|
|
|
|
LambdaQueryWrapper<CrypConfigure> query = Wrappers.lambdaQuery();
|
|
|
|
|
query.eq(CrypConfigure::getState,"1")
|
|
|
|
|
.eq(CrypConfigure::getDeleteFlag, CommonConstants.STATUS_NORMAL)
|
|
|
|
|
.eq(CrypConfigure::getType,"1")
|
|
|
|
|
.eq(CrypConfigure::getCCode,"pem_key");
|
|
|
|
|
|
|
|
|
|
List<CrypConfigure> list = this.list(query);
|
|
|
|
|
|
|
|
|
|
CrypConfigure crypConfigure = list.get(0);
|
|
|
|
|
|
|
|
|
|
String signValue = CrypServiceImpl.signObject2(object,crypConfigure.getCValue());
|
|
|
|
|
|
|
|
|
|
return signValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取加密签名
|
|
|
|
|
* @param map
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String getUniBss(Map<String,String> map){
|
|
|
|
|
//获取token
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
|
|
|
|
|
SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
|
|
|
|
String TIMESTAMP = format.format(date);
|
|
|
|
|
String TRANS_ID = format2.format(date) + (int) ((Math.random() * 9 + 1) * 100000);
|
|
|
|
|
String s = "APP_ID" + app_id + "TIMESTAMP" + TIMESTAMP + "TRANS_ID" + TRANS_ID + app_secret;
|
|
|
|
|
String token = MD5min(s);
|
|
|
|
|
UniBss uniBss = new UniBss();
|
|
|
|
|
uniBss.setUniBssAttached(new UniBssAttached().setMediaInf(""));
|
|
|
|
|
|
|
|
|
|
UniBssHead head = new UniBssHead();
|
|
|
|
|
head.setAppId(app_id);
|
|
|
|
|
head.setTimeStamp(TIMESTAMP);
|
|
|
|
|
head.setTransId(TRANS_ID);
|
|
|
|
|
head.setToken(token);
|
|
|
|
|
uniBss.setUniBssHead(head);
|
|
|
|
|
|
|
|
|
|
UniBssBody body = new UniBssBody();
|
|
|
|
|
body.setSingleOrderQryReq(map);
|
|
|
|
|
|
|
|
|
|
uniBss.setUniBssBody(body);
|
|
|
|
|
|
|
|
|
|
return JSON.toJSONString(uniBss);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 解密
|
|
|
|
|
* @param bean
|
|
|
|
@ -74,7 +192,7 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
|
|
|
|
|
log.debug("---------获取解密秘钥--------");
|
|
|
|
|
CrypConfigure crypConfigure = list.get(0);
|
|
|
|
|
|
|
|
|
|
Boolean b = CrypServiceImpl.verifyValue(bean.getSing(),
|
|
|
|
|
Boolean b = CrypServiceImpl.verifyValue(bean.getSign(),
|
|
|
|
|
bean.getObject(),
|
|
|
|
|
crypConfigure.getCValue());
|
|
|
|
|
return b;
|
|
|
|
|