| | |
| | | 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.github.binarywang.wxpay.config.WxPayConfig; |
| | | import com.github.binarywang.wxpay.constant.WxPayConstants; |
| | | import com.github.binarywang.wxpay.service.WxPayService; |
| | | import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; |
| | | import com.wechat.pay.java.core.Config; |
| | | import com.wechat.pay.java.core.RSAAutoCertificateConfig; |
| | | 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.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; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | |
| | | |
| | | /** |
| | | * 微信小程序组件 |
| | | */ |
| | | @Configuration |
| | | @Slf4j |
| | | public class WxMiniConfig { |
| | | /********微信小程序服务**********/ |
| | | public static WxMaService wxMaService; |
| | | /********微信小程序支付**********/ |
| | | public static WxPayService wxPayService; |
| | | |
| | | public static JsapiService wxPayService; |
| | | public static WxPayService wxPayV2Service; |
| | | public static RefundService refundService; |
| | | public static JsapiServiceExtension jsapiExtService; |
| | | public static BillDownloadService billDownloadService; |
| | | public static WxPayProperties wxProperties; |
| | | @Autowired |
| | | private WxPayProperties wxPayProperties; |
| | | |
| | |
| | | void init() { |
| | | this.load_WxMaService(); |
| | | this.load_wxPayService(); |
| | | this.load_wxPayV2Service(); |
| | | this.wxProperties = wxPayProperties; |
| | | } |
| | | /** |
| | | * 初始化微信小程序 |
| | | */ |
| | | public void load_WxMaService() { |
| | | WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); |
| | | if(wxPayProperties.getExistsSub() ==1){ |
| | | //如果是服务商支付,取子商户信息 |
| | | config.setAppid(StringUtils.trimToNull(wxPayProperties.getSubAppId())); |
| | | config.setSecret(StringUtils.trimToNull(wxPayProperties.getSubAppSecret())); |
| | | }else { |
| | | 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; |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 初始化微信小程序支付 |
| | | */ |
| | | public void load_wxPayService() { |
| | | public void load_wxPayService() |
| | | { |
| | | Config config = |
| | | new RSAAutoCertificateConfig.Builder() |
| | | .merchantId(wxPayProperties.getMchId()) |
| | | .privateKeyFromPath(wxPayProperties.getPrivateKeyPath()) |
| | | .merchantSerialNumber(wxPayProperties.getSerialNumer()) |
| | | .apiV3Key(wxPayProperties.getApiV3Key()) |
| | | .build(); |
| | | this.wxPayService = new JsapiService.Builder().config(config).build(); |
| | | |
| | | this.jsapiExtService = new JsapiServiceExtension.Builder().config(config).build(); |
| | | this.refundService = new RefundService.Builder().config(config).build(); |
| | | this.billDownloadService = new BillDownloadService.Builder().config(config).build();; |
| | | } |
| | | /** |
| | | * 初始化微信小程序支付 |
| | | */ |
| | | public void load_wxPayV2Service() |
| | | { |
| | | WxPayConfig payConfig = new WxPayConfig(); |
| | | payConfig.setTradeType(WxPayConstants.TradeType.JSAPI); |
| | | payConfig.setSignType(WxPayConstants.SignType.MD5); |
| | | payConfig.setAppId(StringUtils.trimToNull(wxPayProperties.getAppId())); |
| | | payConfig.setMchId(StringUtils.trimToNull(wxPayProperties.getMchId())); |
| | | payConfig.setMchKey(StringUtils.trimToNull(wxPayProperties.getMchKey())); |
| | | payConfig.setKeyPath(StringUtils.trimToNull(wxPayProperties.getKeyPath())); |
| | | payConfig.setAppId(StringUtils.trimToNull(wxPayProperties.getSubAppId())); |
| | | payConfig.setMchId(StringUtils.trimToNull(wxPayProperties.getSubMchId())); |
| | | payConfig.setMchKey(StringUtils.trimToNull(wxPayProperties.getSubMchKey())); |
| | | // payConfig.setKeyPath(StringUtils.trimToNull(wxPayProperties.getKeyPath())); |
| | | payConfig.setNotifyUrl(StringUtils.trimToNull(wxPayProperties.getNotifyUrl())); |
| | | WxPayService wxPayService = new WxPayServiceImpl(); |
| | | wxPayService.setConfig(payConfig); |
| | | this.wxPayService = wxPayService; |
| | | this.wxPayV2Service = wxPayService; |
| | | } |
| | | |
| | | |