导入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