|
|
@@ -19,6 +19,7 @@ import com.wechat.pay.java.core.notification.NotificationConfig;
|
|
|
import com.wechat.pay.java.core.notification.NotificationParser;
|
|
|
import com.wechat.pay.java.core.notification.RequestParam;
|
|
|
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
|
|
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
@@ -26,7 +27,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
@@ -53,14 +53,17 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
public static Config config;
|
|
|
|
|
|
- @Autowired
|
|
|
- private WxPayConfig conf;
|
|
|
+ private final WxPayConfig conf;
|
|
|
|
|
|
- @Autowired
|
|
|
- private WalletDetailService walletDetailService;
|
|
|
+ private final WalletDetailService walletDetailService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private PayLogService payLogService;
|
|
|
+ private final PayLogService payLogService;
|
|
|
+
|
|
|
+ public WxPayServiceImpl(WxPayConfig conf, WalletDetailService walletDetailService, PayLogService payLogService) {
|
|
|
+ this.conf = conf;
|
|
|
+ this.walletDetailService = walletDetailService;
|
|
|
+ this.payLogService = payLogService;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 商户订单号查询订单
|
|
|
@@ -97,7 +100,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* JSAPI支付下单
|
|
|
*/
|
|
|
@Override
|
|
|
- public PrepayResponse prepay(JSONObject params) {
|
|
|
+ public PrepayWithRequestPaymentResponse wxPay(JSONObject params) {
|
|
|
if (!params.containsKey("amount") || params.getInteger("amount") == null || !(params.get("amount") instanceof Integer)) {
|
|
|
throw new BusinessException(ResponseEnum.WX_PAY_AMOUNT_ERROR);
|
|
|
}
|
|
|
@@ -118,7 +121,9 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
Payer payer = new Payer();
|
|
|
payer.setOpenid(openid);
|
|
|
request.setPayer(payer);
|
|
|
- return service.prepay(request);
|
|
|
+ JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
|
|
|
+ // response包含了调起支付所需的所有参数,可直接用于前端调起支付
|
|
|
+ return service.prepayWithRequestPayment(request);
|
|
|
}
|
|
|
|
|
|
/**
|