fix: 添加支付截至时间

pull/2/head
tangqian 2023-05-24 10:23:04 +08:00
parent 9a6e45053c
commit 02a33fbf08
1 changed files with 10 additions and 2 deletions

View File

@ -37,6 +37,8 @@ import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -333,15 +335,17 @@ public class OrderPayServiceImpl implements OrderPayService {
WxPayService wxPayService = wxPayOneAutoConfiguration.wxPayOneService(); WxPayService wxPayService = wxPayOneAutoConfiguration.wxPayOneService();
Assert.notNull(wxPayService, "获取微信支付配置失败!"); Assert.notNull(wxPayService, "获取微信支付配置失败!");
WxPayUnifiedOrderV3Request wxPayRequest = new WxPayUnifiedOrderV3Request(); WxPayUnifiedOrderV3Request wxPayRequest = new WxPayUnifiedOrderV3Request();
int sum = storeOrder.getPayPrice().multiply(new BigDecimal("100")).intValue(); // int sum = storeOrder.getPayPrice().multiply(new BigDecimal("100")).intValue();
int sum = 1;
wxPayRequest.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(sum)); wxPayRequest.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(sum));
wxPayRequest.setDescription("会员充值"); wxPayRequest.setDescription("商城消费");
wxPayRequest.setOutTradeNo(storeOrder.getOrderId()); wxPayRequest.setOutTradeNo(storeOrder.getOrderId());
wxPayRequest.setNotifyUrl(payProperties.getNotifyUrl()); wxPayRequest.setNotifyUrl(payProperties.getNotifyUrl());
wxPayRequest.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(openid)); wxPayRequest.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(openid));
wxPayRequest.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(ip)); wxPayRequest.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(ip));
wxPayRequest.setAppid(payProperties.getAppId()); wxPayRequest.setAppid(payProperties.getAppId());
wxPayRequest.setMchid(payProperties.getMchId()); wxPayRequest.setMchid(payProperties.getMchId());
wxPayRequest.setTimeExpire(formatLocalDateTime(LocalDateTime.now().plusMinutes(30), "yyyyMMddHHmmss"));
try { try {
WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = wxPayService.unifiedOrderV3(TradeTypeEnum.JSAPI, wxPayRequest); WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = wxPayService.unifiedOrderV3(TradeTypeEnum.JSAPI, wxPayRequest);
map.put("mweb_url",wxPayUnifiedOrderV3Result.getH5Url()); map.put("mweb_url",wxPayUnifiedOrderV3Result.getH5Url());
@ -350,4 +354,8 @@ public class OrderPayServiceImpl implements OrderPayService {
} }
return map; return map;
} }
public static String formatLocalDateTime(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
} }