|
|
@@ -14,6 +14,7 @@ import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
|
|
|
import com.crm.rely.backend.core.exception.ServiceException;
|
|
|
import com.crm.rely.backend.core.pojo.table.SysConfigTable;
|
|
|
import com.crm.rely.backend.model.config.VaultodyConfig;
|
|
|
+import com.crm.rely.backend.model.config.VaultodyOrderConfig;
|
|
|
import com.crm.rely.backend.model.constant.ConfigConstants;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.TransactionItemDto;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.VaultTransaction;
|
|
|
@@ -22,12 +23,15 @@ import com.crm.rely.backend.model.dto.vaultody.vaults.response.ResponseData;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.response.TransactionItem;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.response.TransactionResponse;
|
|
|
import com.crm.rely.backend.model.dto.vaultody.vaults.response.VaultsListResponseDto;
|
|
|
+import com.crm.rely.backend.model.entity.vaultody.settlement.VaultodyOrderSerialQueryEntity;
|
|
|
import com.crm.rely.backend.model.entity.vaultody.vaults.VaultTransactionsEntity;
|
|
|
import com.crm.rely.backend.model.entity.vaultody.vaults.VaultTransactionsSearchEntity;
|
|
|
import com.crm.rely.backend.model.pojo.table.SysVaultodyConfigTable;
|
|
|
import com.crm.rely.backend.model.pojo.table.TransactionItemTable;
|
|
|
import com.crm.rely.backend.util.AESUtil;
|
|
|
import com.crm.rely.backend.util.HttpUtil;
|
|
|
+import com.crm.rely.backend.util.MapUtil;
|
|
|
+import com.crm.rely.backend.util.SignUtil;
|
|
|
import com.crm.rely.backend.util.UUIDUtil;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -213,6 +217,17 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
return vaultodyConfig;
|
|
|
}
|
|
|
|
|
|
+ public VaultodyOrderConfig getVaultodyOrderConfig() {
|
|
|
+ SysVaultodyConfigTable configTable = vaultodyConfigService.getByCode(ConfigConstants.VAULTODY_ORDER_SERIAL_CONFIG);
|
|
|
+ if (configTable == null) {
|
|
|
+ throw ServiceException.exception(Constants.SYSTEM_ERROR);
|
|
|
+ }
|
|
|
+ String aesKey = getPropertyKey();
|
|
|
+
|
|
|
+ String property = AESUtil.decrypt(configTable.getValue(), aesKey);
|
|
|
+ return JSON.parseObject(property, VaultodyOrderConfig.class);
|
|
|
+ }
|
|
|
+
|
|
|
public VaultodyConfig getVaultodyConfig(String vaultId) {
|
|
|
SysVaultodyConfigTable configTable = vaultodyConfigService.getByCode(ConfigConstants.VAULTODY_MANAGER_CONFIG);
|
|
|
if (configTable == null) {
|
|
|
@@ -244,6 +259,73 @@ public class VaultodyServiceImpl implements VaultodyService {
|
|
|
return table.getValue();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据交易流水号查询订单号
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, String> getOrderSerialByTransactionIds(List<String> transactionIds) {
|
|
|
+ if (CollectionUtils.isEmpty(transactionIds)) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ VaultodyOrderConfig config = getVaultodyOrderConfig();
|
|
|
+ if (config == null || StringUtils.isBlank(config.getMerchantId()) || StringUtils.isBlank(config.getPrivateKey())
|
|
|
+ || StringUtils.isBlank(config.getPlatformPublicKey()) || StringUtils.isBlank(config.getBaseUrl())
|
|
|
+ || StringUtils.isBlank(config.getQueryPath())) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ VaultodyOrderSerialQueryEntity queryEntity = new VaultodyOrderSerialQueryEntity();
|
|
|
+ queryEntity.setMerchantId(config.getMerchantId());
|
|
|
+ queryEntity.setTransactionIds(transactionIds);
|
|
|
+ queryEntity.setRequestTime(System.currentTimeMillis());
|
|
|
+ queryEntity.setSign(SignUtil.signSHA256withRSA(config.getPrivateKey(), getOrderSerialSignString(queryEntity)));
|
|
|
+ Connection.Response response = HttpUtil.post(config.getBaseUrl() + config.getQueryPath(), JSON.toJSONString(queryEntity));
|
|
|
+ if (response.statusCode() != 200) {
|
|
|
+ log.error("get order serial failed,status:{},body:{}", response.statusCode(), response.body());
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ BaseResultDto resultDto = JSON.parseObject(response.body(), BaseResultDto.class);
|
|
|
+ if (resultDto == null || resultDto.getCode() != Constants.SUCCESS_CODE || resultDto.getData() == null) {
|
|
|
+ log.error("get order serial result error,body:{}", response.body());
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ Map<String, Object> responseMap = JSON.parseObject(JSON.toJSONString(resultDto.getData()), Map.class);
|
|
|
+ Map<String, String> data = JSON.parseObject(JSON.toJSONString(responseMap.get("data")), Map.class);
|
|
|
+ Long requestTime = Long.valueOf(String.valueOf(responseMap.get("requestTime")));
|
|
|
+ String sign = String.valueOf(responseMap.get("sign"));
|
|
|
+ if (Math.abs(System.currentTimeMillis() - requestTime) > 60000) {
|
|
|
+ log.error("get order serial response time out,response:{}", response.body());
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ if (!SignUtil.verifySignSHA256withRSA(config.getPlatformPublicKey(),
|
|
|
+ getOrderSerialResponseSignString(config.getMerchantId(), requestTime, new TreeMap<>(data)), sign)) {
|
|
|
+ log.error("get order serial response sign error,response:{}", response.body());
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ } catch (Exception e){
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getOrderSerialSignString(VaultodyOrderSerialQueryEntity entity) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("merchantId", entity.getMerchantId());
|
|
|
+ map.put("requestTime", String.valueOf(entity.getRequestTime()));
|
|
|
+ map.put("transactionIds", StringUtils.join(entity.getTransactionIds(), ","));
|
|
|
+ return MapUtil.getStringSortByKey(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getOrderSerialResponseSignString(String merchantId, Long requestTime, Map<String, String> data) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("merchantId", merchantId);
|
|
|
+ map.put("requestTime", String.valueOf(requestTime));
|
|
|
+ map.put("data", JSON.toJSONString(data));
|
|
|
+ return MapUtil.getStringSortByKey(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public BaseResultDto vaultsList() throws Exception {
|