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

Commit c63c5586 authored by anjiabin's avatar anjiabin

调试至信链NFt购买接口

parent d3b56884
......@@ -11,7 +11,7 @@ import java.util.Arrays;
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/2/21 14:00
*/
public enum ErrorEnum {
public enum ZxlErrorEnum {
SECCESS("0","成功"),
FAILURE("1","失败"),
NO_INIT_ERROR("000", "没有初始化"),
......@@ -53,14 +53,14 @@ public enum ErrorEnum {
TORT_SOURCE_ERROR("6026", "侵权 Source 类型错误");
private String code;
private String msg;
ErrorEnum(String code, String msg) {
ZxlErrorEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() { return this.code; }
public String getMsg() { return this.msg; }
public static String errorMsg(String content) {
ErrorEnum err = Arrays.<ErrorEnum>asList(values()).stream().filter(errorEnum -> errorEnum.getCode().equals(content)).findFirst().orElse(SERVER_INNER_ERROR);
ZxlErrorEnum err = Arrays.<ZxlErrorEnum>asList(values()).stream().filter(errorEnum -> errorEnum.getCode().equals(content)).findFirst().orElse(SERVER_INNER_ERROR);
return err.getMsg();
}
}
\ No newline at end of file
package com.liquidnet.service.zxlnft;
import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.constant.ZxlErrorEnum;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
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.BASE64Util;
import com.liquidnet.commons.lang.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -16,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.UnsupportedEncodingException;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
......@@ -56,47 +60,97 @@ public class TestZxlnftService {
*/
@Test
public void personRegisterBind(){
//生成助记词
CreateMnemonicReq req = CreateMnemonicReq.getNew();
CreateMnemonicResp createMnemonicResp = zxlWalletSdkUtil.createMnemonic(req);
//生成公私钥
DeriveKeyPairReq deriveKeyPairReq = DeriveKeyPairReq.getNew();
deriveKeyPairReq.setMnemonic("economy cost balance weapon flight also nut biology very sun slight about");
String userId = "310508344264376327445470";
String userName = "安家宾";
String mobile = "13811314082";
String idCardType = ZxlnftEnum.CardTypeEnum.ID_CARD.getCode();
String idCard = "142323198302062216";
// String userName = "周焕";
// String mobile = "18548596019";
// String idCardType = ZxlnftEnum.CardTypeEnum.ID_CARD.getCode();
// String idCard = "150422199805206019";
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(0l);
DeriveKeyPairResp deriveKeyPairResp = zxlWalletSdkUtil.deriveKeyPair(deriveKeyPairReq);
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平台签名)接口
//1.2.1调用自然人注册实名(使用NFT平台签名)接口
Nft003RegisterPersonPlatformReqDto nft003ReqDto = Nft003RegisterPersonPlatformReqDto.getNew();
nft003ReqDto.setPersonName("周焕");
nft003ReqDto.setPersonName(userName);
// reqDto.setEmail("");
nft003ReqDto.setMobile("18548596019");
nft003ReqDto.setIdCard("150422199805206019");
nft003ReqDto.setMobile(mobile);
nft003ReqDto.setIdCard(idCard);
nft003ReqDto.setCardType(Integer.valueOf(ZxlnftEnum.CardTypeEnum.ID_CARD.getCode()));
nft003ReqDto.setCardType(Integer.valueOf(idCardType));
ZxlnftResponseDto<Nft003RegisterPersonPlatformRespDto> nft003Resp = zxlnftSdkUtil.nft003RegisterPersonPlatform(nft003ReqDto);
// 1.2.2调用授信平台NFT地址绑定接口
Nft014IdentityBindSubmitByTrustedReqDto nft004ReqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
//周焕
nft004ReqDto.setUserPubKey(deriveKeyPairResp.getPubKey());
nft004ReqDto.setUserIdentification(nft003Resp.getData().getUserIdentification());
String signature = zxlnftBiz.createSign(deriveKeyPairResp.getPriKey(),nft004ReqDto.getUserIdentification());
nft004ReqDto.setUserSignData(signature);
ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft004Resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(nft004ReqDto);
if(nft003Resp.isSuccess()){
userIdentification = nft003Resp.getData().getUserIdentification();
}
if(nft004Resp.isSuccess()){
// 1.2.3调用绑定状态批量查询
Nft016IdentityBindQueryReqDto nft016ReqDto = Nft016IdentityBindQueryReqDto.getNew();
nft016ReqDto.setAddressList(nft004Resp.getData().getAddress());
ZxlnftResponseDto<Nft016IdentityBindQueryRespDto> nft016Resp = zxlnftSdkUtil.nft016IdentityBindQuery(nft016ReqDto);
}else{
log.info("返回结果:{}",nft004Resp.toJson());
//
if(StringUtil.isNotEmpty(userPubKey)&&StringUtil.isNotEmpty(userPriKey)&&StringUtil.isNotEmpty(userIdentification)){
//1.2.2调用授信平台NFT地址绑定接口
Nft014IdentityBindSubmitByTrustedReqDto nft004ReqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
try {
nft004ReqDto.setUserPubKey(BASE64Util.decode(userPubKey));
nft004ReqDto.setUserIdentification(nft003Resp.getData().getUserIdentification());
String signature = zxlnftBiz.createSign(BASE64Util.decode(userPriKey),nft004ReqDto.getUserIdentification());
nft004ReqDto.setUserSignData(signature);
} catch (UnsupportedEncodingException e) {
log.error("公私钥解密错误!");
}
ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft004Resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(nft004ReqDto);
if(nft004Resp.isSuccess()){
// 1.2.3调用绑定状态批量查询
Nft016IdentityBindQueryReqDto nft016ReqDto = Nft016IdentityBindQueryReqDto.getNew();
nft016ReqDto.setAddressList(nft004Resp.getData().getAddress());
ZxlnftResponseDto<Nft016IdentityBindQueryRespDto> nft016Resp = zxlnftSdkUtil.nft016IdentityBindQuery(nft016ReqDto);
if(nft016Resp.isSuccess()){
log.info("返回结果:{}",nft016Resp.toJson());
}
}else{
log.info("返回结果:{}",nft004Resp.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