整理天擎接口,编写统一调用公共类

This commit is contained in:
zhangqinbin
2022-01-24 16:58:42 +08:00
parent 0b61aa59a4
commit 85ed0279c0
7 changed files with 715 additions and 17 deletions

View File

@ -0,0 +1,409 @@
/*
* Copyright 2017 DTCC, Fujitsu Australia Software Technology, IBM - All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chinaunicom.mall.ebtp.extend.crypconfigure.crypto.helper;
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA3Digest;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.Comparator;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.codec.binary.Hex.encodeHexString;
public final class Utils {
private static final Log logger = LogFactory.getLog(Utils.class);
private static final boolean TRACE_ENABED = logger.isTraceEnabled();
private static final Config config = Config.getConfig();
private static final int MAX_LOG_STRING_LENGTH = config.maxLogStringLength();
/**
* Generate parameter hash for the given chaincode path,func and args
*
* @param path Chaincode path
* @param func Chaincode function name
* @param args List of arguments
* @return hash of path, func and args
*/
public static String generateParameterHash(String path, String func, List<String> args) {
logger.debug(format("GenerateParameterHash : path=%s, func=%s, args=%s", path, func, args));
// Append the arguments
StringBuilder param = new StringBuilder(path);
param.append(func);
args.forEach(param::append);
// Compute the hash
return Hex.toHexString(hash(param.toString().getBytes(UTF_8), new SHA3Digest()));
}
/**
* Generate hash of a chaincode directory
*
* @param rootDir Root directory
* @param chaincodeDir Channel code directory
* @param hash Previous hash (if any)
* @return hash of the directory
* @throws IOException
*/
public static String generateDirectoryHash(String rootDir, String chaincodeDir, String hash) throws IOException {
// Generate the project directory
Path projectPath;
if (rootDir == null) {
projectPath = Paths.get(chaincodeDir);
} else {
projectPath = Paths.get(rootDir, chaincodeDir);
}
File dir = projectPath.toFile();
if (!dir.exists() || !dir.isDirectory()) {
throw new IOException(format("The chaincode path \"%s\" is invalid", projectPath));
}
StringBuilder hashBuilder = new StringBuilder(hash);
Files.walk(projectPath)
.sorted(Comparator.naturalOrder())
.filter(Files::isRegularFile)
.map(Path::toFile)
.forEach(file -> {
try {
byte[] buf = readFile(file);
byte[] toHash = Arrays.concatenate(buf, hashBuilder.toString().getBytes(UTF_8));
hashBuilder.setLength(0);
hashBuilder.append(Hex.toHexString(hash(toHash, new SHA3Digest())));
} catch (IOException ex) {
throw new RuntimeException(format("Error while reading file %s", file.getAbsolutePath()), ex);
}
});
// If original hash and final hash are the same, it indicates that no new contents were found
if (hashBuilder.toString().equals(hash)) {
throw new IOException(format("The chaincode directory \"%s\" has no files", projectPath));
}
return hashBuilder.toString();
}
/**
* Compress the contents of given directory using Tar and Gzip to an in-memory byte array.
*
* @param sourceDirectory the source directory.
* @param pathPrefix a path to be prepended to every file name in the .tar.gz output, or {@code null} if no prefix is required.
* @param chaincodeMetaInf
* @return the compressed directory contents.
* @throws IOException
*/
public static byte[] generateTarGz(File sourceDirectory, String pathPrefix, File chaincodeMetaInf) throws IOException {
logger.trace(format("generateTarGz: sourceDirectory: %s, pathPrefix: %s, chaincodeMetaInf: %s",
sourceDirectory == null ? "null" : sourceDirectory.getAbsolutePath(), pathPrefix,
chaincodeMetaInf == null ? "null" : chaincodeMetaInf.getAbsolutePath()));
ByteArrayOutputStream bos = new ByteArrayOutputStream(500000);
String sourcePath = sourceDirectory.getAbsolutePath();
// try (TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(bos))) {
// archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
//
// Collection<File> childrenFiles = org.apache.commons.io.FileUtils.listFiles(sourceDirectory, null, true);
//
// ArchiveEntry archiveEntry;
// for (File childFile : childrenFiles) {
// String childPath = childFile.getAbsolutePath();
// String relativePath = childPath.substring((sourcePath.length() + 1));
//
// if (pathPrefix != null) {
// relativePath = Utils.combinePaths(pathPrefix, relativePath);
// }
//
// relativePath = FilenameUtils.separatorsToUnix(relativePath);
//
// if (TRACE_ENABED) {
// logger.trace(format("generateTarGz: Adding '%s' entry from source '%s' to archive.", relativePath, childFile.getAbsolutePath()));
// }
//
// archiveEntry = new TarArchiveEntry(childFile, relativePath);
// archiveOutputStream.putArchiveEntry(archiveEntry);
//
// try (FileInputStream fileInputStream = new FileInputStream(childFile)) {
// IOUtils.copy(fileInputStream, archiveOutputStream);
// } finally {
// archiveOutputStream.closeArchiveEntry();
// }
//
// }
//
// if (null != chaincodeMetaInf) {
// childrenFiles = org.apache.commons.io.FileUtils.listFiles(chaincodeMetaInf, null, true);
//
// final URI metabase = chaincodeMetaInf.toURI();
//
// for (File childFile : childrenFiles) {
//
// final String relativePath = Paths.get("META-INF", metabase.relativize(childFile.toURI()).getPath()).toString();
//
// if (TRACE_ENABED) {
// logger.trace(format("generateTarGz: Adding '%s' entry from source '%s' to archive.", relativePath, childFile.getAbsolutePath()));
// }
//
// archiveEntry = new TarArchiveEntry(childFile, relativePath);
// archiveOutputStream.putArchiveEntry(archiveEntry);
//
// try (FileInputStream fileInputStream = new FileInputStream(childFile)) {
// IOUtils.copy(fileInputStream, archiveOutputStream);
// } finally {
// archiveOutputStream.closeArchiveEntry();
// }
//
// }
//
// }
// }
return bos.toByteArray();
}
/**
* Read the contents a file.
*
* @param input source file to read.
* @return contents of the file.
* @throws IOException
*/
public static byte[] readFile(File input) throws IOException {
return Files.readAllBytes(Paths.get(input.getAbsolutePath()));
}
/**
* Generate a v4 UUID
*
* @return String representation of {@link UUID}
*/
public static String generateUUID() {
return UUID.randomUUID().toString();
}
/**
* Create a new {@link Timestamp} instance based on the current time
*
* @return timestamp
*/
public static Timestamp generateTimestamp() {
Instant time = Instant.now();
return Timestamp.newBuilder().setSeconds(time.getEpochSecond())
.setNanos(time.getNano()).build();
}
/**
* Delete a file or directory
*
* @param file {@link File} representing file or directory
* @throws IOException
*/
public static void deleteFileOrDirectory(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
Path rootPath = Paths.get(file.getAbsolutePath());
Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} else {
file.delete();
}
} else {
throw new RuntimeException("File or directory does not exist");
}
}
/**
* Generate hash of the given input using the given Digest.
*
* @param input input data.
* @param digest the digest to use for hashing
* @return hashed data.
*/
public static byte[] hash(byte[] input, Digest digest) {
byte[] retValue = new byte[digest.getDigestSize()];
digest.update(input, 0, input.length);
digest.doFinal(retValue, 0);
return retValue;
}
/**
* Combine two or more paths
*
* @param first parent directory path
* @param other children
* @return combined path
*/
public static String combinePaths(String first, String... other) {
return Paths.get(first, other).toString();
}
/**
* Read a file from classpath
*
* @param fileName
* @return byte[] data
* @throws IOException
*/
public static byte[] readFileFromClasspath(String fileName) throws IOException {
try (InputStream is = Utils.class.getClassLoader().getResourceAsStream(fileName)) {
return IOUtils.toByteArray(is);
}
}
public static Properties parseGrpcUrl(String url) {
if (isNullOrEmpty(url)) {
throw new RuntimeException("URL cannot be null or empty");
}
Properties props = new Properties();
Pattern p = Pattern.compile("([^:]+)[:]//([^:]+)[:]([0-9]+)", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(url);
if (m.matches()) {
props.setProperty("protocol", m.group(1));
props.setProperty("host", m.group(2));
props.setProperty("port", m.group(3));
String protocol = props.getProperty("protocol");
if (!"grpc".equals(protocol) && !"grpcs".equals(protocol)) {
throw new RuntimeException(format("Invalid protocol expected grpc or grpcs and found %s.", protocol));
}
} else {
throw new RuntimeException("URL must be of the format protocol://host:port. Found: '" + url + "'");
}
// TODO: allow all possible formats of the URL
return props;
}
/**
* Check if the strings Grpc url is valid
*
* @param url
* @return Return the io.seata.core.exception that indicates the error or null if ok.
*/
public static Exception checkGrpcUrl(String url) {
try {
parseGrpcUrl(url);
return null;
} catch (Exception e) {
return e;
}
}
/**
* Check if a string is null or empty.
*
* @param url the string to test.
* @return {@code true} if the string is null or empty; otherwise {@code false}.
*/
public static boolean isNullOrEmpty(String url) {
return url == null || url.isEmpty();
}
/**
* Makes logging strings which can be long or with unprintable characters be logged and trimmed.
*
* @param string Unsafe string too long
* @return returns a string which does not have unprintable characters and trimmed in length.
*/
public static String logString(final String string) {
if (string == null || string.length() == 0) {
return string;
}
String ret = string.replaceAll("[^\\p{Print}]", "?");
ret = ret.substring(0, Math.min(ret.length(), MAX_LOG_STRING_LENGTH)) + (ret.length() > MAX_LOG_STRING_LENGTH ? "..." : "");
return ret;
}
private static final int NONONCE_LENGTH = 24;
private static final SecureRandom RANDOM = new SecureRandom();
public static byte[] generateNonce() {
byte[] values = new byte[NONONCE_LENGTH];
RANDOM.nextBytes(values);
return values;
}
public static String toHexString(ByteString byteString) {
if (byteString == null) {
return null;
}
return encodeHexString(byteString.toByteArray());
}
public static String toHexString(byte[] bytes) {
if (bytes == null) {
return null;
}
return encodeHexString(bytes);
}
public static String toHexString(String bytes) {
if (bytes == null) {
return null;
}
return encodeHexString(bytes.getBytes(UTF_8));
}
/**
* Private constructor to prevent instantiation.
*/
private Utils() {
}
}

View File

@ -10,8 +10,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chinaunicom.baas.util.AccessToken;
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
import com.chinaunicom.mall.ebtp.common.base.service.impl.BaseServiceImpl;
import com.chinaunicom.mall.ebtp.common.constant.CommonConstants;
import com.chinaunicom.mall.ebtp.common.crypto.service.CrypServiceImpl;
import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
import com.chinaunicom.mall.ebtp.common.uniBss.constant.UniBssConstant;
import com.chinaunicom.mall.ebtp.common.uniBss.entity.*;
@ -20,10 +18,12 @@ import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLog;
import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLogVo;
import com.chinaunicom.mall.ebtp.extend.blockchain.service.IBlockChainLogService;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.crypto.service.CrypServiceImpl;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.dao.CrypConfigureMapper;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService;
import com.chinaunicom.mall.ebtp.extend.uniBss.UniBssUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -46,7 +46,7 @@ import static com.chinaunicom.mall.ebtp.common.uniBss.service.UniBssServiceImpl.
*/
@Slf4j
@Service
public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMapper,CrypConfigure> implements ICrypConfigureService {
public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMapper,CrypConfigure> implements ICrypConfigureService {
@Autowired
private IBlockChainLogService iBlockChainLogService;
@ -276,23 +276,12 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
* @return
*/
private String getUniBss(String reqName, Map<String,Object> map){
//获取token
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String TIMESTAMP = format.format(date);
String TRANS_ID = format2.format(date) + (int) ((Math.random() * 9 + 1) * 100000);
String s = "APP_ID" + app_id + "TIMESTAMP" + TIMESTAMP + "TRANS_ID" + TRANS_ID + app_secret;
String token = MD5min(s);
UniBss uniBss = new UniBss();
uniBss.setUniBssAttached(new UniBssAttached().setMediaInf(""));
//天擎部分head
UniBssHead head = new UniBssHead();
head.setAppId(app_id);
head.setTimeStamp(TIMESTAMP);
head.setTransId(TRANS_ID);
head.setToken(token);
uniBss.setUniBssHead(head);
uniBss.setUniBssHead(UniBssUtil.getUniBssHead());
UniReqHead reqhead = new UniReqHead();
//测试写死

View File

@ -0,0 +1,104 @@
package com.chinaunicom.mall.ebtp.extend.uniBss;
import com.alibaba.fastjson.JSON;
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBss;
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBssAttached;
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBssHead;
import com.chinaunicom.mall.ebtp.common.uniBss.service.UniBssServiceImpl;
import com.chinaunicom.mall.ebtp.extend.blockchain.service.IBlockChainLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static com.chinaunicom.mall.ebtp.common.uniBss.service.UniBssServiceImpl.MD5min;
/**
* 对数据表 biz_bid_cryp_configure 操作的 serviceImpl
* @author yss
*
*/
@Slf4j
public class UniBssUtil {
@Value("${mconfig.bss.app-id}")
private static String app_id;
@Value("${mconfig.bss.app-secret}")
private static String app_secret;
/**
* 获取加密签名 Head 参数 公共方法一般不会有变化
* @param
* @return
*/
public static UniBssHead getUniBssHead() {
//获取token
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String TIMESTAMP = format.format(date);
String TRANS_ID = format2.format(date) + (int) ((Math.random() * 9 + 1) * 100000);
String s = "APP_ID" + app_id + "TIMESTAMP" + TIMESTAMP + "TRANS_ID" + TRANS_ID + app_secret;
String token = MD5min(s);
//天擎部分head
UniBssHead head = new UniBssHead();
head.setAppId(app_id);
head.setTimeStamp(TIMESTAMP);
head.setTransId(TRANS_ID);
head.setToken(token);
return head;
}
/**
* 获取加密签名 拼接 对应接口 API名称_REQ + 业务参数
* {
* 【API名称_REQ】:{
* 【业务参数】
* }
* @param map 业务参数
* @return UniBss 对象
*/
public static String getUniBssJson(Map<String,Object> map){
return JSON.toJSONString(UniBssUtil.getUniBss(map));
}
public static UniBss getUniBss(Map<String,Object> reqMap){
UniBss uniBss = new UniBss();
//Head层
uniBss.setUniBssHead(UniBssUtil.getUniBssHead());//公共方法获得
//Body层
uniBss.setUniBssBodyMap(reqMap);
//Attached层
uniBss.setUniBssAttached(new UniBssAttached().setMediaInf(""));// 无特殊要求 默认设置
return uniBss;
}
public static void main(String[] args) {
app_id = "2ICalrrQ0F";
app_secret = "1mb6n6635cJkDb3pEQPUFXc2nRJ8RPaS";
Map map = new HashMap();
map.put("code","1111");
Map<String,Object> reqMap = new HashMap<>();
reqMap.put("DELETE_PUR_MSG_REQ",map);
String json = UniBssUtil.getUniBssJson(reqMap);
log.info("json ----------------"+json);
String str = UniBssServiceImpl.uniBssHttpPost("http://10.124.150.230:8000/api/chinaUnicom/manageCenter/partnerPortal/deletePurMsg/v1", json);
log.info("str --------------"+str);
}
}

View File

@ -0,0 +1,43 @@
package com.chinaunicom.mall.ebtp.extend.uniBss.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chinaunicom.baas.util.AccessToken;
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLogVo;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService;
import com.chinaunicom.mall.ebtp.extend.uniBss.entity.UniBssBean;
import com.chinaunicom.mall.ebtp.extend.uniBss.service.UniService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@Api(value = "天擎公共调用接口")
@RequestMapping("/v1/uniController")
public class UniController {
@Resource
private UniService uniService;
/**
* 调用天擎接口
*
* @param bean
* @return
*/
@ApiOperation("调用天擎接口")
@PostMapping("/toUniBss")
public BaseResponse<Boolean> callUniInterface(@RequestBody UniBssBean bean) {
return BaseResponse.success(this.uniService.toUniBss(bean));
}
}

View File

@ -0,0 +1,30 @@
package com.chinaunicom.mall.ebtp.extend.uniBss.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Map;
/**
* 实体类 CrypConfigure-区块链参数配置表
*
* @author yss
*/
@Data
public class UniBssBean {
/**
* Body参数 Map 格式
* {
* 【API名称_REQ】:{
* 【业务参数】
* }
*/
@ApiModelProperty(value = "req名称+业务参数")
public Map<String,Object> reqMap;
/**
* 天擎接口地址
*/
@ApiModelProperty(value = "天擎接口地址")
public String url;
}

View File

@ -0,0 +1,18 @@
package com.chinaunicom.mall.ebtp.extend.uniBss.service;
import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLogVo;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
import com.chinaunicom.mall.ebtp.extend.uniBss.entity.UniBssBean;
/**
* 对数据表 biz_bid_cryp_configure 操作的 service
* @author yss
*
*/
public interface UniService {
/**
* 请求天擎接口
*/
Boolean toUniBss(UniBssBean uniBssBean);
}

View File

@ -0,0 +1,105 @@
package com.chinaunicom.mall.ebtp.extend.uniBss.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.chinaunicom.baas.util.AccessToken;
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
import com.chinaunicom.mall.ebtp.common.uniBss.constant.UniBssConstant;
import com.chinaunicom.mall.ebtp.common.uniBss.entity.UniBss;
import com.chinaunicom.mall.ebtp.common.uniBss.service.UniBssServiceImpl;
import com.chinaunicom.mall.ebtp.extend.blockchain.service.IBlockChainLogService;
import com.chinaunicom.mall.ebtp.extend.uniBss.UniBssUtil;
import com.chinaunicom.mall.ebtp.extend.uniBss.entity.UniBssBean;
import com.chinaunicom.mall.ebtp.extend.uniBss.service.UniService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 对数据表 biz_bid_cryp_configure 操作的 serviceImpl
* @author yss
*
*/
@Slf4j
@Service
public class UniServiceImpl implements UniService {
@Autowired
private IBlockChainLogService iBlockChainLogService;
private @Autowired
IBaseCacheUserService service;
/**
* 请求天擎接口
*/
@Override
public Boolean toUniBss(UniBssBean uniBssBean){
String json = UniBssUtil.getUniBssJson(uniBssBean.getReqMap());
log.info("天擎接口 请求地址:"+uniBssBean.getUrl());
log.info("天擎接口 请求参数:"+json);
String str = UniBssServiceImpl.uniBssHttpPost(uniBssBean.getUrl(), json);
log.info("天擎接口 返回参数:"+str);
UniBss uniBssRsp = JSONArray.parseObject(str, UniBss.class);
if (uniBssRsp != null && UniBssConstant.RESP_CODE_00000.equals(uniBssRsp.getUniBssHead().getRespCode())) {
if(str!=null&&!"".equals(str)&&str.indexOf("_RSP\":{\"Code\":200,")>=0){
return true;
}
}
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName(str,true);
return false;
}
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, UnsupportedEncodingException {
//String json = "{\"RESULT_ID\":\"1\",\"TP_ID\":\"2\",\"SECTION_ID\":\"3\",\"REPORT_ID\":\"4\",\"RESULTDETAIL\":[{\"RESULT_DETAIL_ID\":\"51\",\"RESULT_ID\":\"52\",\"TENDERER_ID\":\"53\",\"WINNER_CANDIDATE\":\"54\",\"PRICE\":\"55\",\"PRICE_REVIEW\":\"56\",\"BUSINESS_SCORE\":\"57\",\"TECHNICAL_SCORE\":\"58\",\"SERVICE_SCORE\":\"59\",\"PRICE_SCORE\":\"60\",\"TOTAL_SCORE\":\"61\",\"CONTRACTED_MONEY\":\"62\",\"TAX_RATE_PRICE\":\"63\",\"SCOREDETAIL\":[{\"RESULT_DETAIL_ID\":\"71\",\"TENDERER_ID\":\"72\",\"USER_ID\":\"73\",\"BUSINESS_SCORE\":\"74\",\"TECHNICAL_SCORE\":\"75\",\"SERVICE_SCORE\":\"76\",\"PRICE_SCORE\":\"77\"}]}]}";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//format.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = format.format(new Date());
String token = AccessToken.tokenCreate("bidding");
System.out.println(token);
// example of HashMap entity, treeMap can also work out,
// but LinkedHashMap is NOT supported
// Map<String,Object> mapb= new HashMap<>();
//
// Map<String,String> map = new HashMap<>(1);
// map.put("TENDERER_ID","8533");
// map.put("SHOPPINGCART_ID","L3307");
// map.put("AMOUNT","1000");
// map.put("TP_ID","L3307A");
// map.put("SECTION_ID","1111");
// List list = new ArrayList();
// list.add(map);
//mapb.put("BODY_LIST",list);
// String json = "{\"BODY_LIST\":[{\"AMOUNT\":\"0\",\"SHOPPINGCART_ID\":\"1434792850257195008\",\"TENDERER_ID\":\"100002372\",\"TP_ID\":\"1433613698540576768\",\"SECTION_ID\":\"1433613698543464448\"}]}";
// Map jsonMap = parseJSON2Map(json);
// System.out.println(jsonMap);
// CrypConfigureServiceImpl crypService = new CrypConfigureServiceImpl();
//
// CrypBean bean = new CrypBean();
//
// String key = crypService.getSignValue(jsonMap);
// System.out.println(key);
//bean.setObject(jsonMap);
//bean.setSign("MEUCIQCqbcS4d8je+XvTwlSJ1/5IEgiZBYgJlQ+nU/oi2ZeLAgIgd+SZ72Hk8xdKhcVnxwrFsIL6gHMKOFDIbo4nLzmYroM=");
// System.out.println(bean);
//System.out.println("signature of Map: "+bean.getSign());
//System.out.println("signature object of Map: "+bean.getObject());
//byte[] b = JSON.toJSONBytes(bean.getObject(), new SerializerFeature[]{SerializerFeature.MapSortField, SerializerFeature.SortField});
//System.out.println("signature object2 of Map: "+new String(b));
// boolean isOk = crypService.verifyObject(bean);
// System.out.println("verify result of Map: "+ isOk);
}
}