56 lines
1.4 KiB
Java
56 lines
1.4 KiB
Java
|
|
package com.whdc.common.config;
|
||
|
|
|
||
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||
|
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||
|
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||
|
|
import lombok.Data;
|
||
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||
|
|
import org.springframework.context.annotation.Bean;
|
||
|
|
import org.springframework.context.annotation.Configuration;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Description:
|
||
|
|
* Created by XuSan on 2024/6/3.
|
||
|
|
* 微信小程序 配置
|
||
|
|
*
|
||
|
|
* @author XuSan
|
||
|
|
* @version 1.0
|
||
|
|
*/
|
||
|
|
@Data
|
||
|
|
@Configuration
|
||
|
|
@ConditionalOnClass(WxMaService.class)
|
||
|
|
@ConfigurationProperties(prefix = "wx.miniapp.configs")
|
||
|
|
public class WxMiniappConfiguration {
|
||
|
|
/**
|
||
|
|
* 设置微信小程序的appId
|
||
|
|
*/
|
||
|
|
|
||
|
|
private String appId;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 设置微信小程序的Secret
|
||
|
|
*/
|
||
|
|
|
||
|
|
private String secret;
|
||
|
|
|
||
|
|
@Bean
|
||
|
|
@ConditionalOnMissingBean(WxMaService.class)
|
||
|
|
public WxMaService wxMaService() {
|
||
|
|
|
||
|
|
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||
|
|
|
||
|
|
config.setAppid(this.getAppId());
|
||
|
|
|
||
|
|
config.setSecret(this.getSecret());
|
||
|
|
|
||
|
|
WxMaService service = new WxMaServiceImpl();
|
||
|
|
|
||
|
|
service.setWxMaConfig(config);
|
||
|
|
|
||
|
|
return service;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|