java 接入微信支付支付宝支付

本文介绍了如何在Java项目中集成微信和支付宝支付功能,包括配置pom.xml、application-dev.yml文件,设置支付宝和微信的账户实体类,支付配置以及支付控制器的实现,最后提到了查询控制器的作用。
摘要由CSDN通过智能技术生成

导入pom.xml 文件中的

      <dependency>
            <groupId>cn.springboot</groupId>
            <artifactId>best-pay-sdk</artifactId>
            <version>${
   best-pay-sdk.version}</version>
        </dependency>

application-dev.yml

#微信
wechat:
  mpAppId: # 公众号APPID
  mchId: # 商户号
  mchKey: # 商户密钥
  keyPath: /var/weixin_cert/wxpay.p12 # 密钥路径
  notifyUrl: https://www.baidu.com/   #通知路径 ,我这里应用的是百度做的测试,这里要修改成自己的通知路径
  miniAppId: # 小程序APPID
  miniAppSecret: #小程序密钥
  appAppId: #移动app的APPID
#  profit_sharing:  Y 是否分帐
# 支付宝
alipay: 
  appId:  # 阿里的appId,也就是支付宝app的AppId
  privateKey:  # 私钥,采用支付宝提供的密钥工具去生成的
  aliPayPublicKey: # 公钥,采用支付宝提供的密钥工具去生成的
  notifyUrl:  # 通知路径
  returnUrl: # 返回路径
  sandbox: false # 是否使用沙箱

支付宝账户配置(实体类)

@Data
@ConfigurationProperties(prefix = "alipay")
@Component
public class AliPayAccountConfig {
   
    /**
     * appId
     */
    private String appId;
    /**
     * 商户私钥
     */
    private String privateKey;
    /**
     * 支付宝公钥
     */
    private String aliPayPublicKey;
    /**
     * 异步通知url
     */
    private String notifyUrl;

    /**
     * 同步返回的url
     */
    private String returnUrl;

    /**
     * 是否使用沙箱
     */
    private Boolean sandbox;
}

微信帐号配置

public class WechatAccountConfig {
   
    /**
     * 公众账号appid
     * 获取地址 https://mp.weixin.qq.com
     */
    private String mpAppId;

    /**
     * 小程序appId
     * 获取地址 https://mp.weixin.qq.com
     */
    private String miniAppId;

    /**
     * 小程序appSecret
     */
    private String miniAppSecret;

    /**
     * 商户号
     * 获取地址 https://pay.weixin.qq.com
     */
    private String mchId;


    /**
     * 商户密钥
     */
    private String mchKey;

    /**
     * 商户证书路径
     */
    private String keyPath;

    /**
     * 微信支付异步通知地址
     */
    private String notifyUrl;

    /**
     * app应用appid
     * 获取地址 https://open.weixin.qq.com
     */
    private String appAppId;
}

支付配置

public class PayConfig {
   

    @Autowired
    private WechatAccountConfig accountConfig;

    @Autowired
    private AliPayAccountConfig aliPayAccountConfig;

    @Bean
    public WxPayConfig wxPayConfig() {
   
        WxPayConfig wxPayConfig = new WxPayConfig();
        wxPayConfig.setAppId(accountConfig.getMpAppId());
        wxPayConfig.setMiniAppId(accountConfig.getMiniAppId());
        wxPayConfig.setMchId(accountConfig.getMchId());
        wxPayConfig.setMchKey(accountConfig.getMchKey());
        wxPayConfig.setKeyPath(accountConfig.getKeyPath());
        wxPayConfig.setNotifyUrl(accountConfig.getNotifyUrl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值