记得上下班打卡 | git大法好,push需谨慎

Commit 5d01ab7e authored by anjiabin's avatar anjiabin

至信链数字账户开通调整

parent 8987c844
...@@ -21,7 +21,8 @@ public class GalaxyConstant { ...@@ -21,7 +21,8 @@ public class GalaxyConstant {
//以下禁止删除 //以下禁止删除
public static final String REDIS_KEY_GALAXY_PUBLISH_NFT="galaxy:publish:nft:"; //nft索引递增记录 public static final String REDIS_KEY_GALAXY_PUBLISH_NFT="galaxy:publish:nft:"; //nft索引递增记录
public static final String SERIES_NAME_PREFIX="NOW_ZXL_";// 系列存储目录名称和系列声明
public static final String ADAM_USER_SYNC_URL="/rsc/syn/certmeta";// adam用户开通数字账户信息同步url
public static final String SERIES_NAME_PREFIX="NOW_ZXL_";// 系列存储目录名称和系列声明
} }
package com.liquidnet.service.galaxy.exception;
import lombok.Data;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: 自定义异常类
* @class: GalaxyNftUserException
* @Package com.liquidnet.service.galaxy.exception
* @Copyright: LightNet @ Copyright (c) 2022
* @date 2022/5/12 13:44
*/
@Data
public class GalaxyNftUserException extends RuntimeException{
private static final long serialVersionUID = -3916918823313768482L;
private String code;
private String message;
public GalaxyNftUserException(String code, String message) {
super(message);
this.code = code;
this.message = message;
}
public GalaxyNftUserException(String code, String message, Throwable t) {
super(message, t);
this.code = code;
this.message = message;
}
}
...@@ -328,8 +328,8 @@ public class MQConst { ...@@ -328,8 +328,8 @@ public class MQConst {
SQL_NFT_ORDER_INFO("galaxy:stream:rk.sql.nftOrderInfo", "group.sql.nftOrderInfo", "订单信息"), SQL_NFT_ORDER_INFO("galaxy:stream:rk.sql.nftOrderInfo", "group.sql.nftOrderInfo", "订单信息"),
SQL_NFT_TRADE_INFO("galaxy:stream:rk.sql.nftTradeInfo", "group.sql.nftTradeInfo", "交易信息"), SQL_NFT_TRADE_INFO("galaxy:stream:rk.sql.nftTradeInfo", "group.sql.nftTradeInfo", "交易信息"),
SQL_NFT_ORDER_FAIL_LOG("galaxy:stream:rk.sql.nftOrderFailLog", "group.sql.nftOrderFailLog", "交易发行购买失败记录"), SQL_NFT_ORDER_FAIL_LOG("galaxy:stream:rk.sql.nftOrderFailLog", "group.sql.nftOrderFailLog", "交易发行购买失败记录"),
JSON_NFT_PUBLISH_AND_BUY("galaxy:stream:rk.json.nftPublishAndBuy", "group.sql.nftPublishAndBuy", "NFT发行和购买"), JSON_NFT_PUBLISH_AND_BUY("galaxy:stream:rk.json.nftPublishAndBuy", "group.json.nftPublishAndBuy", "NFT发行和购买"),
; JSON_NFT_USER_REGISTER("galaxy:stream:rk.json.userRegister", "group.json.userRegister", "NFT用户注册");
private final String key; private final String key;
private final String group; private final String group;
private final String desc; private final String desc;
......
package com.liquidnet.service.consumer.kylin.config;
import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.kylin.receiver.ConsumerGalaxyJsonNftUserRegisterReceiver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
import java.util.ArrayList;
import java.util.List;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: 区块链nft订单相关
* @class: ConsumerSqlNftOrderInfoConfig
* @Package com.liquidnet.service.consumer.galaxy.config
* @Copyright: LightNet @ Copyright (c) 2022
* @date 2022/3/25 14:45
*/
@Configuration
public class ConsumerGalaxyJsonNftUserRegisterConfig extends RedisStreamConfig {
@Autowired
private ConsumerGalaxyJsonNftUserRegisterReceiver jsonNftUserRegisterReceiver;
@Autowired
StringRedisTemplate stringRedisTemplate;
@Bean
public List<Subscription> subscriptionJsonNftPublishAndBuy(RedisConnectionFactory factory) {
List<Subscription> subscriptionList = new ArrayList<>();
MQConst.GalaxyQueue stream = MQConst.GalaxyQueue.JSON_NFT_USER_REGISTER;
this.initStream(stringRedisTemplate, stream.getKey(), stream.getGroup());
for (int i = 0; i < 10; i++) {
StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer = this.buildStreamMessageListenerContainer(factory);
subscriptionList.add(listenerContainer.receiveAutoAck(
Consumer.from(stream.getGroup(), getConsumerName(stream.name() + i)),
StreamOffset.create(stream.getKey(), ReadOffset.lastConsumed()), jsonNftUserRegisterReceiver
));
listenerContainer.start();
}
return subscriptionList;
}
}
package com.liquidnet.service.consumer.kylin.receiver;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.kylin.service.processor.ConsumerGalaxyJsonNftUserRegisterProcessor;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterRespDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@Slf4j
@Component
public class ConsumerGalaxyJsonNftUserRegisterReceiver extends AbstractBizRedisReceiver {
@Autowired
private ConsumerGalaxyJsonNftUserRegisterProcessor jsonNftUserRegisterProcessor;
@Override
protected boolean consumerMessageHandler(String msg) {
boolean aBoolean = false;
try {
GalaxyUserRegisterReqDto textMessage = JsonUtils.fromJson(msg, GalaxyUserRegisterReqDto.class);
if (textMessage == null) {
aBoolean = true;
} else {
//执行计数
ResponseDto<GalaxyUserRegisterRespDto> responseDto = jsonNftUserRegisterProcessor.userRegister(textMessage);
// if(responseDto.isSuccess()){
aBoolean = true;
// }
}
} catch (Exception e) {
log.error("CONSUMER MSG EX_HANDLE ==> [{}]:{}", this.getRedisStreamKey(), msg, e);
} finally {
if (!aBoolean) {
HashMap<String, String> map = CollectionUtil.mapStringString();
map.put("message", msg);
stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(this.getRedisStreamKey()));
}
}
return aBoolean;
}
@Override
protected String getRedisStreamKey() {
return MQConst.GalaxyQueue.JSON_NFT_USER_REGISTER.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.GalaxyQueue.JSON_NFT_USER_REGISTER.getGroup();
}
}
package com.liquidnet.service.consumer.kylin.service.processor;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterRespDto;
import com.liquidnet.service.galaxy.router.zxin.biz.ZxinUserCommonBiz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: ConsumerJsonNftPublishAndBuyProcessor
* @Package com.liquidnet.service.consumer.kylin.service.processor
* @Copyright: LightNet @ Copyright (c) 2022
* @date 2022/3/29 17:04
*/
@Slf4j
@Component
public class ConsumerGalaxyJsonNftUserRegisterProcessor {
@Autowired
private ZxinUserCommonBiz zxinUserCommonBiz;
/**
* 执行用户注册
* @param reqDto
* @return
*/
public ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto) {
return zxinUserCommonBiz.userRegister(reqDto);
}
}
...@@ -31,5 +31,15 @@ ...@@ -31,5 +31,15 @@
<artifactId>liquidnet-service-galaxy-api</artifactId> <artifactId>liquidnet-service-galaxy-api</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-service-goblin-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-service-adam-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
package com.liquidnet.service.galaxy.router.zxin.biz;
import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.constant.ZxlErrorEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
import com.liquidnet.common.third.zxlnft.dto.nft.Nft016QueryRsData;
import com.liquidnet.common.third.zxlnft.dto.wallet.CreateMnemonicReq;
import com.liquidnet.common.third.zxlnft.dto.wallet.CreateMnemonicResp;
import com.liquidnet.common.third.zxlnft.dto.wallet.DeriveKeyPairReq;
import com.liquidnet.common.third.zxlnft.dto.wallet.DeriveKeyPairResp;
import com.liquidnet.common.third.zxlnft.exception.ZxlNftException;
import com.liquidnet.common.third.zxlnft.util.ZxlWalletSdkUtil;
import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.adam.constant.AdamEnum;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.galaxy.constant.GalaxyConstant;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterRespDto;
import com.liquidnet.service.galaxy.exception.GalaxyNftUserException;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.constant.NftAccStatusEnum;
import com.liquidnet.service.goblin.dto.GoblinUserNftAccInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: ZxinUserCommonBiz
* @Package com.liquidnet.service.galaxy.router.zxin.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/5/12 13:08
*/
@Slf4j
@Component
public class ZxinUserCommonBiz {
@Autowired
private ZxlnftSdkUtil zxlnftSdkUtil;
@Autowired
private ZxlnftBiz zxlnftBiz;
@Autowired
private GalaxyDataUtils dataUtils;
@Autowired
private ZxlWalletSdkUtil zxlWalletSdkUtil;
@Value("${liquidnet.service.adam.url}")
private String adamUrl;
public ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto) {
String userId = reqDto.getUserId();
String userName = reqDto.getUserName();
String mobile = reqDto.getMobile();
String idCardType = reqDto.getIdCardType();
String idCard = reqDto.getIdCard();
String mnemonic = null;
Long index = 0L;
String userIdentification = null;
String address = null;
String userPubKey = null;
String userPriKey = null;
//业务失败信息
String bizFailDesc = null;
//系统失败信息
String sysFailDesc = null;
//是否实名认证成功
boolean isRealNameAuthSuccess = false;
//是否绑定区块链地址
boolean isBindBlockAddressSuccess = false;
GalaxyUserRegisterRespDto respDto = GalaxyUserRegisterRespDto.getNew();
try{
/**
* todo 把助记词进行redis存储 key=userID mnemonic/index/userIdentification/address
*/
GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),userId);
if(userInfoBo!=null){
mnemonic = userInfoBo.getMnemonic();
if(StringUtil.isNotEmpty(userInfoBo.getBlockChainAddress())){
try{
//同步用户数字账户开通信息
boolean isOpenAccount = syncOpenAccount(reqDto,respDto.getBlockChainAddress(),bizFailDesc,sysFailDesc,true,true);
log.info("用户 {} 数字账户开通结果:{}",reqDto.getUserId(),isOpenAccount);
}catch(Exception e){
log.error("同步用户数字账户开通信息异常:"+e.getMessage(),e);
}
return ResponseDto.failure("已经开通过数字账户");
}
}else{
try{
//生成助记词
CreateMnemonicReq req = CreateMnemonicReq.getNew();
CreateMnemonicResp createMnemonicResp = zxlWalletSdkUtil.createMnemonic(req);
mnemonic = createMnemonicResp.getMnemonic();
}catch(Exception e){
log.error("生成助记词失败 msg:{}",e.getMessage(),e);
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),"生成助记词失败!");
}
}
if(StringUtil.isNotEmpty(mnemonic)){
//生成公私钥
DeriveKeyPairReq deriveKeyPairReq = DeriveKeyPairReq.getNew();
deriveKeyPairReq.setMnemonic(mnemonic);
// deriveKeyPairReq.setMnemonic(createMnemonicResp.getMnemonic());
deriveKeyPairReq.setIndex(index);
try{
DeriveKeyPairResp deriveKeyPairResp = zxlWalletSdkUtil.deriveKeyPair(deriveKeyPairReq);
if(!deriveKeyPairResp.getErr().equals("")) throw new Exception("生成公私钥失败!");
userPubKey = BASE64Util.encoded(deriveKeyPairResp.getPubKey());
userPriKey = BASE64Util.encoded(deriveKeyPairResp.getPriKey());
}catch(Exception e){
log.error("生成公私钥失败 msg:{}",e.getMessage(),e);
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),e.getMessage());
}
}
if(StringUtil.isNull(userInfoBo)){
//初始化用户信息
try{
//构造缓存数据
userInfoBo = GalaxyUserInfoBo.getNew();
userInfoBo.setUserId(userId);
userInfoBo.setUserName(userName);
userInfoBo.setMobile(mobile);
userInfoBo.setIdCardType(idCardType);
userInfoBo.setIdCard(idCard);
userInfoBo.setMnemonic(mnemonic);
userInfoBo.setIndex(index.toString());
userInfoBo.setUserIdentification(userIdentification);
userInfoBo.setUserPubKey(userPubKey);
userInfoBo.setUserPriKey(userPriKey);
userInfoBo.setRouterType(GalaxyEnum.RouterTypeEnum.ZXINCHAIN.getCode());
userInfoBo.setBlockChainAddress(address);
dataUtils.setGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId(),userInfoBo);
}catch(Exception e){
log.error("设置用户信息异常 msg:{}",e.getMessage(),e);
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),"设置用户信息异常");
}
}
//1.2.1调用自然人注册实名(使用NFT平台签名)接口
Nft003RegisterPersonPlatformReqDto nft003ReqDto = Nft003RegisterPersonPlatformReqDto.getNew();
nft003ReqDto.setPersonName(userName);
// reqDto.setEmail("");
nft003ReqDto.setMobile(mobile);
nft003ReqDto.setIdCard(idCard);
nft003ReqDto.setCardType(Integer.valueOf(idCardType));
ZxlnftResponseDto<Nft003RegisterPersonPlatformRespDto> nft003Resp = zxlnftSdkUtil.nft003RegisterPersonPlatform(nft003ReqDto);
if(nft003Resp.isSuccess()){
userIdentification = nft003Resp.getData().getUserIdentification();
isRealNameAuthSuccess = true;
}else{
throw new GalaxyNftUserException(nft003Resp.getCode(),nft003Resp.getMessage());
}
if(StringUtil.isNotEmpty(userPubKey)&&StringUtil.isNotEmpty(userPriKey)&&StringUtil.isNotEmpty(userIdentification)){
//1.2.2调用授信平台NFT地址绑定接口
Nft014IdentityBindSubmitByTrustedReqDto nft014ReqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
try {
nft014ReqDto.setUserPubKey(BASE64Util.decode(userPubKey));
nft014ReqDto.setUserIdentification(nft003Resp.getData().getUserIdentification());
String signature = zxlnftBiz.createSign(BASE64Util.decode(userPriKey),nft014ReqDto.getUserIdentification());
nft014ReqDto.setUserSignData(signature);
} catch (UnsupportedEncodingException e) {
log.error("公私钥解密错误!");
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),e.getMessage());
}
ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft014Resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(nft014ReqDto);
ZxlnftResponseDto<Nft016IdentityBindQueryRespDto> nft016Resp = null;
if(nft014Resp.isSuccess()){
//1.2.3调用绑定状态批量查询
Nft016IdentityBindQueryReqDto nft016ReqDto = Nft016IdentityBindQueryReqDto.getNew();
nft016ReqDto.setAddressList(nft014Resp.getData().getAddress());
nft016Resp = zxlnftSdkUtil.nft016IdentityBindQuery(nft016ReqDto);
}else{
log.info("nft014Resp 返回结果:{}",nft014Resp.toJson());
throw new GalaxyNftUserException(nft014Resp.getCode(),nft014Resp.getMessage());
}
if(StringUtil.isNotNull(nft016Resp)&&nft016Resp.isSuccess()){
List<Nft016QueryRsData> queryRsDataList = nft016Resp.getData().getList();
Nft016QueryRsData queryRsData = queryRsDataList.get(0);
address = queryRsData.getAddress();
log.info("nft016Resp 返回结果:{}",nft016Resp.toJson());
//构造返回参数
respDto.setUserId(userId);
respDto.setBlockChainType(GalaxyEnum.RouterTypeEnum.ZXINCHAIN.getCode());
respDto.setBlockChainAddress(address);
isBindBlockAddressSuccess = true;
}else{
throw new GalaxyNftUserException(nft016Resp.getCode(),nft016Resp.getMessage());
}
}
}catch (GalaxyNftUserException e) {
bizFailDesc = e.getMessage();
log.info(e.getMessage());
}catch(ZxlNftException e){
sysFailDesc = e.getMessage();
log.error(e.getMessage(),e);
}catch(Exception e){
sysFailDesc = e.getMessage();
log.error(e.getMessage(),e);
}
try{
//同步用户数字账户开通信息
boolean isOpenAccount = syncOpenAccount(reqDto,respDto.getBlockChainAddress(),bizFailDesc,sysFailDesc,isRealNameAuthSuccess,isBindBlockAddressSuccess);
log.info("用户 {} 数字账户开通结果:{}",reqDto.getUserId(),isOpenAccount);
}catch(Exception e){
log.error("同步用户数字账户开通信息异常:"+e.getMessage(),e);
}
if(StringUtil.isNotEmpty(sysFailDesc)){
return ResponseDto.failure(sysFailDesc);
}
if(StringUtil.isNotEmpty(bizFailDesc)){
return ResponseDto.failure(bizFailDesc);
}
return ResponseDto.success(respDto);
}
/**
* 同步用户数字账户开通信息
* @param reqDto
* @param bizFailDesc
* @param sysFailDesc
* @param isRealNameAuthSuccess
* @param isBindBlockAddressSuccess
* @return
*/
public boolean syncOpenAccount(GalaxyUserRegisterReqDto reqDto,String blockChainAddress,String bizFailDesc,String sysFailDesc,
boolean isRealNameAuthSuccess,boolean isBindBlockAddressSuccess){
long openAccSuccessKeyExpireTime = 3600*24*30*3;
long openAccFailKeyExpireTime = 60*5;
//是否开通数字账户
boolean isOpenAccount = false;
//开通失败错误信息
String resultCode = null;
String resultMessage = null;
//实名成功+绑定区块链地址成功
if(isRealNameAuthSuccess && isBindBlockAddressSuccess){
isOpenAccount = true;
resultCode = NftAccStatusEnum.StatusAcc.SUCCESS.getCode();
resultMessage = NftAccStatusEnum.StatusAcc.SUCCESS.getMsg();
}
//开通数字账户失败
if(!isOpenAccount){
//实名失败
if(!isRealNameAuthSuccess){
resultCode = NftAccStatusEnum.StatusAcc.FAILURE1.getCode();
resultMessage = NftAccStatusEnum.StatusAcc.FAILURE1.getMsg();
}else{
//地址绑定失败
if(!isBindBlockAddressSuccess){
if(StringUtil.isNotEmpty(bizFailDesc)){
resultCode = NftAccStatusEnum.StatusAcc.FAILURE3.getCode();
resultMessage = NftAccStatusEnum.StatusAcc.FAILURE3.getMsg();
}else if(StringUtil.isNotEmpty(sysFailDesc)){
resultCode = NftAccStatusEnum.StatusAcc.FAILURE2.getCode();
resultMessage = NftAccStatusEnum.StatusAcc.FAILURE2.getMsg();
}
}
}
}
//更新至信链开户状态
GoblinUserNftAccInfoVo goblinUserNftAccInfoVo = GoblinUserNftAccInfoVo.getNew();
goblinUserNftAccInfoVo.setCode(resultCode);
goblinUserNftAccInfoVo.setMsg(resultMessage);
goblinUserNftAccInfoVo.setTime(LocalDateTime.now());
if(isOpenAccount){
//更新开户状态
dataUtils.getRedisUtil().set(GoblinRedisConst.REDIS_GOBLIN_NFT_NUM_ACCOUNT_INFO.concat(reqDto.getUserId())
,goblinUserNftAccInfoVo);
//同步用户信息到adam 格式:{uid},{mobile},{证件类型}{证件号},{姓名}
syncUserAccountInfoToAdam(reqDto);
//同步业务账号关联关系到adam
dataUtils.getQueueUtil().sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("adam_user_busi_acct.add", reqDto.getUserId(), AdamEnum.BizAcct.NFT_ZX.name(), blockChainAddress, null, null, 1, LocalDateTime.now())
);
//开户成功记录缓存 {goblin:nft:certmeta:{idType+idNo},{idname,mobile}}
dataUtils.getRedisUtil().set(GoblinRedisConst.REDIS_GOBLIN_NFT_CERTMETA.concat(reqDto.getIdCardType().concat(reqDto.getIdCard()))
,reqDto.getUserName().concat(",").concat(reqDto.getMobile()),openAccSuccessKeyExpireTime);
}else{
//更新开户状态
dataUtils.getRedisUtil().set(GoblinRedisConst.REDIS_GOBLIN_NFT_NUM_ACCOUNT_INFO.concat(reqDto.getUserId())
,goblinUserNftAccInfoVo,openAccFailKeyExpireTime);
}
//设置错误信息到redis
if(StringUtil.isNotEmpty(resultCode)){
//开户失败记录缓存 {goblin:nft:certmeta:{idType+idNo},{idname,mobile}}
dataUtils.getRedisUtil().set(GoblinRedisConst.REDIS_GOBLIN_NFT_CERTMETA_JUNK.concat(reqDto.getIdCardType().concat(reqDto.getIdCard()))
,reqDto.getUserName().concat(",").concat(reqDto.getMobile()),openAccFailKeyExpireTime);
}
return isOpenAccount;
}
/**
* 同步用户信息到adam 格式:{uid},{mobile},{证件类型}{证件号},{姓名}
* @param reqDto
* @return
*/
private boolean syncUserAccountInfoToAdam(GalaxyUserRegisterReqDto reqDto) {
try {
String certmetaInfo = reqDto.getUserId().concat(",")
.concat(reqDto.getMobile()).concat(",")
.concat(reqDto.getIdCardType().concat(reqDto.getIdCard())).concat(",")
.concat(reqDto.getUserName());
//加密用户信息
DESUtils desUtils = DESUtils.DES();
MultiValueMap<String, String> params = new LinkedMultiValueMap();
params.add("certmeta",desUtils.encrypt(certmetaInfo));
HttpUtil.post(adamUrl + GalaxyConstant.ADAM_USER_SYNC_URL, params);
} catch (Exception e) {
log.error("同步用户信息到adam异常:{}",JsonUtils.toJson(reqDto), e);
return false;
}
return true;
}
// public ResponseDto<GalaxyUserRegisterRespDto> userRegister2(GalaxyUserRegisterReqDto reqDto) {
// String userId = reqDto.getUserId();
// String userName = reqDto.getUserName();
// String mobile = reqDto.getMobile();
// String idCardType = reqDto.getIdCardType();
// String idCard = reqDto.getIdCard();
// String mnemonic = null;
// Long index = 0L;
// String userIdentification = null;
// String address = null;
// String userPubKey = null;
// String userPriKey = null;
//
// GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),userId);
// if(userInfoBo!=null){
// mnemonic = userInfoBo.getMnemonic();
// }else{
// try{
// //生成助记词
// CreateMnemonicReq req = CreateMnemonicReq.getNew();
// CreateMnemonicResp createMnemonicResp = zxlWalletSdkUtil.createMnemonic(req);
// mnemonic = createMnemonicResp.getMnemonic();
// }catch(Exception e){
// throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),"生成助记词失败!");
// }
// }
//
//
// /**
// * todo 把助记词进行redis存储 key=userID mnemonic/index/userIdentification/address
// */
//
// if(StringUtil.isNotEmpty(mnemonic)){
// //生成公私钥
// DeriveKeyPairReq deriveKeyPairReq = DeriveKeyPairReq.getNew();
// deriveKeyPairReq.setMnemonic(mnemonic);
//// deriveKeyPairReq.setMnemonic(createMnemonicResp.getMnemonic());
// deriveKeyPairReq.setIndex(index);
// try{
// DeriveKeyPairResp deriveKeyPairResp = zxlWalletSdkUtil.deriveKeyPair(deriveKeyPairReq);
// if(!deriveKeyPairResp.getErr().equals("")) throw new Exception("生成公私钥失败!");
// userPubKey = BASE64Util.encoded(deriveKeyPairResp.getPubKey());
// userPriKey = BASE64Util.encoded(deriveKeyPairResp.getPriKey());
// }catch(Exception e){
// throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),e.getMessage());
// }
// }
//
// //1.2.1调用自然人注册实名(使用NFT平台签名)接口
// Nft003RegisterPersonPlatformReqDto nft003ReqDto = Nft003RegisterPersonPlatformReqDto.getNew();
// nft003ReqDto.setPersonName(userName);
//// reqDto.setEmail("");
// nft003ReqDto.setMobile(mobile);
// nft003ReqDto.setIdCard(idCard);
//
// nft003ReqDto.setCardType(Integer.valueOf(idCardType));
// ZxlnftResponseDto<Nft003RegisterPersonPlatformRespDto> nft003Resp = zxlnftSdkUtil.nft003RegisterPersonPlatform(nft003ReqDto);
//
// if(nft003Resp.isSuccess()){
// userIdentification = nft003Resp.getData().getUserIdentification();
// }else{
// return ResponseDto.failure(nft003Resp.getCode(),nft003Resp.getMessage());
// }
//
// GalaxyUserRegisterRespDto respDto = GalaxyUserRegisterRespDto.getNew();
//
// if(StringUtil.isNotEmpty(userPubKey)&&StringUtil.isNotEmpty(userPriKey)&&StringUtil.isNotEmpty(userIdentification)){
// //1.2.2调用授信平台NFT地址绑定接口
// Nft014IdentityBindSubmitByTrustedReqDto nft014ReqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
//
// try {
// nft014ReqDto.setUserPubKey(BASE64Util.decode(userPubKey));
// nft014ReqDto.setUserIdentification(nft003Resp.getData().getUserIdentification());
//
// String signature = zxlnftBiz.createSign(BASE64Util.decode(userPriKey),nft014ReqDto.getUserIdentification());
// nft014ReqDto.setUserSignData(signature);
// } catch (UnsupportedEncodingException e) {
// log.error("公私钥解密错误!");
// }
//
// ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft014Resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(nft014ReqDto);
//
// ZxlnftResponseDto<Nft016IdentityBindQueryRespDto> nft016Resp = null;
// if(nft014Resp.isSuccess()){
// //1.2.3调用绑定状态批量查询
// Nft016IdentityBindQueryReqDto nft016ReqDto = Nft016IdentityBindQueryReqDto.getNew();
// nft016ReqDto.setAddressList(nft014Resp.getData().getAddress());
// nft016Resp = zxlnftSdkUtil.nft016IdentityBindQuery(nft016ReqDto);
// }else{
// log.info("nft014Resp 返回结果:{}",nft014Resp.toJson());
// return ResponseDto.failure(nft014Resp.getCode(),nft014Resp.getMessage());
// }
//
// if(StringUtil.isNotNull(nft016Resp)&&nft016Resp.isSuccess()){
// List<Nft016QueryRsData> queryRsDataList = nft016Resp.getData().getList();
// Nft016QueryRsData queryRsData = queryRsDataList.get(0);
// address = queryRsData.getAddress();
// log.info("nft016Resp 返回结果:{}",nft016Resp.toJson());
// //构造返回参数
// respDto.setUserId(userId);
// respDto.setBlockChainType(GalaxyEnum.RouterTypeEnum.ZXINCHAIN.getCode());
// respDto.setBlockChainAddress(address);
// }else{
// return ResponseDto.failure(nft016Resp.getMessage());
// }
//
//
// //构造缓存数据
// if(userInfoBo==null){
// userInfoBo = GalaxyUserInfoBo.getNew();
// userInfoBo.setUserId(userId);
// userInfoBo.setUserName(userName);
// userInfoBo.setMobile(mobile);
// userInfoBo.setIdCardType(idCardType);
// userInfoBo.setIdCard(idCard);
// userInfoBo.setMnemonic(mnemonic);
// userInfoBo.setIndex(index.toString());
// userInfoBo.setUserIdentification(userIdentification);
// userInfoBo.setUserPubKey(userPubKey);
// userInfoBo.setUserPriKey(userPriKey);
// userInfoBo.setRouterType(GalaxyEnum.RouterTypeEnum.ZXINCHAIN.getCode());
// userInfoBo.setBlockChainAddress(address);
// dataUtils.setGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId(),userInfoBo);
// }else{
//
// }
// }
// return ResponseDto.success(respDto);
// }
}
...@@ -42,6 +42,35 @@ public abstract class AbstractDataUtils { ...@@ -42,6 +42,35 @@ public abstract class AbstractDataUtils {
userInfoVo.setCreatedAt(LocalDateTime.now()); userInfoVo.setCreatedAt(LocalDateTime.now());
this.getMongoTemplate().save(userInfoVo,GalaxyUserInfoVo.class.getSimpleName()); this.getMongoTemplate().save(userInfoVo,GalaxyUserInfoVo.class.getSimpleName());
// insert into galaxy_user_info (mid, user_id, user_name, user_type, mobile, id_card_type
// , id_card, mnemonic, index,user_identification, user_pub_key
// , user_pri_key, block_chain_address, router_type,created_at, updated_at)
try{
this.getQueueUtil().sendMySqlRedis(
SqlMapping.get("galaxy_user_info.insert"),
new Object[]{userId,userInfoBo.getUserName(),userType,userInfoBo.getMobile(),userInfoBo.getIdCardType()
,userInfoBo.getIdCard(),userInfoBo.getMnemonic(),userInfoBo.getIndex(),userInfoBo.getUserIdentification(),userInfoBo.getUserPubKey()
,userInfoBo.getUserPriKey(),userInfoBo.getBlockChainAddress(),userInfoBo.getRouterType(),new Date(),null
}
, MQConst.GalaxyQueue.SQL_USER_INFO.getKey()
);
}catch(Exception e){
log.error(e.getMessage(),e);
log.error("#setGalaxyUserInfo error ==> MESSAGE:{}",e.getMessage());
}
}
public void updateGalaxyUserInfo(String routerType,String userId, GalaxyUserInfoBo userInfoBo) {
String userType = GalaxyEnum.RegisterTypeEnum.PERSON.getCode();
this.getRedisUtil().set(GalaxyConstant.REDIS_KEY_GALAXY_USER.concat(routerType).concat(":") + userId,userInfoBo);
//入库mongo
GalaxyUserInfoVo userInfoVo = GalaxyUserInfoVo.getNew();
BeanUtil.copy(userInfoBo,userInfoVo);
userInfoVo.setCreatedAt(LocalDateTime.now());
this.getMongoTemplate().save(userInfoVo,GalaxyUserInfoVo.class.getSimpleName());
// insert into galaxy_user_info (mid, user_id, user_name, user_type, mobile, id_card_type // insert into galaxy_user_info (mid, user_id, user_name, user_type, mobile, id_card_type
// , id_card, mnemonic, index,user_identification, user_pub_key // , id_card, mnemonic, index,user_identification, user_pub_key
// , user_pri_key, block_chain_address, router_type,created_at, updated_at) // , user_pri_key, block_chain_address, router_type,created_at, updated_at)
......
...@@ -26,3 +26,5 @@ galaxy_series_nft_info.updateSeriesNftCrtCount=update galaxy_series_nft_info t s ...@@ -26,3 +26,5 @@ galaxy_series_nft_info.updateSeriesNftCrtCount=update galaxy_series_nft_info t s
# ------------------------更新发行购买处理结果---------------------------- # ------------------------更新发行购买处理结果----------------------------
galaxy_nft_order_fail_log.updateDealWithStatus=update galaxy_nft_order_fail_log t set t.deal_with_status = ?,t.updated_at =? where t.nft_order_pay_id = ? and t.router_type = ? galaxy_nft_order_fail_log.updateDealWithStatus=update galaxy_nft_order_fail_log t set t.deal_with_status = ?,t.updated_at =? where t.nft_order_pay_id = ? and t.router_type = ?
# ------------------------同步用户数字账户信息到adam---------------------------
adam_user_busi_acct.add=INSERT INTO adam_user_busi_acct (`uid`, busi, uuid, `work`, ppwd, `state`, created_at) VALUES (?,?,?,?,?,?,?)
...@@ -67,6 +67,11 @@ public class GalaxyTradeController { ...@@ -67,6 +67,11 @@ public class GalaxyTradeController {
@ApiOperation(value = "NFT发行购买结果查询") @ApiOperation(value = "NFT发行购买结果查询")
@PostMapping(value = {"nftPublishAndBuyResultQuery"}) @PostMapping(value = {"nftPublishAndBuyResultQuery"})
public ResponseDto<GalaxyNftPublishAndBuyResultQueryRespDto> nftPublishAndBuyResultQuery(@Valid @RequestBody GalaxyNftPublishAndBuyResultQueryReqDto reqDto){ public ResponseDto<GalaxyNftPublishAndBuyResultQueryRespDto> nftPublishAndBuyResultQuery(@Valid @RequestBody GalaxyNftPublishAndBuyResultQueryReqDto reqDto){
try {
Thread.sleep(2000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
return galaxyTradeService.nftPublishAndBuyResultQuery(reqDto); return galaxyTradeService.nftPublishAndBuyResultQuery(reqDto);
} }
......
package com.liquidnet.service.galaxy.router.zxin.biz; package com.liquidnet.service.galaxy.router.zxin.biz;
import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz; import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.constant.ZxlErrorEnum; import com.liquidnet.common.third.zxlnft.dto.Nft016IdentityBindQueryReqDto;
import com.liquidnet.common.third.zxlnft.dto.*; import com.liquidnet.common.third.zxlnft.dto.Nft016IdentityBindQueryRespDto;
import com.liquidnet.common.third.zxlnft.dto.ZxlnftResponseDto;
import com.liquidnet.common.third.zxlnft.dto.nft.Nft016QueryRsData; import com.liquidnet.common.third.zxlnft.dto.nft.Nft016QueryRsData;
import com.liquidnet.common.third.zxlnft.dto.wallet.CreateMnemonicReq;
import com.liquidnet.common.third.zxlnft.dto.wallet.CreateMnemonicResp;
import com.liquidnet.common.third.zxlnft.dto.wallet.DeriveKeyPairReq;
import com.liquidnet.common.third.zxlnft.dto.wallet.DeriveKeyPairResp;
import com.liquidnet.common.third.zxlnft.exception.ZxlNftException;
import com.liquidnet.common.third.zxlnft.util.ZxlWalletSdkUtil; import com.liquidnet.common.third.zxlnft.util.ZxlWalletSdkUtil;
import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil; import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.BASE64Util;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.biz.GalaxyEnumBiz; import com.liquidnet.service.galaxy.biz.GalaxyEnumBiz;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserBindStatusQueryReqDto; import com.liquidnet.service.galaxy.dto.param.GalaxyUserBindStatusQueryReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserBindStatusQueryRespDto; import com.liquidnet.service.galaxy.dto.param.GalaxyUserBindStatusQueryRespDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto; import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto;
...@@ -26,9 +18,6 @@ import lombok.extern.slf4j.Slf4j; ...@@ -26,9 +18,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.util.List;
/** /**
* @author AnJiabin <anjiabin@zhengzai.tv> * @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0 * @version V1.0
...@@ -53,132 +42,11 @@ public class ZxinUserBiz { ...@@ -53,132 +42,11 @@ public class ZxinUserBiz {
@Autowired @Autowired
private GalaxyDataUtils dataUtils; private GalaxyDataUtils dataUtils;
public ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto) { @Autowired
String userId = reqDto.getUserId(); private ZxinUserCommonBiz zxinUserCommonBiz;
String userName = reqDto.getUserName();
String mobile = reqDto.getMobile();
String idCardType = reqDto.getIdCardType();
String idCard = reqDto.getIdCard();
String mnemonic = null;
Long index = 0L;
String userIdentification = null;
String address = null;
String userPubKey = null;
String userPriKey = null;
GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),userId);
if(userInfoBo!=null){
mnemonic = userInfoBo.getMnemonic();
}else{
try{
//生成助记词
CreateMnemonicReq req = CreateMnemonicReq.getNew();
CreateMnemonicResp createMnemonicResp = zxlWalletSdkUtil.createMnemonic(req);
mnemonic = createMnemonicResp.getMnemonic();
}catch(Exception e){
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),"生成助记词失败!");
}
}
/**
* todo 把助记词进行redis存储 key=userID mnemonic/index/userIdentification/address
*/
if(StringUtil.isNotEmpty(mnemonic)){
//生成公私钥
DeriveKeyPairReq deriveKeyPairReq = DeriveKeyPairReq.getNew();
deriveKeyPairReq.setMnemonic(mnemonic);
// deriveKeyPairReq.setMnemonic(createMnemonicResp.getMnemonic());
deriveKeyPairReq.setIndex(index);
try{
DeriveKeyPairResp deriveKeyPairResp = zxlWalletSdkUtil.deriveKeyPair(deriveKeyPairReq);
if(!deriveKeyPairResp.getErr().equals("")) throw new Exception("生成公私钥失败!");
userPubKey = BASE64Util.encoded(deriveKeyPairResp.getPubKey());
userPriKey = BASE64Util.encoded(deriveKeyPairResp.getPriKey());
}catch(Exception e){
throw new ZxlNftException(ZxlErrorEnum.FAILURE.getCode(),e.getMessage());
}
}
//1.2.1调用自然人注册实名(使用NFT平台签名)接口
Nft003RegisterPersonPlatformReqDto nft003ReqDto = Nft003RegisterPersonPlatformReqDto.getNew();
nft003ReqDto.setPersonName(userName);
// reqDto.setEmail("");
nft003ReqDto.setMobile(mobile);
nft003ReqDto.setIdCard(idCard);
nft003ReqDto.setCardType(Integer.valueOf(idCardType));
ZxlnftResponseDto<Nft003RegisterPersonPlatformRespDto> nft003Resp = zxlnftSdkUtil.nft003RegisterPersonPlatform(nft003ReqDto);
if(nft003Resp.isSuccess()){
userIdentification = nft003Resp.getData().getUserIdentification();
}else{
return ResponseDto.failure(nft003Resp.getCode(),nft003Resp.getMessage());
}
GalaxyUserRegisterRespDto respDto = GalaxyUserRegisterRespDto.getNew();
if(StringUtil.isNotEmpty(userPubKey)&&StringUtil.isNotEmpty(userPriKey)&&StringUtil.isNotEmpty(userIdentification)){
//1.2.2调用授信平台NFT地址绑定接口
Nft014IdentityBindSubmitByTrustedReqDto nft014ReqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
try {
nft014ReqDto.setUserPubKey(BASE64Util.decode(userPubKey));
nft014ReqDto.setUserIdentification(nft003Resp.getData().getUserIdentification());
String signature = zxlnftBiz.createSign(BASE64Util.decode(userPriKey),nft014ReqDto.getUserIdentification());
nft014ReqDto.setUserSignData(signature);
} catch (UnsupportedEncodingException e) {
log.error("公私钥解密错误!");
}
ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft014Resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(nft014ReqDto);
ZxlnftResponseDto<Nft016IdentityBindQueryRespDto> nft016Resp = null;
if(nft014Resp.isSuccess()){
//1.2.3调用绑定状态批量查询
Nft016IdentityBindQueryReqDto nft016ReqDto = Nft016IdentityBindQueryReqDto.getNew();
nft016ReqDto.setAddressList(nft014Resp.getData().getAddress());
nft016Resp = zxlnftSdkUtil.nft016IdentityBindQuery(nft016ReqDto);
}else{
log.info("nft014Resp 返回结果:{}",nft014Resp.toJson());
return ResponseDto.failure(nft014Resp.getCode(),nft014Resp.getMessage());
}
if(StringUtil.isNotNull(nft016Resp)&&nft016Resp.isSuccess()){
List<Nft016QueryRsData> queryRsDataList = nft016Resp.getData().getList();
Nft016QueryRsData queryRsData = queryRsDataList.get(0);
address = queryRsData.getAddress();
log.info("nft016Resp 返回结果:{}",nft016Resp.toJson());
//构造返回参数
respDto.setUserId(userId);
respDto.setBlockChainType(GalaxyEnum.RouterTypeEnum.ZXINCHAIN.getCode());
respDto.setBlockChainAddress(address);
}else{
return ResponseDto.failure(nft016Resp.getMessage());
}
//构造缓存数据 public ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto) {
if(userInfoBo==null){ return zxinUserCommonBiz.userRegister(reqDto);
userInfoBo = GalaxyUserInfoBo.getNew();
userInfoBo.setUserId(userId);
userInfoBo.setUserName(userName);
userInfoBo.setMobile(mobile);
userInfoBo.setIdCardType(idCardType);
userInfoBo.setIdCard(idCard);
userInfoBo.setMnemonic(mnemonic);
userInfoBo.setIndex(index.toString());
userInfoBo.setUserIdentification(userIdentification);
userInfoBo.setUserPubKey(userPubKey);
userInfoBo.setUserPriKey(userPriKey);
userInfoBo.setRouterType(GalaxyEnum.RouterTypeEnum.ZXINCHAIN.getCode());
userInfoBo.setBlockChainAddress(address);
dataUtils.setGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId(),userInfoBo);
}
}
return ResponseDto.success(respDto);
} }
public ResponseDto<GalaxyUserBindStatusQueryRespDto> userBindStatusQuery(GalaxyUserBindStatusQueryReqDto reqDto){ public ResponseDto<GalaxyUserBindStatusQueryRespDto> userBindStatusQuery(GalaxyUserBindStatusQueryReqDto reqDto){
......
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