mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-09-06 23:01:08 +08:00
调整微信工具
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package com.mdd.common.config.wechat;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.mdd.common.entity.system.SystemConfig;
|
||||
import com.mdd.common.mapper.system.SystemConfigMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author panweiliang
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(WxPayService.class)
|
||||
@AllArgsConstructor
|
||||
public class WxMnpConfiguration {
|
||||
|
||||
@Resource
|
||||
private final SystemConfigMapper systemConfigMapper;
|
||||
|
||||
/**
|
||||
* 微信小程序配置
|
||||
*
|
||||
* @author fzr
|
||||
* @return WxMaService
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WxMaService wxMnpService() {
|
||||
Map<String, String> config = this.getChannelConfig("mp_channel");
|
||||
|
||||
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
||||
wxConfig.setAppid(config.getOrDefault("appId", ""));
|
||||
wxConfig.setSecret(config.getOrDefault("appSecret", ""));
|
||||
|
||||
WxMaService wxService = new WxMaServiceImpl();
|
||||
wxService.setWxMaConfig(wxConfig);
|
||||
return wxService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号配置
|
||||
*
|
||||
* @author zr
|
||||
* @return WxMpService
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WxMpService wxOaService() {
|
||||
Map<String, String> config = this.getChannelConfig("oa_channel");
|
||||
|
||||
WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
|
||||
wxMpDefaultConfig.setAppId(config.getOrDefault("appId", "").trim());
|
||||
wxMpDefaultConfig.setSecret(config.getOrDefault("appSecret", "").trim());
|
||||
wxMpDefaultConfig.setToken(config.getOrDefault("token", "").trim());
|
||||
wxMpDefaultConfig.setAesKey(config.getOrDefault("encodingAesKey", "").trim());
|
||||
|
||||
WxMpService wxService = new WxMpServiceImpl();
|
||||
wxService.setWxMpConfigStorage(wxMpDefaultConfig);
|
||||
return wxService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置读取
|
||||
*
|
||||
* @author fzr
|
||||
* @param type 类型
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
private Map<String, String> getChannelConfig(String type) {
|
||||
List<SystemConfig> configs = systemConfigMapper.selectList(
|
||||
new QueryWrapper<SystemConfig>()
|
||||
.select("id", "type", "name", "value")
|
||||
.eq("type", type));
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
for (SystemConfig config : configs) {
|
||||
map.put(config.getName(), config.getValue());
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,41 @@
|
||||
package com.mdd.common.util;
|
||||
package com.mdd.common.plugin.wechat;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
public class WeChatUtils {
|
||||
/**
|
||||
* 微信基础驱动
|
||||
*/
|
||||
@Component
|
||||
public class WxMnpDriver {
|
||||
|
||||
private static WxMaService wxMaService;
|
||||
|
||||
private static WxMpService wxMpService;
|
||||
|
||||
/**
|
||||
* 微信小程序依赖注入
|
||||
*/
|
||||
@Resource
|
||||
public void setWxMaService(WxMaService wxMaService) {
|
||||
WxMnpDriver.wxMaService = wxMaService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号依赖注入
|
||||
*/
|
||||
@Resource
|
||||
public void setWxOaService(WxMpService wxMpService) {
|
||||
WxMnpDriver.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信小程序
|
||||
@@ -20,14 +46,13 @@ public class WeChatUtils {
|
||||
public static WxMaService mnp() {
|
||||
Map<String, String> config = ConfigUtils.get("mp_channel");
|
||||
|
||||
WxMaService service = new WxMaServiceImpl();
|
||||
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
||||
wxConfig.setAppid(config.getOrDefault("appId", ""));
|
||||
wxConfig.setSecret(config.getOrDefault("appSecret", ""));
|
||||
service.setWxMaConfig(wxConfig);
|
||||
return service;
|
||||
}
|
||||
wxMaService.setWxMaConfig(wxConfig);
|
||||
|
||||
return wxMaService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号
|
||||
@@ -35,7 +60,7 @@ public class WeChatUtils {
|
||||
* @author fzr
|
||||
* @return WxMpService
|
||||
*/
|
||||
public static WxMpService official() {
|
||||
public static WxMpService oa() {
|
||||
Map<String, String> config = ConfigUtils.get("oa_channel");
|
||||
|
||||
WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
|
||||
@@ -43,10 +68,8 @@ public class WeChatUtils {
|
||||
wxMpDefaultConfig.setSecret(config.getOrDefault("appSecret", "").trim());
|
||||
wxMpDefaultConfig.setToken(config.getOrDefault("token", "").trim());
|
||||
wxMpDefaultConfig.setAesKey(config.getOrDefault("encodingAesKey", "").trim());
|
||||
wxMpService.setWxMpConfigStorage(wxMpDefaultConfig);
|
||||
|
||||
WxMpService service = new WxMpServiceImpl();
|
||||
service.setWxMpConfigStorage(wxMpDefaultConfig);
|
||||
return service;
|
||||
return wxMpService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,9 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信支付驱动
|
||||
*/
|
||||
@Component
|
||||
public class WxPayDriver {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user