| | |
| | | import cn.binarywang.wx.miniapp.api.WxMaService; |
| | | import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
| | | import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.mybatis.SpringUtils; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.github.binarywang.wxpay.config.WxPayConfig; |
| | | import com.github.binarywang.wxpay.constant.WxPayConstants; |
| | | import com.github.binarywang.wxpay.service.WxPayService; |
| | |
| | | import com.wechat.pay.java.core.Config; |
| | | import com.wechat.pay.java.core.RSAAutoCertificateConfig; |
| | | import com.wechat.pay.java.core.RSAPublicKeyConfig; |
| | | import com.wechat.pay.java.core.http.HostName; |
| | | import com.wechat.pay.java.core.notification.NotificationParser; |
| | | import com.wechat.pay.java.core.notification.RSAPublicKeyNotificationConfig; |
| | | import com.wechat.pay.java.service.billdownload.BillDownloadService; |
| | | import com.wechat.pay.java.service.partnerpayments.jsapi.JsapiService; |
| | | import com.wechat.pay.java.service.partnerpayments.jsapi.JsapiServiceExtension; |
| | | import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; |
| | | import com.wechat.pay.java.service.refund.RefundService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | /** |
| | | * 微信小程序组件 |
| | | */ |
| | | @Slf4j |
| | | @Configuration |
| | | public class WxMiniConfig { |
| | | /********微信小程序服务**********/ |
| | | public static WxMaService wxMaService; |
| | | /********微信小程序支付**********/ |
| | | /********微信小程序支付 V2**********/ |
| | | public static WxPayService wxPayService; |
| | | /********微信APP支付**********/ |
| | | public static WxPayService wxAppPayService; |
| | | |
| | | /********微信支付 V3**********/ |
| | | public static JsapiServiceExtension v3JsapiService; |
| | | public static RefundService v3RefundService; |
| | | public static NotificationParser v3NotificationParser; |
| | | |
| | | @Autowired |
| | | private WxPayProperties wxPayProperties; |
| | |
| | | void init() { |
| | | this.load_WxMaService(); |
| | | this.load_wxPayService(); |
| | | this.load_wxPayV3Service(); |
| | | // this.load_wxAppPayService(); |
| | | } |
| | | /** |
| | |
| | | config.setAppid(StringUtils.trimToNull(wxPayProperties.getAppId())); |
| | | config.setSecret(StringUtils.trimToNull(wxPayProperties.getAppSecret())); |
| | | config.setMsgDataFormat("JSON"); |
| | | //config.setToken(""); |
| | | //config.setAesKey(""); |
| | | WxMaService wxMaService = new WxMaServiceImpl(); |
| | | wxMaService.setWxMaConfig(config); |
| | | this.wxMaService = wxMaService; |
| | | } |
| | | |
| | | /** |
| | | * 初始化微信小程序支付 |
| | | * 初始化微信小程序支付 V2 |
| | | */ |
| | | public void load_wxPayService() { |
| | | WxPayConfig payConfig = new WxPayConfig(); |
| | |
| | | this.wxPayService = wxPayService; |
| | | } |
| | | |
| | | /** |
| | | * 初始化微信支付 V3(JSAPI + 退款 + 回调验签) |
| | | */ |
| | | public void load_wxPayV3Service() { |
| | | try { |
| | | Config config = |
| | | new RSAPublicKeyConfig.Builder() |
| | | .merchantId(wxPayProperties.getMchId()) //微信支付的商户号 |
| | | .privateKeyFromPath(wxPayProperties.getPrivateKeyPath()) // 商户API证书私钥的存放路径 |
| | | .merchantSerialNumber(wxPayProperties.getSerialNumer()) //商户API证书序列号 |
| | | .publicKeyFromPath(wxPayProperties.getPubKeyPath()) //微信支付公钥的存放路径 |
| | | .publicKeyId(wxPayProperties.getPublicKeyId()) //微信支付公钥ID |
| | | .apiV3Key(wxPayProperties.getApiV3Key()) //APIv3密钥 |
| | | .build(); |
| | | |
| | | |
| | | // 支付公钥配置(用于回调验签) |
| | | RSAPublicKeyNotificationConfig notifyConfig = new RSAPublicKeyNotificationConfig.Builder() |
| | | .publicKeyFromPath(wxPayProperties.getPubKeyPath()) |
| | | .publicKeyId(wxPayProperties.getPublicKeyId()) |
| | | .apiV3Key(wxPayProperties.getApiV3Key()) |
| | | .build(); |
| | | |
| | | v3JsapiService = new JsapiServiceExtension.Builder().config(config).build(); |
| | | v3RefundService = new RefundService.Builder().config(config).build(); |
| | | v3NotificationParser = new NotificationParser(notifyConfig); |
| | | |
| | | log.info("微信支付V3初始化成功"); |
| | | } catch (Exception e) { |
| | | log.error("微信支付V3初始化失败: {}", e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | // /** |
| | | // * 初始化App支付 |
| | | // */ |