spring boot 微信 支付宝 集成 开源jm-pay sdk

微信和支付宝集成封装的sdk 需要自己拉代码到本地进行打包

https://github.com/sunuping/jm-pay.git

pom.xml

		
		<dependency>
            <groupId>com.alipay.sdkgroupId>
            <artifactId>alipay-sdk-javaartifactId>
            <version>4.34.0.ALLversion>
        dependency>
        
        <dependency>
            <groupId>com.github.wechatpay-apiv3groupId>
            <artifactId>wechatpay-javaartifactId>
            <version>0.2.4version>
        dependency>
        
        <dependency>
            <groupId>org.jmgroupId>
            <artifactId>jm-payartifactId>
            <version>2.6version>
        dependency>

application.yml 配置支付宝和微信支付配置

jm:
  ali:
    appid: xxx
    rsa-privateKey: xxx
    notify-url: https://xxx/pay/callback
    return-url: https://xxx
    gateway-url: https://openapi.alipay.com/gateway.do
    charset: UTF-8
    format: json
    alipay-publicKey: xxx
    sign-type: RSA2
  wx:
    api-v3-key: xxx
    private-key-path: E:\xxxx\apiclient_key.pem
    private-key: xxxx
    mch-id: xxx
    appid: xxx
    mch-serial-number: xxx
    notify-url: https://xxxx/pay/callback

调用支付

package org.jm.pay.constant;

/**
 * @author kong
 */
public class JmAlipayTypeConstant {
    /**
     * 支付宝h5支付
     */
    public static final String ALIPAY_H5 = "alipay_h5";
    /**
     * 支付宝pc支付
     */
    public static final String ALIPAY_PC = "alipay_pc";
    /**
     * 支付宝app支付
     */
    public static final String ALIPAY_APP = "alipay_app";
}

package org.jm.pay.constant;

/**
 * @author kong
 */
public class JmWxPayTypeConstant {
    /**
     * 微信h5支付
     */
    public static final String WX_H5 = "wx_h5";
    /**
     * 微信pc支付
     */
    public static final String WX_PC = "wx_pc";
    /**
     * 微信native支付
     */
    public static final String WX_NATIVE = "wx_native";
}



  	private final JmAlipayPc jmAlipayPc;
    private final JmAlipayH5 jmAlipayH5;
    private final JmWxPayNative jmWxPayNative;
    private final JmWxPayH5 jmWxPayH5;
    
    @Autowired
    public PayServiceImpl(JmAlipayPc jmAlipayPc, JmAlipayH5 jmAlipayH5, JmWxPayNative jmWxPayNative, JmWxPayH5 jmWxPayH5) {
        this.jmAlipayPc = jmAlipayPc;
        this.jmAlipayH5 = jmAlipayH5;
        this.jmWxPayNative = jmWxPayNative;
        this.jmWxPayH5 = jmWxPayH5;
    }

支付参数


 JmPayParam jmPayParam = new JmPayParam();
        jmPayParam.setOrderNo("订单编号");
        jmPayParam.setOrderName("订单名称");
        jmPayParam.setDesc("订单描述");
        //订单金额
        jmPayParam.setAmount(param.getAmount());

调用支付

    private JmPayVO pay(JmPayParam param, String type) {
        switch (type) {
            case JmAlipayTypeConstant.ALIPAY_H5:
                return this.jmAlipayH5.pay(param);
            case JmAlipayTypeConstant.ALIPAY_PC:
                return this.jmAlipayPc.pay(param);
            case JmWxPayTypeConstant.WX_H5:
                return this.jmWxPayH5.pay(param);
            case JmWxPayTypeConstant.WX_NATIVE:
                return this.jmWxPayNative.pay(param);
            default:
                throw new ErrorException("支付异常");
        }
    }

支付结果

        JmPayVO payVO = this.pay(jmPayParam,param.getPayType());

你可能感兴趣的:(java,开发语言)