jhprjv2/ruoyi-common/src/main/java/com/ruoyi/common/config/WechatMpConfig.java

55 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.ruoyi.common.config;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
/**
* Created by tao.
* Date: 2023/3/21 15:00
* 描述:
*/
@Component
public class WechatMpConfig {
@Autowired
private WechatAccountConfig accountConfig;
/**
* @author tao
* @date Created in 2021/3/12 10:15
* @param:
* @return WxMpService 对象
* 配置wxMpConfigStorage,返回 WxMpService 对象
*/
@Bean
public WxMpService wxMpService() {
WxMpService wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
return wxMpService;
}
/**
* @author tao
* @date Created in 2021/3/12 10:20
* @param:
* @return WxMpConfigStorage 对象
* 配置AppId、和AppSecret获取WxMpConfigStorage 对象
*/
@Bean
public WxMpConfigStorage wxMpConfigStorage() {
WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage();
wxMpConfigStorage.setAppId(accountConfig.getMpAppId());
wxMpConfigStorage.setSecret(accountConfig.getMpAppSecret());
wxMpConfigStorage.setToken(accountConfig.getMyToken());
wxMpConfigStorage.setAccessToken(accountConfig.getMyAccessToken());
return wxMpConfigStorage;
}
}