52 lines
1.5 KiB
Java
52 lines
1.5 KiB
Java
/**
|
|
* Copyright (C) 2018-2019
|
|
* All rights reserved, Designed By admin
|
|
* 注意:
|
|
*
|
|
*/
|
|
package com.starry.weichat.config;
|
|
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
/**
|
|
* 微信支付Configuration
|
|
*
|
|
* @author admin
|
|
*/
|
|
@Slf4j
|
|
@Configuration
|
|
public class WxPayConfiguration {
|
|
|
|
private static WxMaProperties wxMaProperties;
|
|
|
|
@Autowired
|
|
public WxPayConfiguration(WxMaProperties wxMaProperties) {
|
|
WxPayConfiguration.wxMaProperties = wxMaProperties;
|
|
}
|
|
|
|
/**
|
|
* 获取WxMpService
|
|
*
|
|
* @return
|
|
*/
|
|
public static WxPayService getPayService() {
|
|
WxPayService wxPayService = null;
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
payConfig.setAppId(wxMaProperties.getConfigs().get(0).getAppId());
|
|
payConfig.setMchId(wxMaProperties.getConfigs().get(0).getMchId());
|
|
payConfig.setMchKey(wxMaProperties.getConfigs().get(0).getMchKey());
|
|
payConfig.setKeyPath(wxMaProperties.getConfigs().get(0).getKeyPath());
|
|
// 可以指定是否使用沙箱环境
|
|
payConfig.setUseSandboxEnv(false);
|
|
wxPayService = new WxPayServiceImpl();
|
|
wxPayService.setConfig(payConfig);
|
|
return wxPayService;
|
|
}
|
|
|
|
}
|