|
|
@@ -119,8 +119,17 @@ public class SandPayService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public JSONObject requestAlipay(String orderId, BigDecimal amount, String subject, String desc,
|
|
|
- int timeout, String extend) {
|
|
|
+ public String requestAlipay(String orderId, BigDecimal amount, String subject, String desc,
|
|
|
+ int timeout, String extend) {
|
|
|
+ JSONObject res = requestAlipayRaw(orderId, amount, subject, desc, timeout, extend);
|
|
|
+ if ("000000".equals(res.getJSONObject("head").getString("respCode"))) {
|
|
|
+ return "alipays://platformapi/startapp?saId=10000007&qrcode=" + res.getJSONObject("body").getString("qrCode");
|
|
|
+ }
|
|
|
+ throw new BusinessException("绿洲宇宙冷却系统已启动,请稍后支付");
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject requestAlipayRaw(String orderId, BigDecimal amount, String subject, String desc,
|
|
|
+ int timeout, String extend) {
|
|
|
if (orderId.length() < 12) {
|
|
|
for (int i = orderId.length(); i < 12; i++) {
|
|
|
orderId = "0" + orderId;
|
|
|
@@ -142,7 +151,7 @@ public class SandPayService {
|
|
|
//body.put("limitPay", "5"); //限定支付方式 送1-限定不能使用贷记卡 送4-限定不能使用花呗 送5-限定不能使用贷记卡+花呗
|
|
|
body.put("subject", subject); //订单标题
|
|
|
body.put("body", desc); //订单描述
|
|
|
- body.put("txnTimeOut", getTimeout(180)); //订单超时时间
|
|
|
+ body.put("txnTimeOut", getTimeout(timeout)); //订单超时时间
|
|
|
body.put("notifyUrl", sandPayProperties.getNotifyUrl()); //异步通知地址
|
|
|
body.put("bizExtendParams", ""); //业务扩展参数
|
|
|
body.put("merchExtendParams", ""); //商户扩展参数
|
|
|
@@ -239,7 +248,7 @@ public class SandPayService {
|
|
|
extend.put("type", "order");
|
|
|
extend.put("id", orderId);
|
|
|
|
|
|
- JSONObject res = requestAlipay(orderId.toString(), order.getTotalPrice(), order.getName(), order.getName(),
|
|
|
+ JSONObject res = requestAlipayRaw(orderId.toString(), order.getTotalPrice(), order.getName(), order.getName(),
|
|
|
180, extend.toJSONString());
|
|
|
if (res == null)
|
|
|
throw new BusinessException("下单失败,请稍后再试");
|
|
|
@@ -296,7 +305,7 @@ public class SandPayService {
|
|
|
extend.put("type", "gift");
|
|
|
extend.put("id", orderId);
|
|
|
|
|
|
- JSONObject res = requestAlipay(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(), "转增" + order.getAssetId(),
|
|
|
+ JSONObject res = requestAlipayRaw(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(), "转增" + order.getAssetId(),
|
|
|
180, extend.toJSONString());
|
|
|
if (res == null)
|
|
|
throw new BusinessException("下单失败,请稍后再试");
|
|
|
@@ -325,7 +334,7 @@ public class SandPayService {
|
|
|
extend.put("type", "mintOrder");
|
|
|
extend.put("id", orderId);
|
|
|
|
|
|
- JSONObject res = requestAlipay(orderId.toString(), order.getGasPrice(), "铸造活动:" + order.getMintActivityId(),
|
|
|
+ JSONObject res = requestAlipayRaw(orderId.toString(), order.getGasPrice(), "铸造活动:" + order.getMintActivityId(),
|
|
|
"铸造活动:" + order.getMintActivityId(), 180, extend.toJSONString());
|
|
|
if (res == null)
|
|
|
throw new BusinessException("下单失败,请稍后再试");
|
|
|
@@ -407,7 +416,107 @@ public class SandPayService {
|
|
|
try {
|
|
|
log.info("请求报文:{}", reqMap);
|
|
|
result = HttpClient.doPost("https://caspay.sandpay.com.cn/agent-main/openapi/agentpay",
|
|
|
- reqMap, 10000, 10000);
|
|
|
+ reqMap, 300000, 300000);
|
|
|
+ result = URLDecoder.decode(result, StandardCharsets.UTF_8);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("响应报文:{}", result);
|
|
|
+ Map<String, String> responseMap = SDKUtil.convertResultStringToMap(result);
|
|
|
+
|
|
|
+ String retEncryptKey = responseMap.get("encryptKey");
|
|
|
+ String retEncryptData = responseMap.get("encryptData");
|
|
|
+ String retSign = responseMap.get("sign");
|
|
|
+
|
|
|
+ log.debug("retEncryptKey:[{}]", retEncryptKey);
|
|
|
+ log.debug("retEncryptData:[{}]", retEncryptData);
|
|
|
+ log.debug("retSign:[{}]", retSign);
|
|
|
+
|
|
|
+ byte[] decodeBase64KeyBytes = Base64.decodeBase64(retEncryptKey
|
|
|
+ .getBytes(StandardCharsets.UTF_8));
|
|
|
+
|
|
|
+ byte[] merchantAESKeyBytes = CryptoUtil.RSADecrypt(
|
|
|
+ decodeBase64KeyBytes, CertUtil.getPrivateKey(), 2048, 11,
|
|
|
+ "RSA/ECB/PKCS1Padding");
|
|
|
+
|
|
|
+ byte[] decodeBase64DataBytes = Base64.decodeBase64(retEncryptData.getBytes(StandardCharsets.UTF_8));
|
|
|
+
|
|
|
+ byte[] respDataBytes = CryptoUtil.AESDecrypt(decodeBase64DataBytes,
|
|
|
+ merchantAESKeyBytes, "AES", "AES/ECB/PKCS5Padding", null);
|
|
|
+
|
|
|
+ String respData = new String(respDataBytes, StandardCharsets.UTF_8);
|
|
|
+ log.info("retData:[" + respData + "]");
|
|
|
+ System.out.println("响应data数据:" + respData);
|
|
|
+
|
|
|
+ byte[] signBytes = Base64.decodeBase64(retSign.getBytes(StandardCharsets.UTF_8));
|
|
|
+
|
|
|
+ boolean isValid = CryptoUtil.verifyDigitalSign(respDataBytes, signBytes,
|
|
|
+ CertUtil.getPublicKey(), "SHA1WithRSA");
|
|
|
+
|
|
|
+ if (!isValid) {
|
|
|
+ log.error("verify sign fail.");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ log.info("verify sign success");
|
|
|
+ System.out.println("verify sign success");
|
|
|
+
|
|
|
+ JSONObject respJson = JSONObject.parseObject(respData);
|
|
|
+ return respJson;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject queryTransfer(String tranTime, String orderId) {
|
|
|
+ JSONObject request = new JSONObject();
|
|
|
+ request.put("version", "01"); // 版本号
|
|
|
+ request.put("productId", "00000004"); // 产品ID
|
|
|
+ request.put("tranTime", tranTime); // 查询订单的交易时间
|
|
|
+ request.put("orderCode", orderId); // 要查询的订单号
|
|
|
+
|
|
|
+ String reqData = request.toJSONString();
|
|
|
+ log.info("请求数据:{}", reqData);
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ String aesKey = RandomStringGenerator.getRandomStringByLength(16);
|
|
|
+ byte[] aesKeyBytes = aesKey.getBytes(StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ byte[] plainBytes = reqData.getBytes(StandardCharsets.UTF_8);
|
|
|
+ String encryptData = new String(Base64.encodeBase64(
|
|
|
+ CryptoUtil.AESEncrypt(plainBytes, aesKeyBytes, "AES",
|
|
|
+ "AES/ECB/PKCS5Padding", null)), StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ String sign = new String(Base64.encodeBase64(
|
|
|
+ CryptoUtil.digitalSign(plainBytes, CertUtil.getPrivateKey(),
|
|
|
+ "SHA1WithRSA")), StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ String encryptKey = new String(Base64.encodeBase64(
|
|
|
+ CryptoUtil.RSAEncrypt(aesKeyBytes, CertUtil.getPublicKey(), 2048, 11,
|
|
|
+ "RSA/ECB/PKCS1Padding")), StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, String> reqMap = new HashMap<String, String>();
|
|
|
+ //整体报文格式
|
|
|
+ reqMap.put("transCode", "ODQU"); // 交易码
|
|
|
+ reqMap.put("accessType", "0"); // 接入类型
|
|
|
+ reqMap.put("merId", sandPayProperties.getMid()); // 合作商户ID 杉德系统分配,唯一标识
|
|
|
+ reqMap.put("plId", null);
|
|
|
+ reqMap.put("encryptKey", encryptKey); // 加密后的AES秘钥
|
|
|
+ reqMap.put("encryptData", encryptData); // 加密后的请求/应答报文
|
|
|
+ reqMap.put("sign", sign); // 签名
|
|
|
+ reqMap.put("extend", ""); // 扩展域
|
|
|
+
|
|
|
+ String result;
|
|
|
+ try {
|
|
|
+ log.info("请求报文:{}", reqMap);
|
|
|
+ result = HttpClient.doPost("https://caspay.sandpay.com.cn/agent-main/openapi/queryOrder",
|
|
|
+ reqMap, 300000, 300000);
|
|
|
result = URLDecoder.decode(result, StandardCharsets.UTF_8);
|
|
|
} catch (IOException e) {
|
|
|
log.error(e.getMessage());
|