wechatpay-apiv3 / wechatpay-java

微信支付 APIv3 的官方 Java Library
Apache License 2.0
923 stars 206 forks source link

建议命名差异化、相同结构尽量使用同一个对象 #164

Open elylon1101 opened 1 year ago

elylon1101 commented 1 year ago

您的功能请求与问题有关吗? 请描述您遇到的问题

`import com.wechat.pay.java.core.RSAAutoCertificateConfig; import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; import com.wechat.pay.java.service.payments.nativepay.NativePayService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component;

@Component @RequiredArgsConstructor public class WxPayApi {

private final WxPayConfig wxPayConfig;

public com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse nativePay(String merchantId, Integer money, String appId, String description, String notifyUrl, String orderNo) {
    RSAAutoCertificateConfig config = wxPayConfig.getConfigByMerchantId(merchantId);
    NativePayService service = new NativePayService.Builder().config(config).build();
    com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest request = new com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest();
    com.wechat.pay.java.service.payments.nativepay.model.Amount amount = new com.wechat.pay.java.service.payments.nativepay.model.Amount();
    amount.setTotal(money);
    request.setAmount(amount);
    request.setAppid(appId);
    request.setMchid(merchantId);
    request.setDescription(description);
    request.setNotifyUrl(notifyUrl);
    request.setOutTradeNo(orderNo);
    return service.prepay(request);
}

public PrepayWithRequestPaymentResponse jsapiPay(String merchantId, Integer money, String appId, String description, String notifyUrl, String orderNo) {
    RSAAutoCertificateConfig config = wxPayConfig.getConfigByMerchantId(merchantId);
    JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
    com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest request = new com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest();
    com.wechat.pay.java.service.payments.jsapi.model.Amount amount = new com.wechat.pay.java.service.payments.jsapi.model.Amount();
    amount.setTotal(money);
    request.setAmount(amount);
    request.setAppid(appId);
    request.setMchid(merchantId);
    request.setDescription(description);
    request.setNotifyUrl(notifyUrl);
    request.setOutTradeNo(orderNo);
    return service.prepayWithRequestPayment(request);
}

}`

描述您想要的解决方案

我看过issues里面对于这个问题的回答,但是还是建议命名差异化。在现在的项目中同时支持多端口是很常见的需求,这就需要支持多种支付方式

  1. 命名差异化
  2. 一些相同结构的对象应该使用同一个对象,例:支付参数中的amount
  3. 当前sdk是java版本,在回调处理的时候应该提供一个基于HttpServletRequest的处理方法
  4. 希望请求参数类也支持build模式

您还有其他的方案吗?

No response

其他信息

No response