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

Commit 537c4654 authored by anjiabin's avatar anjiabin

优化相关策略实现

parent a6cc452a
...@@ -15,11 +15,14 @@ import org.springframework.util.LinkedMultiValueMap; ...@@ -15,11 +15,14 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -133,7 +136,8 @@ public class ZxlnftBiz { ...@@ -133,7 +136,8 @@ public class ZxlnftBiz {
*/ */
public String getHashString(String data){ public String getHashString(String data){
SM3HashEncodeReq req = SM3HashEncodeReq.getNew(); SM3HashEncodeReq req = SM3HashEncodeReq.getNew();
req.setData(data.getBytes(StandardCharsets.UTF_8)); byte[] fileByteArray = this.getNftFileByteArray(data);
req.setData(fileByteArray);
SM3HashEncodeResp sm3HashEncodeResp = walletSdkService.sM3HashEncode(req); SM3HashEncodeResp sm3HashEncodeResp = walletSdkService.sM3HashEncode(req);
return sm3HashEncodeResp.getDigest(); return sm3HashEncodeResp.getDigest();
} }
...@@ -199,4 +203,28 @@ public class ZxlnftBiz { ...@@ -199,4 +203,28 @@ public class ZxlnftBiz {
return params; return params;
} }
/**
* 获取素材字节数组
* @param url
* @return
*/
public byte[] getNftFileByteArray(String url) {
try {
HttpURLConnection httpUrl = (HttpURLConnection) new URL(url).openConnection();
httpUrl.connect();
InputStream ins = httpUrl.getInputStream();
byte[] arr = new byte[1024];
ByteArrayOutputStream out=new ByteArrayOutputStream();
int len=0;
while((len=ins.read(arr))!=-1){
out.write(arr, 0, len);
}
out.close();
return out.toByteArray();
} catch (Exception e) {
log.error("inputStreamToFileUrlError", e);
return null;
}
}
} }
...@@ -4,10 +4,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,10 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File; import java.io.*;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
......
...@@ -6,8 +6,8 @@ liquidnet: ...@@ -6,8 +6,8 @@ liquidnet:
username: user username: user
password: user123 password: user123
eureka: eureka:
host: 172.17.192.42:7001 # host: 172.17.192.42:7001
# host: 127.0.0.1:7001 host: 127.0.0.1:7001
# end-dev-这里是配置信息基本值 # end-dev-这里是配置信息基本值
spring: spring:
......
...@@ -11,6 +11,7 @@ import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil; ...@@ -11,6 +11,7 @@ import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.DateUtil; import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator; import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.StringUtil; import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.galaxy.router.strategy.biz.GalaxyCommonBiz;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -54,6 +55,9 @@ public class TestZxlWalletSdkUtil { ...@@ -54,6 +55,9 @@ public class TestZxlWalletSdkUtil {
@Autowired @Autowired
private ZxlnftBiz zxlnftBiz; private ZxlnftBiz zxlnftBiz;
@Autowired
private GalaxyCommonBiz galaxyCommonBiz;
/** /**
* 1、生成助记词 * 1、生成助记词
*/ */
...@@ -218,10 +222,12 @@ public class TestZxlWalletSdkUtil { ...@@ -218,10 +222,12 @@ public class TestZxlWalletSdkUtil {
*/ */
@Test @Test
public void sM3Hash(){ public void sM3Hash(){
// String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg"; String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg";
// SM3HashReq req = SM3HashReq.getNew(); cosUrl = "https://nft-user-1255940152.file.myqcloud.com/nft/5867f50e40075319f8bc0bdca59967414d1d9046a4d3c1aaf9bdd8199bb46e4a/0d2d845b56feee933c705786add60b5f12f2909ffcfa7a6b23e58d47a83918cf/%E7%82%AB%E8%BF%882022%E5%AD%A3%E8%8A%82%E7%8F%8D%E8%97%8F%E7%89%88%E6%96%B0%E4%B8%8A%E5%B8%82%E7%B3%BB%E5%88%97/nft_img_20220308_126193.png";
// req.setData(cosUrl.getBytes(StandardCharsets.UTF_8)); SM3HashReq req = SM3HashReq.getNew();
// zxlWalletSdkUtil.sM3Hash(req); req.setData(cosUrl.getBytes(StandardCharsets.UTF_8));
SM3HashResp resp = zxlWalletSdkUtil.sM3Hash(req);
System.out.println(resp.toString());
} }
/** /**
...@@ -229,11 +235,31 @@ public class TestZxlWalletSdkUtil { ...@@ -229,11 +235,31 @@ public class TestZxlWalletSdkUtil {
*/ */
@Test @Test
public void sM3HashEncode(){ public void sM3HashEncode(){
String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg"; String cosUrl = "https://nft-user-1255940152.file.myqcloud.com/nft/5867f50e40075319f8bc0bdca59967414d1d9046a4d3c1aaf9bdd8199bb46e4a/0d2d845b56feee933c705786add60b5f12f2909ffcfa7a6b23e58d47a83918cf/%E7%82%AB%E8%BF%882022%E5%AD%A3%E8%8A%82%E7%8F%8D%E8%97%8F%E7%89%88%E6%96%B0%E4%B8%8A%E5%B8%82%E7%B3%BB%E5%88%97/nft_img_20220308_126193.png";
// String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg";
// String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241628485194860245.jpg"; // String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241628485194860245.jpg";
// String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef//2022-02-24/ZXLNFTIMAGE202202241704292368452405.jpg"; // String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef//2022-02-24/ZXLNFTIMAGE202202241704292368452405.jpg";
cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg";
SM3HashEncodeReq req = SM3HashEncodeReq.getNew(); SM3HashEncodeReq req = SM3HashEncodeReq.getNew();
req.setData(cosUrl.getBytes(StandardCharsets.UTF_8)); req.setData(cosUrl.getBytes(StandardCharsets.UTF_8));
zxlWalletSdkUtil.sM3HashEncode(req); SM3HashEncodeResp resp = zxlWalletSdkUtil.sM3HashEncode(req);
System.out.println(resp.toString());
}
@Test
public void sM3HashEncode2(){
String cosUrl = "https://nft-user-1255940152.file.myqcloud.com/nft/5867f50e40075319f8bc0bdca59967414d1d9046a4d3c1aaf9bdd8199bb46e4a/0d2d845b56feee933c705786add60b5f12f2909ffcfa7a6b23e58d47a83918cf/%E7%82%AB%E8%BF%882022%E5%AD%A3%E8%8A%82%E7%8F%8D%E8%97%8F%E7%89%88%E6%96%B0%E4%B8%8A%E5%B8%82%E7%B3%BB%E5%88%97/nft_img_20220308_126193.png";
// String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg";
// String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241628485194860245.jpg";
// String cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef//2022-02-24/ZXLNFTIMAGE202202241704292368452405.jpg";
cosUrl = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg";
cosUrl = "https://nft-user-1255940152.file.myqcloud.com/nft/5867f50e40075319f8bc0bdca59967414d1d9046a4d3c1aaf9bdd8199bb46e4a/0d2d845b56feee933c705786add60b5f12f2909ffcfa7a6b23e58d47a83918cf/%E7%82%AB%E8%BF%882022%E5%AD%A3%E8%8A%82%E7%8F%8D%E8%97%8F%E7%89%88%E6%96%B0%E4%B8%8A%E5%B8%82%E7%B3%BB%E5%88%97/nft_img_20220308_124595.png";
SM3HashEncodeReq req = SM3HashEncodeReq.getNew();
byte[] fileByteArray = zxlnftBiz.getNftFileByteArray(cosUrl);
req.setData(fileByteArray);
SM3HashEncodeResp resp = zxlWalletSdkUtil.sM3HashEncode(req);
System.out.println(resp.toString());
//eb383d5c4e5a81da3581f275bb8d8dc01910ac2f59e07e48c8e791bf124f59ca
//eb383d5c4e5a81da3581f275bb8d8dc01910ac2f59e07e48c8e791bf124f59ca
} }
} }
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