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

Commit ac94ca6a authored by anjiabin's avatar anjiabin

实现xuper相关艺术品上传

parent 34604e54
......@@ -23,6 +23,7 @@ public class GalaxyConstant {
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 SERIES_NAME_XUPER_PREFIX="NOW_XUPER_";// 系列存储目录名称和系列声明
public static final String ADAM_USER_SYNC_URL="/adam/rsc/syn/certmeta";// adam用户开通数字账户信息同步url
......
......@@ -117,6 +117,10 @@ public class IDGenerator {
return "ZXLNFTIMAGE" + nextTimeId();
}
public static String getXuperNftImageCosCode() {
return "XUPERNFTIMAGE" + nextTimeId();
}
public static String refundCode() {
return "RED" + nextTimeId();
}
......
package com.liquidnet.common.third.xuper.dto;
import com.baidu.xasset.client.base.BaseDef;
import com.baidu.xasset.client.xasset.XassetDef;
import lombok.Data;
/**
......@@ -16,8 +14,36 @@ import lombok.Data;
@Data
public class XuperUploadFileRespDto {
public String link;
public XassetDef.GetStokenResp resp;
public BaseDef.RequestRes res;
public GetStokenResp resp;
public RequestRes res;
@Data
public static class GetStokenResp {
public long requestId;
public int errNo;
public String errMsg;
public AccessInfo accessInfo;
}
@Data
public static class AccessInfo {
public String bucket;
public String endPoint;
public String objectPath;
public String accessKeyId;
public String secreteAccessKey;
public String sessionToken;
public String createTime;
public String expiration;
}
@Data
public static class RequestRes {
public int httpCode;
public String reqUrl;
public String traceId;
public String body;
}
private static final XuperUploadFileRespDto obj = new XuperUploadFileRespDto();
public static XuperUploadFileRespDto getNew() {
......
......@@ -60,7 +60,12 @@ public class XuperSdkUtil {
byte[] dataByte = reqDto.getDataByte();
String property = reqDto.getProperty();
XassetDef.UploadFile uploadFile = getAsset().uploadFile(account, fileName, filePath, dataByte, property);
log.info("xuperUploadFile resp : "+ JsonUtils.toJson(uploadFile));
BaseDef.RequestRes requestRes = uploadFile.res;
if(requestRes.httpCode==200){
log.info("xuperUploadFile resp : "+ JsonUtils.toJson(uploadFile));
respDto = JsonUtils.fromJson(JsonUtils.toJson(uploadFile),new TypeReference<XuperUploadFileRespDto>(){});
}
log.info("xuperUploadFile resp : "+ JsonUtils.toJson(respDto));
}catch(Exception e){
log.error("error msg "+e.getMessage(),e);
throw new XupterException(XuperErrorEnum.SERVER_INNER_ERROR.getCode(),XuperErrorEnum.SERVER_INNER_ERROR.getMsg());
......
......@@ -85,7 +85,7 @@ public class XuperArtworkBiz {
String originalNftUrl = reqDto.getOriginalNftUrl();
String originalDisplayUrl = reqDto.getOriginalDisplayUrl();
//上传系列名只用来目录区分
String seriesName = GalaxyConstant.SERIES_NAME_PREFIX + reqDto.getSkuId(); //素材存储目录
String seriesName = GalaxyConstant.SERIES_NAME_XUPER_PREFIX + reqDto.getSkuId(); //素材存储目录
//返回素材上传结果
GalaxyNftUploadRespDto galaxyNftUploadRespDto = GalaxyNftUploadRespDto.getNew();
......@@ -109,6 +109,7 @@ public class XuperArtworkBiz {
seriesNftUploadBo.setOriginalDisplayUrl(originalDisplayUrl);
seriesNftUploadBo.setNftUrl(galaxyNftUploadRespDto.getNftUrl());
seriesNftUploadBo.setDisplayUrl(galaxyNftUploadRespDto.getDisplayUrl());
seriesNftUploadBo.setCreatedAt(LocalDateTime.now());
dataUtils.setSeriesNftUploadBo(reqDto.getRouterType(),reqDto.getSkuId(),seriesNftUploadBo);
return ResponseDto.success(galaxyNftUploadRespDto);
......@@ -118,8 +119,8 @@ public class XuperArtworkBiz {
//系列声明用到参数
String skuId = reqDto.getSkuId();
//以下系列名称可以用spu名称代替
String seriesName = GalaxyConstant.SERIES_NAME_PREFIX.concat(skuId);
String seriesCode = GalaxyConstant.SERIES_NAME_PREFIX.concat(skuId);
String seriesName = GalaxyConstant.SERIES_NAME_XUPER_PREFIX.concat(skuId);
String seriesCode = GalaxyConstant.SERIES_NAME_XUPER_PREFIX.concat(skuId);
Long totalCount = reqDto.getTotalCount();
String coverUrl = reqDto.getCoverUrl();//暂时用nftUrl
......@@ -155,35 +156,41 @@ public class XuperArtworkBiz {
try {
Xuper002CreateAssetReqDto xuper002CreateAssetReqDto = Xuper002CreateAssetReqDto.getNew();
String nftUrl = "bos_v1://xasset-offline/110381/ZXLNFTIMAGE202206231042217867523750.jpg/";
// String nftUrl = "bos_v1://xasset-offline/110381/ZXLNFTIMAGE202206231042217867523750.jpg/";
String nftUrl = reqDto.getNftUrl();
//该文件只为了生成hash值
String originalNftUrl = seriesNftUploadBo.getOriginalNftUrl();
String displlayUrl = reqDto.getDisplayUrl();
try {
xuper002CreateAssetReqDto.setMnemonic(xuperConfig.getNftPlatformMnemonic());
//资产碎片数量,小于1和大于200000代表不做库存限制
xuper002CreateAssetReqDto.setAmount(100);
xuper002CreateAssetReqDto.setAmount(totalCount.intValue());
//藏品显示售卖价格,单位为分
xuper002CreateAssetReqDto.setPrice(1000l);
xuper002CreateAssetReqDto.setPrice(Long.parseLong(reqDto.getSellCount()));
//资产分类。1:艺术品 2:收藏品 3:门票 4:酒店
xuper002CreateAssetReqDto.setAssetCate(Integer.valueOf(XuperEnum.assetTypeEnum.COLLECTION.getCode()));
//资产名称,小于30个字节
xuper002CreateAssetReqDto.setTitle("百度超级链-数字藏品-测试20220622-001");
xuper002CreateAssetReqDto.setTitle(reqDto.getNftName());
//资产缩略图。bos上传的图片,格式支持:”jpg”, “jpeg”, “png”, “bmp”, “webp”, “heic”。参数格式bos_v1://{bucket}/{object}/{width}_{height}
xuper002CreateAssetReqDto.setThumb(nftUrl.concat("1000_500"));
xuper002CreateAssetReqDto.setThumb(displlayUrl.concat("1000_500"));
//短文字描述,小于300个字节
xuper002CreateAssetReqDto.setShortDesc(xuper002CreateAssetReqDto.getTitle().concat("-短文字描述小于300个字节"));
xuper002CreateAssetReqDto.setShortDesc(reqDto.getNftDesc());
//(可选)资产详情介绍长图。bos上传的图片,格式支持:”jpg”, “jpeg”, “png”, “bmp”, “webp”, “heic”。参数格式bos_v1://{bucket}/{object}/{width}_{height}
xuper002CreateAssetReqDto.setImgDesc(nftUrl.concat("1000_500"));
xuper002CreateAssetReqDto.setImgDesc(displlayUrl.concat("1000_500"));
//资产原始文件。比如图片,图片本身就是资产。格式bos_v1://{bucket}/{object} ,文件大小<10M。文件名采用文件md5值,为了正常展现,需要正确携带文件后缀
xuper002CreateAssetReqDto.setAssetUrl(nftUrl.concat("900_1200"));
//(可选)长文字描述,小于1200个字节
xuper002CreateAssetReqDto.setLongDesc(xuper002CreateAssetReqDto.getTitle().concat("-长文字描述,小于1200个字节"));
xuper002CreateAssetReqDto.setLongDesc(reqDto.getNftDesc());
//(可选)资产额外描述信息json字符串。比如标签
xuper002CreateAssetReqDto.setAssetExt("{\"tags\":[\"艺术品\",\"古董\"]} ");
// xuper002CreateAssetReqDto.setAssetExt("{\"tags\":[\"艺术品\",\"古董\"]} ");
//(可选)资产组id。用于关联业务层酒店/店铺id
xuper002CreateAssetReqDto.setGroupId(123123l);
xuper002CreateAssetReqDto.setGroupId(0l);
//(可选)业务侧用户标记,必要时请安全处理后设置
xuper002CreateAssetReqDto.setUserId(123123l);
xuper002CreateAssetReqDto.setUserId(0l);
//(可选)要存证的资产文件sm3散列值,如有多个文件逐个计算hash值后合并计算最终hash值
xuper002CreateAssetReqDto.setFileHash(new String(Hash.doubleSha256(nftUrl.concat("900_1200").getBytes())));
xuper002CreateAssetReqDto.setFileHash(this.getNftHashByNftUrl(originalNftUrl));
//执行数字资产创建
XuperResponseDto<Xuper002CreateAssetRespDto> xuperResponseDto = xuperSdkUtil.xuper002CreateAsset(xuper002CreateAssetReqDto);
if(xuperResponseDto.isSuccess()){
xuper002CreateAssetRespDto = xuperResponseDto.getParseData(Xuper002CreateAssetRespDto.class);
......@@ -338,7 +345,7 @@ public class XuperArtworkBiz {
//完整全路径 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;
XuperUploadFileRespDto xuperUploadFileRespDto = null;
try {
String filePath = null;
String imageType = null;
......@@ -349,13 +356,13 @@ public class XuperArtworkBiz {
}else{
imageType = originalUrl.substring(originalUrl.lastIndexOf("."),originalUrl.length());
}
String fileName = IDGenerator.getZxlNftImageCosCode() + imageType;
String fileName = IDGenerator.getXuperNftImageCosCode() + imageType;
//通过图片url地址上传
File cosFile = galaxyCommonBiz.inputStreamToFile(originalUrl,fileName);
filePath = cosFile.getAbsolutePath();
log.info("cosFile.getPath() :{}",cosFile.getPath());
log.info("cosFile.getAbsoluteFile() :{}",cosFile.getAbsoluteFile());
filePath = cosFile.getPath();
log.info("cosFile.getPath() :{}",cosFile.getPath());//Users/anjiabin/data/galaxy/tempFilePath/XUPERNFTIMAGE202206291056041871343690.jpg
log.info("cosFile.getAbsoluteFile() :{}",cosFile.getAbsoluteFile());///Users/anjiabin/mdsky_gitlab/liquidnet-bus-v1/Users/anjiabin/data/galaxy/tempFilePath/XUPERNFTIMAGE202206291056041871343690.jpg
XuperUploadFileReqDto reqDto = XuperUploadFileReqDto.getNew();
......@@ -373,20 +380,58 @@ public class XuperArtworkBiz {
reqDto.setProperty("");
XuperResponseDto<XuperUploadFileRespDto> uploadFileResp = xuperSdkUtil.xuperUploadFile(reqDto);
if(uploadFileResp.isSuccess()){
respDto = uploadFileResp.getParseData(XuperUploadFileRespDto.class);
fullFilePath = respDto.getLink();
xuperUploadFileRespDto = uploadFileResp.getParseData(XuperUploadFileRespDto.class);
fullFilePath = xuperUploadFileRespDto.getLink();
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("testXuperUploadFile resp : "+ JsonUtils.toJson(respDto));
log.info("xuper getFullFilePath xuperUploadFile resp : "+ JsonUtils.toJson(xuperUploadFileRespDto));
log.info("完整的素材访问fullFilePath url:{}",fullFilePath);
return fullFilePath;
}
private String getNftHashByNftUrl(String originalUrl){
//原始介质文件hash值
String nftHashStr = null;
try {
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.getXuperNftImageCosCode() + imageType;
//通过图片url地址上传
File cosFile = galaxyCommonBiz.inputStreamToFile(originalUrl,fileName);
filePath = cosFile.getPath();
log.info("cosFile.getPath() :{}",cosFile.getPath());//Users/anjiabin/data/galaxy/tempFilePath/XUPERNFTIMAGE202206291056041871343690.jpg
log.info("cosFile.getAbsoluteFile() :{}",cosFile.getAbsoluteFile());///Users/anjiabin/mdsky_gitlab/liquidnet-bus-v1/Users/anjiabin/data/galaxy/tempFilePath/XUPERNFTIMAGE202206291056041871343690.jpg
byte[] fileByte = new byte[0];
try {
fileByte = galaxyCommonBiz.toByteArray(new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
nftHashStr = new String(Hash.doubleSha256(fileByte));
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("getNftHashByNftUrl url:{} ,hashStr:{}",originalUrl,nftHashStr);
return nftHashStr;
}
private GalaxySeriesInfoBo buildSeriesInfoBo(GalaxyArtSeriesClaimReqDto reqDto,String taskId,String publishStatus){
String seriesName = reqDto.getSkuId();
......
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