|
|
@@ -27,10 +27,12 @@ import java.net.URLDecoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.DecimalFormatSymbols;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -47,10 +49,15 @@ public class SandPayService {
|
|
|
return DateTimeUtils.format(LocalDateTime.now(), "yyyyMMddHHmmss");
|
|
|
}
|
|
|
|
|
|
- public String getTimeout(int seconds) {
|
|
|
+ public static String getTimeout(int seconds) {
|
|
|
return DateTimeUtils.format(LocalDateTime.now().plusSeconds(seconds), "yyyyMMddHHmmss");
|
|
|
}
|
|
|
|
|
|
+ public static String getTimeout(LocalDateTime createTime, int seconds) {
|
|
|
+ return DateTimeUtils.format(Optional.ofNullable(createTime).orElse(LocalDateTime.now())
|
|
|
+ .plusSeconds(seconds), "yyyyMMddHHmmss");
|
|
|
+ }
|
|
|
+
|
|
|
public String convertAmount(BigDecimal amount) {
|
|
|
DecimalFormat df = new DecimalFormat("000000000000", DecimalFormatSymbols.getInstance(Locale.US));
|
|
|
return df.format(amount.multiply(new BigDecimal("100")));
|
|
|
@@ -120,7 +127,7 @@ public class SandPayService {
|
|
|
}
|
|
|
|
|
|
public String requestAlipay(String orderId, BigDecimal amount, String subject, String desc,
|
|
|
- int timeout, String extend) {
|
|
|
+ String 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");
|
|
|
@@ -129,7 +136,7 @@ public class SandPayService {
|
|
|
}
|
|
|
|
|
|
public JSONObject requestAlipayRaw(String orderId, BigDecimal amount, String subject, String desc,
|
|
|
- int timeout, String extend) {
|
|
|
+ String timeout, String extend) {
|
|
|
if (orderId.length() < 12) {
|
|
|
for (int i = orderId.length(); i < 12; i++) {
|
|
|
orderId = "0" + orderId;
|
|
|
@@ -151,7 +158,7 @@ public class SandPayService {
|
|
|
//body.put("limitPay", "5"); //限定支付方式 送1-限定不能使用贷记卡 送4-限定不能使用花呗 送5-限定不能使用贷记卡+花呗
|
|
|
body.put("subject", subject); //订单标题
|
|
|
body.put("body", desc); //订单描述
|
|
|
- body.put("txnTimeOut", getTimeout(timeout)); //订单超时时间
|
|
|
+ body.put("txnTimeOut", timeout); //订单超时时间
|
|
|
body.put("notifyUrl", sandPayProperties.getNotifyUrl()); //异步通知地址
|
|
|
body.put("bizExtendParams", ""); //业务扩展参数
|
|
|
body.put("merchExtendParams", ""); //商户扩展参数
|
|
|
@@ -249,7 +256,7 @@ public class SandPayService {
|
|
|
extend.put("id", orderId);
|
|
|
|
|
|
JSONObject res = requestAlipayRaw(orderId.toString(), order.getTotalPrice(), order.getName(), order.getName(),
|
|
|
- 180, extend.toJSONString());
|
|
|
+ getTimeout(order.getCreatedAt(), 180), extend.toJSONString());
|
|
|
if (res == null)
|
|
|
throw new BusinessException("下单失败,请稍后再试");
|
|
|
|
|
|
@@ -305,8 +312,9 @@ public class SandPayService {
|
|
|
extend.put("type", "gift");
|
|
|
extend.put("id", orderId);
|
|
|
|
|
|
- JSONObject res = requestAlipayRaw(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(), "转增" + order.getAssetId(),
|
|
|
- 180, extend.toJSONString());
|
|
|
+ JSONObject res = requestAlipayRaw(orderId.toString(), order.getGasPrice(), "转增" + order.getAssetId(),
|
|
|
+ "转增" + order.getAssetId(),
|
|
|
+ getTimeout(order.getCreatedAt(), 180), extend.toJSONString());
|
|
|
if (res == null)
|
|
|
throw new BusinessException("下单失败,请稍后再试");
|
|
|
|
|
|
@@ -335,7 +343,7 @@ public class SandPayService {
|
|
|
extend.put("id", orderId);
|
|
|
|
|
|
JSONObject res = requestAlipayRaw(orderId.toString(), order.getGasPrice(), "铸造活动:" + order.getMintActivityId(),
|
|
|
- "铸造活动:" + order.getMintActivityId(), 180, extend.toJSONString());
|
|
|
+ "铸造活动:" + order.getMintActivityId(), getTimeout(order.getCreatedAt(), 180), extend.toJSONString());
|
|
|
if (res == null)
|
|
|
throw new BusinessException("下单失败,请稍后再试");
|
|
|
|