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

Commit f5f91961 authored by anjiabin's avatar anjiabin

实现xuper相关艺术品上传

parent 252739a1
package com.liquidnet.common.third.xuper.config;
import com.baidu.xasset.auth.XchainAccount;
import com.baidu.xasset.client.xasset.Asset;
import com.baidu.xasset.common.config.Config;
import com.baidu.xuper.api.Account;
import com.liquidnet.commons.lang.util.BASE64Util;
import com.liquidnet.commons.lang.util.MD5Utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.io.UnsupportedEncodingException;
import java.util.logging.Logger;
/**
......@@ -32,6 +28,8 @@ public class XuperConfig {
private String secretAccessKey;
@Value("${liquidnet.service.galaxy.xuper.nftApiUrl:http://120.48.16.137:8360}")
private String nftApiUrl;
@Value("${liquidnet.service.galaxy.xuper.nftPlatformMnemonic}")
private String nftPlatformMnemonic;
private Asset asset = null;
private static Asset staticAsset = null;
......@@ -84,4 +82,8 @@ public class XuperConfig {
public String getNftApiUrl() {
return nftApiUrl;
}
public String getNftPlatformMnemonic() {
return nftPlatformMnemonic;
}
}
......@@ -40,4 +40,42 @@ public class XuperEnum {
return code;
}
}
/**
* 资产状态 1:初始 3:发行中 4:发行成功 5:冻结中 6:已冻结 7:封禁中 8:已封禁
*/
public enum AssetStatusEnum{
INIT("1","初始"),
PUBLISHING("3","发行中"),
PUBLISH_SUCCESS("4","发行成功"),
FREEZING("5","冻结中"),
BANNEDING("6","封禁中"),
BANNEDED("7","已封禁");
private String code;
private String message;
AssetStatusEnum(String code, String message) {
this.code = code;
this.message = message;
}
public AssetStatusEnum getEnumByCode(String code){
AssetStatusEnum[] arry = AssetStatusEnum.values();
for (int i = 0; i < arry.length; i++) {
if (arry[i].getCode().equals(code)) {
return arry[i];
}
}
return null;
}
public String getCode() {
return code;
}
public String getMessage(){
return message;
}
}
}
package com.liquidnet.common.third.xuper.dto;
import com.baidu.xasset.client.base.BaseDef;
import com.baidu.xasset.client.xasset.XassetDef;
import lombok.Data;
/**
......@@ -13,10 +15,9 @@ import lombok.Data;
*/
@Data
public class XuperUploadFileRespDto {
private String pubKeyStr;
private String priKeyStr;
private String address;
private String mnemonic;
public String link;
public XassetDef.GetStokenResp resp;
public BaseDef.RequestRes res;
private static final XuperUploadFileRespDto obj = new XuperUploadFileRespDto();
public static XuperUploadFileRespDto getNew() {
......
package com.liquidnet.service.galaxy.router.xuper.biz;
import com.baidu.xuper.crypto.Hash;
import com.liquidnet.common.third.xuper.config.XuperConfig;
import com.liquidnet.common.third.xuper.constant.XuperEnum;
import com.liquidnet.common.third.xuper.dto.*;
import com.liquidnet.common.third.xuper.exception.XupterException;
import com.liquidnet.common.third.xuper.util.XuperSdkUtil;
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.constant.ZxlnftEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
import com.liquidnet.common.third.zxlnft.dto.wallet.UploadToCosReq;
import com.liquidnet.common.third.zxlnft.dto.wallet.UploadToCosResp;
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.BeanUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.biz.GalaxyCommonBiz;
......@@ -23,7 +22,6 @@ import com.liquidnet.service.galaxy.constant.GalaxyErrorEnum;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesInfoBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesNftInfoBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesNftUploadBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesNftUploadTempSecretBo;
import com.liquidnet.service.galaxy.dto.param.*;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import lombok.extern.slf4j.Slf4j;
......@@ -31,14 +29,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @Description: 百度超级链艺术品上传
* @class: XuperArtworkBiz
* @Package com.liquidnet.service.galaxy.router.xuper.biz
* @Copyright: LightNet @ Copyright (c) 2022
......@@ -48,16 +46,13 @@ import java.util.Date;
@Component
public class XuperArtworkBiz {
@Autowired
private ZxlnftSdkUtil zxlnftSdkUtil;
@Autowired
private ZxlWalletSdkUtil zxlWalletSdkUtil;
private ZxlnftBiz zxlnftBiz;
@Autowired
private ZxlnftBiz zxlnftBiz;
private XuperSdkUtil xuperSdkUtil;
@Autowired
private ZxlnftConfig zxlnftConfig;
private XuperConfig xuperConfig;
@Autowired
private GalaxyDataUtils dataUtils;
......@@ -65,15 +60,12 @@ public class XuperArtworkBiz {
@Autowired
private GalaxyCommonBiz galaxyCommonBiz;
public ResponseDto<GalaxyNftImageRespDto> nftImageCheck(GalaxyNftImageReqDto reqDto) {
Nft008QueryImageModerationReqDto nft008ReqDto = Nft008QueryImageModerationReqDto.getNew();
nft008ReqDto.setImageUrl(reqDto.getNftOriginalUrl());
ZxlnftResponseDto<Nft008QueryImageModerationRespDto> nft008RespDto = zxlnftSdkUtil.nft008QueryImageModeration(nft008ReqDto);
if(!nft008RespDto.isSuccess()){
throw new ZxlNftException(ZxlErrorEnum.IMAGE_CHECK_ERROR.getCode(),ZxlErrorEnum.IMAGE_CHECK_ERROR.getMsg());
}
GalaxyNftImageRespDto nftImageRespDto = GalaxyNftImageRespDto.getNew();
BeanUtil.copy(nft008RespDto.getData(),nftImageRespDto);
nftImageRespDto.setSuggestion("Pass");
nftImageRespDto.setLabel("Normal");
nftImageRespDto.setScore(100);
return ResponseDto.success(nftImageRespDto);
}
......@@ -120,14 +112,6 @@ public class XuperArtworkBiz {
dataUtils.setSeriesNftUploadBo(reqDto.getRouterType(),reqDto.getSkuId(),seriesNftUploadBo);
return ResponseDto.success(galaxyNftUploadRespDto);
// 1.4.4调用查询素材地址接口 -- 非必需
// Nft021UploadUrlReqDto nft021ReqDto = Nft021UploadUrlReqDto.getNew();
// nft021ReqDto.setSeriesName(seriesName);
// nft021ReqDto.setPlatformIdentification(zxlnftConfig.getPlatformIdentification());
// //如果上传人就是平台管理员,以下需要注释掉,因为会导致返回的地址多了一级目录
//// nft021ReqDto.setUserIdentification(zxlnftConfig.getPlatformIdentification());
// ZxlnftResponseDto<Nft021UploadUrlRespDto> resp = zxlnftSdkUtil.nft021UploadUrl(nft021ReqDto);
}
public ResponseDto<GalaxyArtSeriesClaimRespDto> seriesClaim(GalaxyArtSeriesClaimReqDto reqDto) {
......@@ -140,14 +124,6 @@ public class XuperArtworkBiz {
Long totalCount = reqDto.getTotalCount();
String coverUrl = reqDto.getCoverUrl();//暂时用nftUrl
String seriesDesc = reqDto.getSeriesDesc();
//发行用到的相关信息
// String author = reqDto.getAuthor();
// String nftName = reqDto.getNftName();
// String nftUrl = reqDto.getNftUrl();
// String displayUrl = reqDto.getDisplayUrl();
// String nftDesc = reqDto.getNftDesc();
// String nftFlag = reqDto.getNftFlag();
// String sellCount = reqDto.getSellCount();
//根据skuId获取原始上传信息
GalaxySeriesNftUploadBo seriesNftUploadBo = dataUtils.getSeriesNftUploadBo(reqDto.getRouterType(),reqDto.getSkuId());
......@@ -168,36 +144,65 @@ public class XuperArtworkBiz {
}
}
//业务失败信息
String bizFailDesc = null;
//系统失败信息
String sysFailDesc = null;
GalaxyArtSeriesClaimRespDto seriesClaimRespDto = null;
// 创建区块链数字资产
Xuper002CreateAssetRespDto xuper002CreateAssetRespDto = null;
try {
/**
* 进行系列声明
*/
Nft030SeriesClaimReqDto nft030ReqDto = Nft030SeriesClaimReqDto.getNew();
nft030ReqDto.setPubKey(zxlnftConfig.getNftPlatformPubKey());
nft030ReqDto.setSeriesName(seriesName);
//无限制系列 设置为0
nft030ReqDto.setTotalCount(totalCount);
nft030ReqDto.setOperateId(IDGenerator.get32UUID());
//系列封面
nft030ReqDto.setCoverUrl(coverUrl);
nft030ReqDto.setDesc(seriesDesc);
nft030ReqDto.setMaxPublishCount(0);
nft030ReqDto.setSeriesBeginFromZero(false);
ZxlnftResponseDto<Nft030SeriesClaimRespDto> nft30RespDto = zxlnftSdkUtil.nft030SeriesClaim(nft030ReqDto);
Xuper002CreateAssetReqDto xuper002CreateAssetReqDto = Xuper002CreateAssetReqDto.getNew();
String nftUrl = "bos_v1://xasset-offline/110381/ZXLNFTIMAGE202206231042217867523750.jpg/";
try {
xuper002CreateAssetReqDto.setMnemonic(xuperConfig.getNftPlatformMnemonic());
//资产碎片数量,小于1和大于200000代表不做库存限制
xuper002CreateAssetReqDto.setAmount(100);
//藏品显示售卖价格,单位为分
xuper002CreateAssetReqDto.setPrice(1000l);
//资产分类。1:艺术品 2:收藏品 3:门票 4:酒店
xuper002CreateAssetReqDto.setAssetCate(Integer.valueOf(XuperEnum.assetTypeEnum.COLLECTION.getCode()));
//资产名称,小于30个字节
xuper002CreateAssetReqDto.setTitle("百度超级链-数字藏品-测试20220622-001");
//资产缩略图。bos上传的图片,格式支持:”jpg”, “jpeg”, “png”, “bmp”, “webp”, “heic”。参数格式bos_v1://{bucket}/{object}/{width}_{height}
xuper002CreateAssetReqDto.setThumb(nftUrl.concat("1000_500"));
//短文字描述,小于300个字节
xuper002CreateAssetReqDto.setShortDesc(xuper002CreateAssetReqDto.getTitle().concat("-短文字描述小于300个字节"));
//(可选)资产详情介绍长图。bos上传的图片,格式支持:”jpg”, “jpeg”, “png”, “bmp”, “webp”, “heic”。参数格式bos_v1://{bucket}/{object}/{width}_{height}
xuper002CreateAssetReqDto.setImgDesc(nftUrl.concat("1000_500"));
//资产原始文件。比如图片,图片本身就是资产。格式bos_v1://{bucket}/{object} ,文件大小<10M。文件名采用文件md5值,为了正常展现,需要正确携带文件后缀
xuper002CreateAssetReqDto.setAssetUrl(nftUrl.concat("900_1200"));
//(可选)长文字描述,小于1200个字节
xuper002CreateAssetReqDto.setLongDesc(xuper002CreateAssetReqDto.getTitle().concat("-长文字描述,小于1200个字节"));
//(可选)资产额外描述信息json字符串。比如标签
xuper002CreateAssetReqDto.setAssetExt("{\"tags\":[\"艺术品\",\"古董\"]} ");
//(可选)资产组id。用于关联业务层酒店/店铺id
xuper002CreateAssetReqDto.setGroupId(123123l);
//(可选)业务侧用户标记,必要时请安全处理后设置
xuper002CreateAssetReqDto.setUserId(123123l);
//(可选)要存证的资产文件sm3散列值,如有多个文件逐个计算hash值后合并计算最终hash值
xuper002CreateAssetReqDto.setFileHash(new String(Hash.doubleSha256(nftUrl.concat("900_1200").getBytes())));
XuperResponseDto<Xuper002CreateAssetRespDto> xuperResponseDto = xuperSdkUtil.xuper002CreateAsset(xuper002CreateAssetReqDto);
if(xuperResponseDto.isSuccess()){
xuper002CreateAssetRespDto = xuperResponseDto.getParseData(Xuper002CreateAssetRespDto.class);
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("testXuper002CreateAsset resp : "+ JsonUtils.toJson(xuper002CreateAssetRespDto));
//返回参数
String seriesId = null;
String taskId = null;
seriesClaimRespDto = GalaxyArtSeriesClaimRespDto.getNew();
if(nft30RespDto.isSuccess()){
if(xuper002CreateAssetRespDto.errNo==0){
//第零个系列 无限制系列
taskId = nft30RespDto.getData().getTaskId();
taskId = String.valueOf(xuper002CreateAssetRespDto.getAssetId());
//构造缓存数据
if(StringUtil.isNull(seriesInfoBo)){
//
......@@ -247,102 +252,6 @@ public class XuperArtworkBiz {
return ResponseDto.success(seriesClaimRespDto);
}
public ResponseDto<GalaxyArtSeriesClaimRespDto> seriesClaimBackup(GalaxyArtSeriesClaimReqDto reqDto) {
//系列声明用到参数
String skuId = reqDto.getSkuId();
String seriesName = GalaxyConstant.SERIES_NAME_PREFIX.concat(skuId);
Long totalCount = reqDto.getTotalCount();
String coverUrl = reqDto.getCoverUrl();//暂时用nftUrl
String seriesDesc = reqDto.getSeriesDesc();
//发行用到的相关信息
String author = reqDto.getAuthor();
String nftName = reqDto.getNftName();
String nftUrl = reqDto.getNftUrl();
String displayUrl = reqDto.getDisplayUrl();
String nftDesc = reqDto.getNftDesc();
String nftFlag = reqDto.getNftFlag();
String sellCount = reqDto.getSellCount();
//返回参数
String seriesId = null;
String taskId = null;
GalaxySeriesInfoBo seriesInfoBo = dataUtils.getSeriesInfoBo(reqDto.getRouterType(),reqDto.getSkuId());
if(StringUtil.isNotNull(seriesInfoBo)){
/**
* 如果系列声明成功,则不允许继续声明
*/
if(seriesInfoBo.getSeriesClaimStatus().equalsIgnoreCase(GalaxyEnum.SeriesClaimStatusEnum.SUCCESS.getCode())){
GalaxyArtSeriesClaimRespDto seriesClaimRespDto = GalaxyArtSeriesClaimRespDto.getNew();
seriesClaimRespDto.setSkuId(skuId);
seriesClaimRespDto.setNftUrl(nftUrl);
seriesClaimRespDto.setSeriesId(seriesInfoBo.getSeriesId());
seriesClaimRespDto.setSeriesName(seriesInfoBo.getSeriesName());
return ResponseDto.success(seriesClaimRespDto);
}
}
/**
* 进行系列声明
*/
Nft030SeriesClaimReqDto nft030ReqDto = Nft030SeriesClaimReqDto.getNew();
nft030ReqDto.setPubKey(zxlnftConfig.getNftPlatformPubKey());
nft030ReqDto.setSeriesName(seriesName);
//无限制系列 设置为0
nft030ReqDto.setTotalCount(totalCount);
nft030ReqDto.setOperateId(IDGenerator.get32UUID());
//系列封面
nft030ReqDto.setCoverUrl(coverUrl);
nft030ReqDto.setDesc(seriesDesc);
nft030ReqDto.setMaxPublishCount(0);
nft030ReqDto.setSeriesBeginFromZero(false);
ZxlnftResponseDto<Nft030SeriesClaimRespDto> nft30RespDto = zxlnftSdkUtil.nft030SeriesClaim(nft030ReqDto);
//{"taskId":"49d1cccc-e62c-40bc-923c-bfac31325351_nft-series-claim_1"}
if(nft30RespDto.isSuccess()){
//系列声明结果查询
Nft031SeriesClaimResultReqDto nft031ReqDto = Nft031SeriesClaimResultReqDto.getNew();
//第零个系列 无限制系列
taskId = nft30RespDto.getData().getTaskId();
nft031ReqDto.setTaskId(taskId);
int count = 0;
while(StringUtil.isEmpty(seriesId)){
count++;
log.info("=======执行第{}次查询,taskId:{}",count,nft031ReqDto.getTaskId());
ZxlnftResponseDto<Nft031SeriesClaimResultRespDto> nft031RespDtoTemp = zxlnftSdkUtil.nft031SeriesClaimResult(nft031ReqDto);
if(nft031RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
seriesId = nft031RespDtoTemp.getData().getSeriesId();
break;
}else if(nft031RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
log.info("任务执行失败!taskId:{}",nft031ReqDto.getTaskId());
return ResponseDto.failure(GalaxyErrorEnum.SERIES_CLAIM_ERROR.getCode(), GalaxyErrorEnum.SERIES_CLAIM_ERROR.getMessage());
}
if(count==5){
log.info("=======查询共5次,跳出循环!taskId:{}",nft031ReqDto.getTaskId());
return ResponseDto.failure(GalaxyErrorEnum.SERIES_CLAIM_ERROR_FIVE_TIMES.getCode(), GalaxyErrorEnum.SERIES_CLAIM_ERROR_FIVE_TIMES.getMessage());
}
}
log.info("系列声明结果查询 seriesId :{}",seriesId);
}
GalaxyArtSeriesClaimRespDto seriesClaimRespDto = GalaxyArtSeriesClaimRespDto.getNew();
seriesClaimRespDto.setSkuId(skuId);
seriesClaimRespDto.setNftUrl(nftUrl);
seriesClaimRespDto.setSeriesId(seriesId);
seriesClaimRespDto.setSeriesName(seriesName);
//构造缓存数据
if(seriesInfoBo==null){
//设置为处理中
String publishStatus = GalaxyEnum.SeriesClaimStatusEnum.PROCESSING.getCode();
seriesInfoBo = this.buildSeriesInfoBo(reqDto,null,publishStatus);
dataUtils.setSeriesInfoBo(reqDto.getRouterType(),reqDto.getSkuId(),seriesInfoBo);
}
return ResponseDto.success(seriesClaimRespDto);
}
public ResponseDto<GalaxyArtSeriesClaimResultQueryRespDto> seriesClaimResultQuery(GalaxyArtSeriesClaimResultQueryReqDto reqDto) {
//根据skuId获取系列nft信息
GalaxySeriesNftInfoBo seriesNftInfoBo = dataUtils.getSeriesNftInfoBo(reqDto.getRouterType(),reqDto.getSkuId());
......@@ -369,19 +278,32 @@ public class XuperArtworkBiz {
return ResponseDto.success(resultQueryRespDto);
}
//查询NFT系列声明结果
Nft031SeriesClaimResultReqDto nft031SeriesClaimResultReqDto = Nft031SeriesClaimResultReqDto.getNew();
nft031SeriesClaimResultReqDto.setTaskId(seriesInfoBo.getSeriesClaimTaskId());
nft031SeriesClaimResultReqDto.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
ZxlnftResponseDto<Nft031SeriesClaimResultRespDto> resp = zxlnftSdkUtil.nft031SeriesClaimResult(nft031SeriesClaimResultReqDto);
if(resp.isSuccess()){
if(resp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
Xuper005QueryAssetReqDto xuper005QueryAssetReqDto = Xuper005QueryAssetReqDto.getNew();
// 定义返回结果对象
Xuper005QueryAssetRespDto respDto = null;
//百度超级链使用的是资产id作为任务id
long assetId = Long.parseLong(seriesInfoBo.getSeriesClaimTaskId());
try {
xuper005QueryAssetReqDto.setAssetId(assetId);
XuperResponseDto<Xuper005QueryAssetRespDto> xuperResponseDto = xuperSdkUtil.xuper005QueryAsset(xuper005QueryAssetReqDto);
if(xuperResponseDto.isSuccess()){
respDto = xuperResponseDto.getParseData(Xuper005QueryAssetRespDto.class);
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("seriesClaimResultQuery resp : "+ JsonUtils.toJson(respDto));
if(respDto.getErrNo() == 0){
if(respDto.getMeta().getStatus() == Integer.parseInt(XuperEnum.AssetStatusEnum.INIT.getCode())
|| respDto.getMeta().getStatus() == Integer.parseInt(XuperEnum.AssetStatusEnum.PUBLISH_SUCCESS.getCode())){
//设置系列声明状态
seriesInfoBo.setSeriesClaimStatus(GalaxyEnum.SeriesClaimStatusEnum.SUCCESS.getCode());
String nowTimeStr = DateUtil.format(new Date(resp.getData().getChainTimestamp().longValue()*1000),DateUtil.Formatter.yyyyMMddHHmmss);
String nowTimeStr = DateUtil.getNowTime();
seriesInfoBo.setChainTimestamp(nowTimeStr);
seriesInfoBo.setTradeHash(resp.getData().getTxHash());
seriesInfoBo.setSeriesId(resp.getData().getSeriesId());
seriesInfoBo.setTradeHash(respDto.getMeta().getTxId());
seriesInfoBo.setSeriesId(String.valueOf(respDto.getMeta().getAssetId()));
seriesInfoBo.setUpdatedAt(LocalDateTime.now());
//根据系列编号更新系列声明状态 1对多skuId
......@@ -394,7 +316,8 @@ public class XuperArtworkBiz {
GalaxyArtSeriesClaimResultQueryRespDto resultQueryRespDto = this.buildGalaxyArtSeriesClaimResultQueryRespDto(reqDto,seriesInfoBo,ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode());
return ResponseDto.success(resultQueryRespDto);
}else if(resp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
}else if(respDto.getMeta().getStatus() != Integer.parseInt(XuperEnum.AssetStatusEnum.INIT.getCode())
&& respDto.getMeta().getStatus() != Integer.parseInt(XuperEnum.AssetStatusEnum.PUBLISH_SUCCESS.getCode())){
seriesInfoBo.setSeriesClaimStatus(GalaxyEnum.SeriesClaimStatusEnum.FAIL.getCode());
seriesInfoBo.setUpdatedAt(LocalDateTime.now());
......@@ -412,78 +335,56 @@ public class XuperArtworkBiz {
}
private String getFullFilePath(String seriesName,String originalUrl){
String filePath = null;
String imageType = null;
if(originalUrl.lastIndexOf("?")!=-1){
String tempUrl = originalUrl.substring(0,originalUrl.lastIndexOf("?"));
imageType = tempUrl.substring(tempUrl.lastIndexOf("."),tempUrl.length());
}else{
imageType = originalUrl.substring(originalUrl.lastIndexOf("."),originalUrl.length());
}
String fileName = IDGenerator.getZxlNftImageCosCode() + imageType;
//通过图片url地址上传
File cosFile = galaxyCommonBiz.inputStreamToFile(originalUrl,fileName);
filePath = cosFile.getAbsolutePath();
log.info("cosFile.getPath() :{}",cosFile.getPath());
log.info("cosFile.getAbsoluteFile() :{}",cosFile.getAbsoluteFile());
//完整全路径 https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/NOW_ZXL_NFT_PIC001_test_skuId001/2022-03-04/ZXLNFTIMAGE202203041707466694345291.jpg
String fullFilePath = null; //需要保存,返回给调用者
// 创建区块链账户
XuperUploadFileRespDto respDto = null;
try {
String filePath = null;
String imageType = null;
// 1.4.3调用sdk接口-上传cos接口
GalaxySeriesNftUploadTempSecretBo seriesNftUploadTempSecretBo = this.getSeriesNftUploadTempSecret(seriesName);
if(StringUtil.isNotNull(seriesNftUploadTempSecretBo)){
fullFilePath = seriesNftUploadTempSecretBo.getUploadAddress().concat(fileName);
UploadToCosReq req = UploadToCosReq.getNew();
req.setCosPath(fullFilePath);
req.setTempSecretId(seriesNftUploadTempSecretBo.getTempSecretId());
req.setTempSecretKey(seriesNftUploadTempSecretBo.getTempSecretKey());
req.setSessionToken(seriesNftUploadTempSecretBo.getSessionToken());
req.setFilePath(filePath);
UploadToCosResp uploadToCosResp = zxlWalletSdkUtil.uploadToCos(req);
}
log.info("完整的素材访问fullFilePath url:{}",fullFilePath);
return fullFilePath;
}
public GalaxySeriesNftUploadTempSecretBo getSeriesNftUploadTempSecret(String seriesName){
//获取临时密钥
GalaxySeriesNftUploadTempSecretBo seriesNftUploadTempSecretBo = dataUtils.getSeriesNftUploadTempSecretBo(seriesName);
if(StringUtil.isNull(seriesNftUploadTempSecretBo)){
// 1.4.2调用生成素材上传临时密钥接口
Nft022UploadSecretReqDto nft022ReqDto = Nft022UploadSecretReqDto.getNew();
nft022ReqDto.setSeriesName(seriesName);
nft022ReqDto.setTimestamp(DateUtil.getNowSeconds().toString());
nft022ReqDto.setUserPubKey(zxlnftConfig.getNftPlatformPubKey());
//系列为空
String userData = nft022ReqDto.getTimestamp();
//系列不为空
if(StringUtil.isNotEmpty(nft022ReqDto.getSeriesName())){
userData = nft022ReqDto.getTimestamp() + "_" + nft022ReqDto.getSeriesName();
if(originalUrl.lastIndexOf("?")!=-1){
String tempUrl = originalUrl.substring(0,originalUrl.lastIndexOf("?"));
imageType = tempUrl.substring(tempUrl.lastIndexOf("."),tempUrl.length());
}else{
imageType = originalUrl.substring(originalUrl.lastIndexOf("."),originalUrl.length());
}
String fileName = IDGenerator.getZxlNftImageCosCode() + imageType;
nft022ReqDto.setUserSignedData(zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),userData));
//通过图片url地址上传
File cosFile = galaxyCommonBiz.inputStreamToFile(originalUrl,fileName);
filePath = cosFile.getAbsolutePath();
log.info("cosFile.getPath() :{}",cosFile.getPath());
log.info("cosFile.getAbsoluteFile() :{}",cosFile.getAbsoluteFile());
ZxlnftResponseDto<Nft022UploadSecretRespDto> nft022RespDto = zxlnftSdkUtil.nft022UploadSecret(nft022ReqDto);
XuperUploadFileReqDto reqDto = XuperUploadFileReqDto.getNew();
if(!nft022RespDto.isSuccess()){
throw new ZxlNftException(ZxlErrorEnum.UPLOAD_TEMP_SECRET.getCode(),ZxlErrorEnum.UPLOAD_TEMP_SECRET.getMsg());
}else{
seriesNftUploadTempSecretBo = GalaxySeriesNftUploadTempSecretBo.getNew();
seriesNftUploadTempSecretBo.setTempSecretId(nft022RespDto.getData().getTempSecretId());
seriesNftUploadTempSecretBo.setTempSecretKey(nft022RespDto.getData().getTempSecretKey());
seriesNftUploadTempSecretBo.setSessionToken(nft022RespDto.getData().getSessionToken());
seriesNftUploadTempSecretBo.setUploadAddress(nft022RespDto.getData().getUploadAddress());
seriesNftUploadTempSecretBo.setTimestamp(DateUtil.getNowTime());
dataUtils.setSeriesNftUploadTempSecretBo(seriesName,seriesNftUploadTempSecretBo);
reqDto.setMnemonic(xuperConfig.getNftPlatformMnemonic());
reqDto.setFileName(fileName);
reqDto.setFilePath(filePath);
byte[] fileByte = new byte[0];
try {
fileByte = galaxyCommonBiz.toByteArray(new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
reqDto.setDataByte(fileByte);
reqDto.setProperty("");
XuperResponseDto<XuperUploadFileRespDto> uploadFileResp = xuperSdkUtil.xuperUploadFile(reqDto);
if(uploadFileResp.isSuccess()){
respDto = uploadFileResp.getParseData(XuperUploadFileRespDto.class);
fullFilePath = respDto.getLink();
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
return seriesNftUploadTempSecretBo;
log.info("testXuperUploadFile resp : "+ JsonUtils.toJson(respDto));
log.info("完整的素材访问fullFilePath url:{}",fullFilePath);
return fullFilePath;
}
......
......@@ -117,7 +117,7 @@ public class TestXuperSdkUtil {
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("testXuper000CreateAccount resp : "+ JsonUtils.toJson(respDto));
log.info("testXuperUploadFile resp : "+ JsonUtils.toJson(respDto));
}
@Test
......
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