<dependency> <groupId>cn.springboot</groupId> <artifactId>best-pay-sdk</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
wechat: # 公众账号, 授权 mpAppId: wxd898fcb01713c658 mpAppSecret: # 开放平台, 卖家扫码登录用 openAppId: wx6ad144e54af67d87 openAppSecret: 91a2ff6d38a2bbccfb7e9xxxxxx # 支付/商户号 mchId: 1483469312 mchKey: 06C56A89949D617xxxxxxxxxxx # 发起支付不需要证书, 退款需要 keyPath: notifyUrl: http://sell.natapp4.cc/sell/pay/notify templateId: orderStatus: e-Cqq67QxD6YNI41iRiqawEYdFavW_7pc7LyEMb-yeQ
package com.imooc.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import java.util.Map; @Data @Component @ConfigurationProperties(prefix = "wechat") public class WechatAccountConfig { /** * 公众平台id */ private String mpAppId; /** * 公众平台密钥 */ private String mpAppSecret; /** * 开放平台id */ private String openAppId; /** * 开放平台密钥 */ private String openAppSecret; /** * 商户号 */ private String mchId; /** * 商户密钥 */ private String mchKey; /** * 商户证书路径 */ private String keyPath; /** * 微信支付异步通知地址 */ private String notifyUrl; /** * 微信模版id */ private Map<String, String> templateId; }
package com.imooc.config; import com.lly835.bestpay.config.WxPayH5Config; import com.lly835.bestpay.service.impl.BestPayServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; @Component public class WechatPayConfig { @Autowired private WechatAccountConfig accountConfig; @Bean public BestPayServiceImpl bestPayService() { BestPayServiceImpl bestPayService = new BestPayServiceImpl(); bestPayService.setWxPayH5Config(wxPayH5Config()); return bestPayService; } @Bean public WxPayH5Config wxPayH5Config() { WxPayH5Config wxPayH5Config = new WxPayH5Config(); wxPayH5Config.setAppId(accountConfig.getMpAppId()); wxPayH5Config.setAppSecret(accountConfig.getMpAppSecret()); wxPayH5Config.setMchId(accountConfig.getMchId()); wxPayH5Config.setMchKey(accountConfig.getMchKey()); wxPayH5Config.setKeyPath(accountConfig.getKeyPath()); wxPayH5Config.setNotifyUrl(accountConfig.getNotifyUrl()); return wxPayH5Config; } }