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

Commit 7f9937ae authored by anjiabin's avatar anjiabin

实现zxtnft购买功能

parent b5be8362
package com.liquidnet.service.galaxy.dto;
import com.liquidnet.commons.lang.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: GalaxyUserRegisterReqDto
* @Package com.liquidnet.service.galaxy.dto
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/3/10 20:46
*/
@ApiModel(value = "GalaxyUserRegisterReqDto", description = "用户实名注册")
@Data
public class GalaxyUserRegisterReqDto implements Serializable,Cloneable {
@ApiModelProperty(position = 1, required = true, value = "用户ID[30]")
@NotBlank(message = "用户ID不能为空!")
@Size(min = 1, max = 30, message = "用户ID限制2-30位且不能包含特殊字符")
private String userId;
@ApiModelProperty(position = 2, required = true, value = "姓名[50]", example = "张三")
@Size(min = 1, max = 30, message = "姓名长度限制1-30位")
private String userName;
@ApiModelProperty(position = 3, required = true, value = "手机号[11]", example = "13111111111")
@Pattern(regexp = "\\d{11}", message = "手机号格式有误")
@NotBlank(message = "手机号不能为空")
@Size(min = 1, max = 11, message = "手机号长度限制1-11位")
private String mobile;
@ApiModelProperty(position = 4, required = true, value = "证件类型",example = "")
@NotBlank(message = "证件类型不能为空!")
@Size(min = 1, max = 2, message = "证件类型")
private String idCardType;
@ApiModelProperty(position = 5, required = true, value = "证件号")
@NotBlank(message = "证件号不能为空!")
@Size(min = 1, max = 18, message = "证件号限制1-18位且不能包含特殊字符")
private String idCard;
@Override
public String toString(){
return JsonUtils.toJson(this);
}
private static final GalaxyUserRegisterReqDto obj = new GalaxyUserRegisterReqDto();
public static GalaxyUserRegisterReqDto getNew() {
try {
return (GalaxyUserRegisterReqDto) obj.clone();
} catch (CloneNotSupportedException e) {
return new GalaxyUserRegisterReqDto();
}
}
}
package com.liquidnet.service.galaxy.dto;
import com.liquidnet.commons.lang.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: GalaxyUserRegisterRespDto
* @Package com.liquidnet.service.galaxy.dto
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/3/10 20:46
*/
@ApiModel(value = "GalaxyUserRegisterRespDto", description = "用户实名注册")
@Data
public class GalaxyUserRegisterRespDto implements Serializable,Cloneable {
@ApiModelProperty(position = 1, required = true, value = "用户ID[30]")
private String userId;
@ApiModelProperty(position = 1, required = true, value = "用户区块链类型")
private String blockChainType;
@ApiModelProperty(position = 1, required = true, value = "用户区块链地址")
private String blockChainAddress;
@Override
public String toString(){
return JsonUtils.toJson(this);
}
private static final GalaxyUserRegisterRespDto obj = new GalaxyUserRegisterRespDto();
public static GalaxyUserRegisterRespDto getNew() {
try {
return (GalaxyUserRegisterRespDto) obj.clone();
} catch (CloneNotSupportedException e) {
return new GalaxyUserRegisterRespDto();
}
}
}
package com.liquidnet.service.galaxy.service;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.dto.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.GalaxyUserRegisterRespDto;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
......@@ -12,11 +15,5 @@ package com.liquidnet.service.galaxy.service;
* @date 2022/3/8 11:45
*/
public interface IGalaxyUserService {
// ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto);
//
// String dragonNotify(HttpServletRequest request,String payType,String deviceFrom);
//
// DragonPayOrderQueryRespDto checkOrderStatusByCode(String code);
//
// boolean manulNotify(String code);
ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto);
}
package com.liquidnet.service.galaxy.aop.annotation;
import java.lang.annotation.*;
/**
*自定义注解 拦截Controller
*/
@Target({ElementType.PARAMETER, ElementType.METHOD}) //作用范围为方法和参数
@Retention(RetentionPolicy.RUNTIME) //指定生命周期为内存可读
@Documented //指定其为注解
public @interface ControllerLog {
/**
* 操作说明
*/
public String description() default "";
}
package com.liquidnet.service.galaxy.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.aop.annotation.ControllerLog;
import com.liquidnet.service.galaxy.dto.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.GalaxyUserRegisterRespDto;
import com.liquidnet.service.galaxy.service.IGalaxyUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: GalaxyUserController
* @Package com.liquidnet.service.galaxy.controller
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/3/11 12:11
*/
@Api(tags = "NFT-用户相关")
@RestController
@RequestMapping("user")
@Validated
@Slf4j
public class GalaxyUserController {
@Autowired
private IGalaxyUserService galaxyUserService;
@ControllerLog(description = "NFT用户注册")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "NFT用户注册")
@PostMapping(value = {"register"})
public ResponseDto<GalaxyUserRegisterRespDto> register(@Valid @RequestBody GalaxyUserRegisterReqDto reqDto) {
return galaxyUserService.userRegister(reqDto);
}
}
package com.liquidnet.service.galaxy.service.impl;
import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.config.ZxlnftConfig;
import com.liquidnet.common.third.zxlnft.constant.ZxlErrorEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
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.BASE64Util;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.constant.GalaxyConstant;
import com.liquidnet.service.galaxy.dto.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.GalaxyUserRegisterRespDto;
import com.liquidnet.service.galaxy.service.IGalaxyUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: GalaxyUserServiceImpl
* @Package com.liquidnet.service.galaxy.service.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/3/11 12:09
*/
@Slf4j
@Service
public class GalaxyUserServiceImpl implements IGalaxyUserService {
@Autowired
private ZxlnftSdkUtil zxlnftSdkUtil;
@Autowired
private ZxlWalletSdkUtil zxlWalletSdkUtil;
@Autowired
private ZxlnftBiz zxlnftBiz;
@Autowired
private ZxlnftConfig zxlnftConfig;
@Override
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 = "stuff name goat health siren dumb gorilla antique board tenant buffalo present"; //安家宾
// String mnemonic = "economy cost balance weapon flight also nut biology very sun slight about"; //周焕
Long index = 0L;
String userIdentification = null;
String address = null;
String userPubKey = null;
String userPriKey = null;
// 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.toJson());
return ResponseDto.failure(nft014Resp.getCode(),nft014Resp.getMessage());
}
if(StringUtil.isNotNull(nft016Resp)&&nft016Resp.isSuccess()){
log.info("返回结果:{}",nft016Resp.toJson());
//构造返回参数
respDto.setUserId(userId);
respDto.setBlockChainType(GalaxyConstant.RouterEnum.ZXINCHAIN.getCode());
respDto.setBlockChainAddress(nft016Resp.getData().getList().get(0).getAddress());
}else{
return ResponseDto.failure(nft016Resp.getMessage());
}
}
return ResponseDto.success(respDto);
}
}
......@@ -135,31 +135,31 @@ public class TestZxlnftService {
//
if(StringUtil.isNotEmpty(userPubKey)&&StringUtil.isNotEmpty(userPriKey)&&StringUtil.isNotEmpty(userIdentification)){
//1.2.2调用授信平台NFT地址绑定接口
Nft014IdentityBindSubmitByTrustedReqDto nft004ReqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
Nft014IdentityBindSubmitByTrustedReqDto nft014ReqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
try {
nft004ReqDto.setUserPubKey(BASE64Util.decode(userPubKey));
nft004ReqDto.setUserIdentification(nft003Resp.getData().getUserIdentification());
nft014ReqDto.setUserPubKey(BASE64Util.decode(userPubKey));
nft014ReqDto.setUserIdentification(nft003Resp.getData().getUserIdentification());
String signature = zxlnftBiz.createSign(BASE64Util.decode(userPriKey),nft004ReqDto.getUserIdentification());
nft004ReqDto.setUserSignData(signature);
String signature = zxlnftBiz.createSign(BASE64Util.decode(userPriKey),nft014ReqDto.getUserIdentification());
nft014ReqDto.setUserSignData(signature);
} catch (UnsupportedEncodingException e) {
log.error("公私钥解密错误!");
}
ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft004Resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(nft004ReqDto);
ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft014Resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(nft014ReqDto);
if(nft004Resp.isSuccess()){
if(nft014Resp.isSuccess()){
//1.2.3调用绑定状态批量查询
Nft016IdentityBindQueryReqDto nft016ReqDto = Nft016IdentityBindQueryReqDto.getNew();
nft016ReqDto.setAddressList(nft004Resp.getData().getAddress());
nft016ReqDto.setAddressList(nft014Resp.getData().getAddress());
ZxlnftResponseDto<Nft016IdentityBindQueryRespDto> nft016Resp = zxlnftSdkUtil.nft016IdentityBindQuery(nft016ReqDto);
if(nft016Resp.isSuccess()){
log.info("返回结果:{}",nft016Resp.toJson());
}
}else{
log.info("返回结果:{}",nft004Resp.toJson());
log.info("返回结果:{}",nft014Resp.toJson());
}
}
}
......
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