提交 6248dba4 authored 作者: zjm's avatar zjm

fix(区块链): 修改了根据不同环境是否使用区块

修改了根据不同环境是否使用区块
上级 f6cf91ea
...@@ -4,6 +4,7 @@ import com.tykj.dev.blockcha.conf.BcUrl; ...@@ -4,6 +4,7 @@ import com.tykj.dev.blockcha.conf.BcUrl;
import com.tykj.dev.blockcha.subject.entity.*; import com.tykj.dev.blockcha.subject.entity.*;
import com.tykj.dev.blockcha.subject.service.BlockChainUtil; import com.tykj.dev.blockcha.subject.service.BlockChainUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -16,7 +17,7 @@ import java.util.UUID; ...@@ -16,7 +17,7 @@ import java.util.UUID;
* 步骤: * 步骤:
* 1.构建请求参数 * 1.构建请求参数
* 2.通过rest_template获取数据 * 2.通过rest_template获取数据
* 测试 *
* @author LJJ cnljj1995@gmail.com * @author LJJ cnljj1995@gmail.com
* on 2020-08-13 * on 2020-08-13
*/ */
...@@ -24,6 +25,9 @@ import java.util.UUID; ...@@ -24,6 +25,9 @@ import java.util.UUID;
@Component @Component
public class BlockChainUtilImpl implements BlockChainUtil { public class BlockChainUtilImpl implements BlockChainUtil {
@Value("${block.flag}")
public boolean flag;
private String SECRET_KEY = "3mdeM1dw2FfHrd5h6WAuhB3WYdDG6ZAgz96CcM1nzxbiYA8QaaZHW75Je9xKixTTD2rwujyb1gVUNPYm5W6FPZQ8"; private String SECRET_KEY = "3mdeM1dw2FfHrd5h6WAuhB3WYdDG6ZAgz96CcM1nzxbiYA8QaaZHW75Je9xKixTTD2rwujyb1gVUNPYm5W6FPZQ8";
private String SECRET_ID = "3yXRRiL9xsLfbt2kv7qRH2so6ChJX3rFkay7Njcsxfbp"; private String SECRET_ID = "3yXRRiL9xsLfbt2kv7qRH2so6ChJX3rFkay7Njcsxfbp";
...@@ -72,13 +76,13 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -72,13 +76,13 @@ public class BlockChainUtilImpl implements BlockChainUtil {
@Override @Override
public BcText sendText(Integer index,Integer subCode, String content) { public BcText sendText(Integer index,Integer subCode, String content) {
if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", content); request.put("content", content);
request.put("subCode", subCode); request.put("subCode", subCode);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY)); request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
switch (index){ switch (index) {
case 1: case 1:
return new RestTemplate().postForObject( return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.SEND_TEXT, BLOCK_CHAIN_URL + BcUrl.SEND_TEXT,
...@@ -115,34 +119,44 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -115,34 +119,44 @@ public class BlockChainUtilImpl implements BlockChainUtil {
request, request,
BcText.class BcText.class
); );
// return new BcText().toData(); }else {
return new BcText().toData();
}
} }
@Override @Override
public BcText sendText(Integer subCode, String content) { public BcText sendText(Integer subCode, String content) {
if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", content); request.put("content", content);
request.put("subCode", subCode); request.put("subCode", subCode);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY)); request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
return new RestTemplate().postForObject( return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.SEND_TEXT, BLOCK_CHAIN_URL + BcUrl.SEND_TEXT,
request, request,
BcText.class BcText.class
); );
}else {
return new BcText().toData();
}
} }
// public static void main(String[] args) {
// new BlockChainUtilImpl().sendHash(1,"阿斯顿好看");
// }
@Override @Override
public BcHash sendHash(Integer index,Integer subCode, String content) { public BcHash sendHash(Integer index,Integer subCode, String content) {
if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", HexUtil.hex64(content)); request.put("content", HexUtil.hex64(content));
request.put("subCode", subCode); request.put("subCode", subCode);
String s = ApiSignatureUtil.getApiSignature(request, SECRET_KEY); String s = ApiSignatureUtil.getApiSignature(request, SECRET_KEY);
log.info("apiSignature:{}",s); log.info("apiSignature:{}", s);
request.put("apiSignature", s); request.put("apiSignature", s);
switch (index){ switch (index) {
case 1: case 1:
return new RestTemplate().postForObject( return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.SEND_HASH, BLOCK_CHAIN_URL + BcUrl.SEND_HASH,
...@@ -180,11 +194,14 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -180,11 +194,14 @@ public class BlockChainUtilImpl implements BlockChainUtil {
request, request,
BcHash.class BcHash.class
); );
}else {
return new BcHash().toDate();
}
} }
@Override @Override
public BcHash sendHash(Integer subCode, String content) { public BcHash sendHash(Integer subCode, String content) {
// if ("true".equals(this.useBlockcha)) { if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", HexUtil.hex64(content)); request.put("content", HexUtil.hex64(content));
request.put("subCode", subCode); request.put("subCode", subCode);
...@@ -198,6 +215,10 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -198,6 +215,10 @@ public class BlockChainUtilImpl implements BlockChainUtil {
BcHash.class BcHash.class
); );
} }
else {
return new BcHash().toDate();
}
}
@Override @Override
public BcRecord fetchRecord(String recordId) { public BcRecord fetchRecord(String recordId) {
...@@ -217,7 +238,6 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -217,7 +238,6 @@ public class BlockChainUtilImpl implements BlockChainUtil {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
map.forEach(request::put); map.forEach(request::put);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY)); request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
return new RestTemplate().postForObject( return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.FETCH_HISTORY, BLOCK_CHAIN_URL + BcUrl.FETCH_HISTORY,
request, request,
...@@ -227,6 +247,7 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -227,6 +247,7 @@ public class BlockChainUtilImpl implements BlockChainUtil {
@Override @Override
public BcText appendText(Integer index,String content, String recordId) { public BcText appendText(Integer index,String content, String recordId) {
if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", content); request.put("content", content);
request.put("recordID", recordId); request.put("recordID", recordId);
...@@ -234,7 +255,7 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -234,7 +255,7 @@ public class BlockChainUtilImpl implements BlockChainUtil {
request.put("apiSignature", s); request.put("apiSignature", s);
switch (index){ switch (index) {
case 1: case 1:
return new RestTemplate().postForObject( return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT, BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT,
...@@ -267,11 +288,14 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -267,11 +288,14 @@ public class BlockChainUtilImpl implements BlockChainUtil {
BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT, BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT,
request, request,
BcText.class); BcText.class);
// return new BcText().toData(); }else {
return new BcText().toData();
}
} }
@Override @Override
public BcText appendText(String content, String recordId) { public BcText appendText(String content, String recordId) {
if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", content); request.put("content", content);
request.put("recordID", recordId); request.put("recordID", recordId);
...@@ -282,10 +306,14 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -282,10 +306,14 @@ public class BlockChainUtilImpl implements BlockChainUtil {
BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT, BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT,
request, request,
BcText.class); BcText.class);
}else {
return new BcText().toData();
}
} }
@Override @Override
public BcHash appendHash(Integer index,String content, String recordId) { public BcHash appendHash(Integer index,String content, String recordId) {
if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", HexUtil.hex64(content)); request.put("content", HexUtil.hex64(content));
request.put("recordID", recordId); request.put("recordID", recordId);
...@@ -293,7 +321,7 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -293,7 +321,7 @@ public class BlockChainUtilImpl implements BlockChainUtil {
request.put("apiSignature", s); request.put("apiSignature", s);
switch (index){ switch (index) {
case 1: case 1:
return new RestTemplate().postForObject( return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.APPEND_HASH, BLOCK_CHAIN_URL + BcUrl.APPEND_HASH,
...@@ -331,12 +359,15 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -331,12 +359,15 @@ public class BlockChainUtilImpl implements BlockChainUtil {
request, request,
BcHash.class BcHash.class
); );
// return new BcHash().toDate(); }else {
return new BcHash().toDate();
}
} }
@Override @Override
public BcHash appendHash(String content, String recordId) { public BcHash appendHash(String content, String recordId) {
if (flag) {
SortedMap<Object, Object> request = getRequest(); SortedMap<Object, Object> request = getRequest();
request.put("content", HexUtil.hex64(content)); request.put("content", HexUtil.hex64(content));
request.put("recordID", recordId); request.put("recordID", recordId);
...@@ -348,7 +379,9 @@ public class BlockChainUtilImpl implements BlockChainUtil { ...@@ -348,7 +379,9 @@ public class BlockChainUtilImpl implements BlockChainUtil {
request, request,
BcHash.class BcHash.class
); );
// return new BcHash().toDate(); }else {
return new BcHash().toDate();
}
} }
@Override @Override
......
...@@ -16,16 +16,13 @@ ...@@ -16,16 +16,13 @@
// * 步骤: // * 步骤:
// * 1.构建请求参数 // * 1.构建请求参数
// * 2.通过rest_template获取数据 // * 2.通过rest_template获取数据
// * // * 测试
// * @author LJJ cnljj1995@gmail.com // * @author LJJ cnljj1995@gmail.com
// * on 2020-08-13 // * on 2020-08-13
// */ // */
//@Slf4j //@Slf4j
//@Component //@Component
//public class BlockChainUtilImplLocal implements BlockChainUtil { //public class BlockChainUtilImpl1 implements BlockChainUtil {
//
//
//
// //
// //
// private String SECRET_KEY = "3mdeM1dw2FfHrd5h6WAuhB3WYdDG6ZAgz96CcM1nzxbiYA8QaaZHW75Je9xKixTTD2rwujyb1gVUNPYm5W6FPZQ8"; // private String SECRET_KEY = "3mdeM1dw2FfHrd5h6WAuhB3WYdDG6ZAgz96CcM1nzxbiYA8QaaZHW75Je9xKixTTD2rwujyb1gVUNPYm5W6FPZQ8";
...@@ -118,6 +115,7 @@ ...@@ -118,6 +115,7 @@
// request, // request,
// BcText.class // BcText.class
// ); // );
//// return new BcText().toData();
// } // }
// //
// @Override // @Override
...@@ -126,6 +124,7 @@ ...@@ -126,6 +124,7 @@
// request.put("content", content); // request.put("content", content);
// request.put("subCode", subCode); // request.put("subCode", subCode);
// request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY)); // request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
//
// return new RestTemplate().postForObject( // return new RestTemplate().postForObject(
// BLOCK_CHAIN_URL + BcUrl.SEND_TEXT, // BLOCK_CHAIN_URL + BcUrl.SEND_TEXT,
// request, // request,
...@@ -133,10 +132,6 @@ ...@@ -133,10 +132,6 @@
// ); // );
// } // }
// //
//// public static void main(String[] args) {
//// new BlockChainUtilImpl().sendHash(1,"阿斯顿好看");
//// }
//
// //
// @Override // @Override
// public BcHash sendHash(Integer index,Integer subCode, String content) { // public BcHash sendHash(Integer index,Integer subCode, String content) {
...@@ -202,10 +197,6 @@ ...@@ -202,10 +197,6 @@
// request, // request,
// BcHash.class // BcHash.class
// ); // );
//// }
//// else {
//// return new BcHash(0, "", new BcHashData("000"));
//// }
// } // }
// //
// @Override // @Override
...@@ -226,6 +217,7 @@ ...@@ -226,6 +217,7 @@
// SortedMap<Object, Object> request = getRequest(); // SortedMap<Object, Object> request = getRequest();
// map.forEach(request::put); // map.forEach(request::put);
// request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY)); // request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
//
// return new RestTemplate().postForObject( // return new RestTemplate().postForObject(
// BLOCK_CHAIN_URL + BcUrl.FETCH_HISTORY, // BLOCK_CHAIN_URL + BcUrl.FETCH_HISTORY,
// request, // request,
...@@ -275,6 +267,7 @@ ...@@ -275,6 +267,7 @@
// BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT, // BLOCK_CHAIN_URL + BcUrl.APPEND_TEXT,
// request, // request,
// BcText.class); // BcText.class);
//// return new BcText().toData();
// } // }
// //
// @Override // @Override
...@@ -338,6 +331,7 @@ ...@@ -338,6 +331,7 @@
// request, // request,
// BcHash.class // BcHash.class
// ); // );
//// return new BcHash().toDate();
// //
// } // }
// //
...@@ -354,6 +348,7 @@ ...@@ -354,6 +348,7 @@
// request, // request,
// BcHash.class // BcHash.class
// ); // );
//// return new BcHash().toDate();
// } // }
// //
// @Override // @Override
......
...@@ -8,3 +8,4 @@ spring.jpa.hibernate.ddl-auto=update ...@@ -8,3 +8,4 @@ spring.jpa.hibernate.ddl-auto=update
# spring boot admin # spring boot admin
spring.boot.admin.client.url=http://localhost:8769 spring.boot.admin.client.url=http://localhost:8769
spring.boot.admin.client.instance.serviceBaseUrl=http://localhost:8087w spring.boot.admin.client.instance.serviceBaseUrl=http://localhost:8087w
block.flag=true
...@@ -7,3 +7,4 @@ logging.file=./log/equip.log ...@@ -7,3 +7,4 @@ logging.file=./log/equip.log
preview.path=http://124.70.145.101:8087/equip/file/ preview.path=http://124.70.145.101:8087/equip/file/
# spring boot admin # spring boot admin
spring.boot.admin.client.url=http://localhost:8769 spring.boot.admin.client.url=http://localhost:8769
block.flag=true
\ No newline at end of file
...@@ -7,3 +7,4 @@ spring.jpa.database-platform=org.hibernate.dialect.OscarDialect ...@@ -7,3 +7,4 @@ spring.jpa.database-platform=org.hibernate.dialect.OscarDialect
#file.path=/opt/zb/ #file.path=/opt/zb/
#preview.path=http://10.153.4.11:8088/equip/file/ #preview.path=http://10.153.4.11:8088/equip/file/
#preview.path=http://192.168.0.80:8088/equip/file/ #preview.path=http://192.168.0.80:8088/equip/file/
block.flag=true
\ No newline at end of file
...@@ -7,3 +7,4 @@ spring.jpa.database-platform=org.hibernate.dialect.OscarDialect ...@@ -7,3 +7,4 @@ spring.jpa.database-platform=org.hibernate.dialect.OscarDialect
file.path=/opt/zb/ file.path=/opt/zb/
preview.path=http://10.153.4.11:8088/equip/file/ preview.path=http://10.153.4.11:8088/equip/file/
#preview.path=http://192.168.0.80:8088/equip/file/ #preview.path=http://192.168.0.80:8088/equip/file/
block.flag=true
\ No newline at end of file
...@@ -7,3 +7,4 @@ spring.jpa.database-platform=org.hibernate.dialect.OscarDialect ...@@ -7,3 +7,4 @@ spring.jpa.database-platform=org.hibernate.dialect.OscarDialect
file.path=/opt/zb/ file.path=/opt/zb/
preview.path=http://10.153.4.11:8088/equipTest/file/ preview.path=http://10.153.4.11:8088/equipTest/file/
spring.jmx.enabled=false spring.jmx.enabled=false
block.flag=false
...@@ -9,3 +9,4 @@ file.path=/opt/zb/ ...@@ -9,3 +9,4 @@ file.path=/opt/zb/
preview.path=http://192.168.0.80:8088/equip/file/ preview.path=http://192.168.0.80:8088/equip/file/
spring.boot.admin.client.url=http://localhost:8769 spring.boot.admin.client.url=http://localhost:8769
spring.boot.admin.client.instance.serviceBaseUrl=http://localhost:8087 spring.boot.admin.client.instance.serviceBaseUrl=http://localhost:8087
block.flag=true
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论