【微信支付-服务商】SpringBoot集成微信服务商支付(多子商户集成)

前言

在网上搜了很多,都没有说如何对接微信支付-服务商。于是参考官方代码示例琢磨了一个版本

微信官方api文档网站:https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/partner-mini-prepay.html

官方示例demo:https://github.com/wechatpay-apiv3/wechatpay-java

一、前置工作

1、获取商户平台的xxx核心参数

商户号(merchantId)、秘钥(apiV3Key)、商户证书(apiclient_key.pem)、证书序列号(merchantSerialNumber)
在这里插入图片描述

2、关联对应的小程序(appid)

在这里插入图片描述

二、SpringBoot集成微信小程序

1、引入pom依赖

        <!-- 微信支付 -->
        <dependency>
            <groupId>com.github.wechatpay-apiv3</groupId>
            <artifactId>wechatpay-java</artifactId>
            <version>0.2.12</version>
        </dependency>

2、yml配置


pay:
  # 所关联小程序id
  appId: wxaxxxxxxxxxxxxxxx
  merchantId: 1xxxxxxxx5
  merchantSerialNumber: xxxxxxxxxx
  apiV3Key: xxxxxxxxx
  #支付成功回调地址
  notifyUrl: https://xxxxxx 
  # 商户平台私钥证书路径
  privateKeyPath: /xxxxxx/apiclient_key.pem

商户号(merchantId)、秘钥(apiV3Key)、商户证书(apiclient_key.pem)、证书序列号(merchantSerialNumber)

3、java代码文件

3.1、Properties 配置类


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Data
@ConfigurationProperties(prefix = "pay")
public class WxPayServiceProperties {
   

    private String appId;
    private String merchantId;
    private String merchantSerialNumber;
    private String apiV3Key;
    private String notifyUrl;
    private String privateKeyPath;

}




3.2 Configuration 服务类


import com.alibaba.fastjson.JSONObject;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.util.PemUtil;
import com.wechat.pay.java.service.partnerpayments.jsapi.JsapiService;
import com.wechat.pay.java.service.refund.RefundService;
import com.wechat.pay.java.service.refund.RefundService.Builder;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxRuntimeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import javax.annotation.PostConstruct;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.Signature;
import java.util.Base64;

/**
 * @author tm
 * date 2023/5/15
 * @version 1.0
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(WxPayServiceProperties.class)
public class WxPayServiceConfiguration {
   

    private final WxPayServiceProperties properties;

    public static JsapiService service;

    private static String privateKeyPath;

    public static RefundService refundService;

    @Autowired
    public WxPayServiceConfiguration(WxPayServiceProperties properties) {
   
        this.properties = properties;
    }

    @PostConstruct
    public void init() {
   
        WxPayServiceProperties properties = this.properties
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值