doum
4 小时以前 462a7c752afead89a100522aea8bbfadaea2aab9
server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java
@@ -10,6 +10,15 @@
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.core.RSAPublicKeyConfig;
import com.wechat.pay.java.core.http.HostName;
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.refund.RefundService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@@ -21,12 +30,18 @@
 */
@Configuration
public class WxMiniConfig {
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    /********微信小程序服务**********/
    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;
    public static  TransferToUser transferToUser;
    @Autowired
    private WxPayProperties wxPayProperties;
    public static WxMiniConfig me() {
        return SpringUtils.get().getBean(WxMiniConfig.class);
@@ -35,15 +50,24 @@
    @PostConstruct
    void init() {
        this.load_WxMaService();
//        this.load_wxPayService();
        this.load_wxPayService();
//        this.load_wxPayV2Service();
        this.load_transferToUser();
        this.wxProperties = wxPayProperties;
    }
    /**
     * 初始化微信小程序
     */
    public void load_WxMaService() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.WX_CONFIG,Constants.APPID).getCode()));
        config.setSecret(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.WX_CONFIG,Constants.SECRET).getCode()));
        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("");
@@ -51,6 +75,63 @@
        wxMaService.setWxMaConfig(config);
        this.wxMaService = wxMaService;
    }
    /**
     * 初始化微信小程序支付
     */
    public void load_wxPayService()   {
        try {
            Config config =
                    new RSAPublicKeyConfig.Builder()
                            .merchantId(wxPayProperties.getMchId())
                            .privateKeyFromPath(wxPayProperties.getPrivateKeyPath())
                            .publicKeyFromPath(wxPayProperties.getPubKeyPath())
                            .publicKeyId(wxPayProperties.getPayPublicKeyId())
                            .merchantSerialNumber(wxPayProperties.getSerialNumer())
                            .apiV3Key(wxPayProperties.getApiV3Key())
                            .build();
//            Config config =
//                    new RSAAutoCertificateConfig.Builder()
//                            .merchantId(wxPayProperties.getMchId())
//                            .privateKeyFromPath(wxPayProperties.getPrivateKeyPath())
////                            .publicKeyFromPath(wxPayProperties.getPubKeyPath())
////                            .publicKeyId("PUB_KEY_ID_0117000719222024112700219100000508")
//                            .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();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 初始化微信小程序支付
     */
//    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.setSubAppId(StringUtils.trimToNull(wxPayProperties.getSubAppId()));
//        payConfig.setMchId(StringUtils.trimToNull(wxPayProperties.getMchId()));
//        payConfig.setSubMchId(StringUtils.trimToNull(wxPayProperties.getSubMchId()));
//        payConfig.setMchKey(StringUtils.trimToNull(wxPayProperties.getMchKey()));
////        payConfig.setKeyPath(StringUtils.trimToNull(wxPayProperties.getKeyPath()));
//        payConfig.setNotifyUrl(StringUtils.trimToNull(wxPayProperties.getNotifyUrl()));
//        WxPayService wxPayService = new WxPayServiceImpl();
//        wxPayService.setConfig(payConfig);
//        this.wxPayV2Service = wxPayService;
//    }
    /**
     * 初始化微信小程序支付
@@ -70,7 +151,26 @@
//    }
    //转账业务
    public void load_transferToUser()
    {
        TransferToUser transferToUser = new TransferToUser(
                StringUtils.trimToNull(wxPayProperties.getSubMchId()), //商户id
                StringUtils.trimToNull(wxPayProperties.getWechatSerialNumer()), //商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053
                StringUtils.trimToNull(wxPayProperties.getWechatPrivateKeyPath()), // 商户API证书私钥文件路径,本地文件路径
                StringUtils.trimToNull(wxPayProperties.getWechatPayPublicKeyId()),   // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816
                StringUtils.trimToNull(wxPayProperties.getWechatPubKeyPath()) // 微信支付公钥文件路径,本地文件路径
        );
//        TransferToUser client = new TransferToUser(
//                "1229817002",                    // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756
//                "3FE90C2F3D40A56E1C51926F31B8A8D22426CCE0",         // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053
//                "d://wechatApiclient_key.pem",    // 商户API证书私钥文件路径,本地文件路径
//                "PUB_KEY_ID_0112298170022025071700291836000600",      // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816
//                "d://pub_key.pem"          // 微信支付公钥文件路径,本地文件路径
//        );
        this.transferToUser = transferToUser;
    }
}