From 364bcfcfbd270fefcc64f8fff01c23b67ae29e7e Mon Sep 17 00:00:00 2001 From: 3y Date: Tue, 31 Jan 2023 20:17:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=9C=8D=E5=8A=A1=E5=8F=B7?= =?UTF-8?q?=E5=92=8C=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=9A=84access=5Ftoken?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E8=87=B3Redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/SendAccountConstant.java | 10 ++ .../impl/MiniProgramAccountHandler.java | 10 +- .../handler/impl/OfficialAccountHandler.java | 6 +- .../austin/support/domain/ChannelAccount.java | 6 +- .../support/exception/ProcessException.java | 4 +- .../austin/support/utils/AccountUtils.java | 81 ++++++++++++- .../austin/support/utils/WxServiceUtils.java | 113 ------------------ .../austin/web/config/WeChatLoginConfig.java | 6 +- .../web/controller/MiniProgramController.java | 18 +-- .../controller/OfficialAccountController.java | 12 +- .../impl/ChannelAccountServiceImpl.java | 7 +- 11 files changed, 119 insertions(+), 154 deletions(-) delete mode 100644 austin-support/src/main/java/com/java3y/austin/support/utils/WxServiceUtils.java diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java index ae4b000..c881f00 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java +++ b/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java @@ -18,5 +18,15 @@ public class SendAccountConstant { */ public static final String GE_TUI_ACCESS_TOKEN_PREFIX = "ge_tui_access_token_"; + /** + * 微信服务号 + */ + public static final String OFFICIAL_ACCOUNT_ACCESS_TOKEN_PREFIX = "official_account"; + + /** + * 微信小程序 + */ + public static final String MINI_PROGRAM_TOKEN_PREFIX = "mini_program"; + } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/MiniProgramAccountHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/MiniProgramAccountHandler.java index caa4430..e754286 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/MiniProgramAccountHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/MiniProgramAccountHandler.java @@ -1,6 +1,6 @@ package com.java3y.austin.handler.handler.impl; -import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; +import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; @@ -10,7 +10,7 @@ import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.Handler; import com.java3y.austin.support.domain.MessageTemplate; -import com.java3y.austin.support.utils.WxServiceUtils; +import com.java3y.austin.support.utils.AccountUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -28,7 +28,7 @@ import java.util.Set; @Slf4j public class MiniProgramAccountHandler extends BaseHandler implements Handler { @Autowired - private WxServiceUtils wxServiceUtils; + private AccountUtils accountUtils; public MiniProgramAccountHandler() { channelCode = ChannelType.MINI_PROGRAM.getCode(); @@ -37,11 +37,11 @@ public class MiniProgramAccountHandler extends BaseHandler implements Handler { @Override public boolean handler(TaskInfo taskInfo) { MiniProgramContentModel contentModel = (MiniProgramContentModel) taskInfo.getContentModel(); - WxMaSubscribeService wxMaSubscribeService = wxServiceUtils.getMiniProgramServiceMap().get(taskInfo.getSendAccount().longValue()); + WxMaService wxMaService = accountUtils.getAccountById(taskInfo.getSendAccount(), WxMaService.class); List wxMaSubscribeMessages = assembleReq(taskInfo.getReceiver(), contentModel); for (WxMaSubscribeMessage message : wxMaSubscribeMessages) { try { - wxMaSubscribeService.sendSubscribeMsg(message); + wxMaService.getSubscribeService().sendSubscribeMsg(message); } catch (Exception e) { log.info("MiniProgramAccountHandler#handler fail! param:{},e:{}", JSON.toJSONString(taskInfo), Throwables.getStackTraceAsString(e)); } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/OfficialAccountHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/OfficialAccountHandler.java index 1030b3e..79461fb 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/OfficialAccountHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/OfficialAccountHandler.java @@ -8,7 +8,7 @@ import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.Handler; import com.java3y.austin.support.domain.MessageTemplate; -import com.java3y.austin.support.utils.WxServiceUtils; +import com.java3y.austin.support.utils.AccountUtils; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; @@ -30,7 +30,7 @@ import java.util.Set; public class OfficialAccountHandler extends BaseHandler implements Handler { @Autowired - private WxServiceUtils wxServiceUtils; + private AccountUtils accountUtils; public OfficialAccountHandler() { channelCode = ChannelType.OFFICIAL_ACCOUNT.getCode(); @@ -40,7 +40,7 @@ public class OfficialAccountHandler extends BaseHandler implements Handler { public boolean handler(TaskInfo taskInfo) { try { OfficialAccountsContentModel contentModel = (OfficialAccountsContentModel) taskInfo.getContentModel(); - WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(taskInfo.getSendAccount().longValue()); + WxMpService wxMpService = accountUtils.getAccountById(taskInfo.getSendAccount(), WxMpService.class); List messages = assembleReq(taskInfo.getReceiver(), contentModel); for (WxMpTemplateMessage message : messages) { try { diff --git a/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java b/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java index 9f92d0e..be0047e 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java +++ b/austin-support/src/main/java/com/java3y/austin/support/domain/ChannelAccount.java @@ -1,9 +1,6 @@ package com.java3y.austin.support.domain; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -19,6 +16,7 @@ import javax.persistence.Id; @NoArgsConstructor @AllArgsConstructor @Entity +@ToString public class ChannelAccount { @Id diff --git a/austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java b/austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java index 327b0b9..3d56d47 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java +++ b/austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java @@ -30,9 +30,9 @@ public class ProcessException extends RuntimeException { public String getMessage() { if (Objects.nonNull(this.processContext)) { return this.processContext.getResponse().getMsg(); - } else { - return RespStatusEnum.CONTEXT_IS_NULL.getMsg(); } + return RespStatusEnum.CONTEXT_IS_NULL.getMsg(); + } public ProcessContext getProcessContext() { diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java index 5758b2f..cf616f6 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java @@ -1,38 +1,80 @@ package com.java3y.austin.support.utils; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; +import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; import com.java3y.austin.common.constant.CommonConstant; +import com.java3y.austin.common.constant.SendAccountConstant; +import com.java3y.austin.common.dto.account.WeChatMiniProgramAccount; +import com.java3y.austin.common.dto.account.WeChatOfficialAccount; import com.java3y.austin.common.dto.account.sms.SmsAccount; import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.support.dao.ChannelAccountDao; import com.java3y.austin.support.domain.ChannelAccount; import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; +import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.core.StringRedisTemplate; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; /** * 获取账号信息工具类 * * @author 3y */ -@Component @Slf4j +@Configuration public class AccountUtils { @Autowired private ChannelAccountDao channelAccountDao; + @Autowired + private StringRedisTemplate redisTemplate; + /** + * 消息的小程序/微信服务号账号 + */ + private Map officialAccountServiceMap = new ConcurrentHashMap<>(); + private Map miniProgramServiceMap = new ConcurrentHashMap<>(); + @Bean + public RedisTemplateWxRedisOps redisTemplateWxRedisOps() { + return new RedisTemplateWxRedisOps(redisTemplate); + } + + /** + * 微信小程序:返回 WxMaService + * 微信服务号:返回 WxMpService + * 其他渠道:返回XXXAccount账号对象 + * + * @param sendAccountId + * @param clazz + * @param + * @return + */ public T getAccountById(Integer sendAccountId, Class clazz) { try { Optional optionalChannelAccount = channelAccountDao.findById(Long.valueOf(sendAccountId)); if (optionalChannelAccount.isPresent()) { ChannelAccount channelAccount = optionalChannelAccount.get(); - return JSON.parseObject(channelAccount.getAccountConfig(), clazz); + if (clazz.equals(WxMaService.class)) { + return (T) miniProgramServiceMap.computeIfAbsent(channelAccount, account -> initMiniProgramService(JSON.parseObject(account.getAccountConfig(), WeChatMiniProgramAccount.class))); + } else if (clazz.equals(WxMpService.class)) { + return (T) officialAccountServiceMap.computeIfAbsent(channelAccount, account -> initOfficialAccountService(JSON.parseObject(account.getAccountConfig(), WeChatOfficialAccount.class))); + } else { + return JSON.parseObject(channelAccount.getAccountConfig(), clazz); + } } } catch (Exception e) { log.error("AccountUtils#getAccount fail! e:{}", Throwables.getStackTraceAsString(e)); @@ -68,4 +110,37 @@ public class AccountUtils { return null; } + /** + * 初始化微信服务号 + * access_token 用redis存储 + * + * @return + */ + public WxMpService initOfficialAccountService(WeChatOfficialAccount officialAccount) { + WxMpService wxMpService = new WxMpServiceImpl(); + WxMpRedisConfigImpl config = new WxMpRedisConfigImpl(redisTemplateWxRedisOps(), SendAccountConstant.OFFICIAL_ACCOUNT_ACCESS_TOKEN_PREFIX); + config.setAppId(officialAccount.getAppId()); + config.setSecret(officialAccount.getSecret()); + config.setToken(officialAccount.getToken()); + wxMpService.setWxMpConfigStorage(config); + return wxMpService; + } + + /** + * 初始化微信小程序 + * access_token 用redis存储 + * + * @return + */ + private WxMaService initMiniProgramService(WeChatMiniProgramAccount miniProgramAccount) { + WxMaService wxMaService = new WxMaServiceImpl(); + WxMaRedisBetterConfigImpl config = new WxMaRedisBetterConfigImpl(redisTemplateWxRedisOps(), SendAccountConstant.MINI_PROGRAM_TOKEN_PREFIX); + config.setAppid(miniProgramAccount.getAppId()); + config.setSecret(miniProgramAccount.getAppSecret()); + wxMaService.setWxMaConfig(config); + return wxMaService; + } + + + } diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/WxServiceUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/WxServiceUtils.java deleted file mode 100644 index 0cb271a..0000000 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/WxServiceUtils.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.java3y.austin.support.utils; - - -import cn.binarywang.wx.miniapp.api.WxMaService; -import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; -import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; -import cn.binarywang.wx.miniapp.api.impl.WxMaSubscribeServiceImpl; -import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; -import com.alibaba.fastjson.JSON; -import com.java3y.austin.common.constant.CommonConstant; -import com.java3y.austin.common.dto.account.WeChatMiniProgramAccount; -import com.java3y.austin.common.dto.account.WeChatOfficialAccount; -import com.java3y.austin.common.enums.ChannelType; -import com.java3y.austin.support.dao.ChannelAccountDao; -import com.java3y.austin.support.domain.ChannelAccount; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -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.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 微信服务号/微信小程序 服务初始化工具类 - * - * @author 3y - */ -@Component -@Slf4j -@Data -public class WxServiceUtils { - - /** - * 推送消息的小程序/微信服务号 账号 - */ - private Map officialAccountServiceMap = new ConcurrentHashMap<>(); - private Map miniProgramServiceMap = new ConcurrentHashMap<>(); - - @Autowired - private ChannelAccountDao channelAccountDao; - - @PostConstruct - public void init() { - initOfficialAccount(); - initMiniProgram(); - } - - - /** - * 当账号存在变更/新增时,刷新Map - */ - public void fresh() { - init(); - } - - /** - * 得到所有的小程序账号 - */ - private void initMiniProgram() { - List miniProgram = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.MINI_PROGRAM.getCode()); - for (ChannelAccount channelAccount : miniProgram) { - WeChatMiniProgramAccount weChatMiniProgramAccount = JSON.parseObject(channelAccount.getAccountConfig(), WeChatMiniProgramAccount.class); - miniProgramServiceMap.put(channelAccount.getId(), initMiniProgramService(weChatMiniProgramAccount)); - } - } - - /** - * 得到所有的微信服务号账号 - */ - private void initOfficialAccount() { - List officialAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.OFFICIAL_ACCOUNT.getCode()); - for (ChannelAccount channelAccount : officialAccountList) { - WeChatOfficialAccount weChatOfficialAccount = JSON.parseObject(channelAccount.getAccountConfig(), WeChatOfficialAccount.class); - officialAccountServiceMap.put(channelAccount.getId(), initOfficialAccountService(weChatOfficialAccount)); - } - - } - - /** - * 初始化微信服务号 - * - * @return - */ - public WxMpService initOfficialAccountService(WeChatOfficialAccount officialAccount) { - WxMpService wxMpService = new WxMpServiceImpl(); - WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); - config.setAppId(officialAccount.getAppId()); - config.setSecret(officialAccount.getSecret()); - config.setToken(officialAccount.getToken()); - wxMpService.setWxMpConfigStorage(config); - return wxMpService; - } - - /** - * 初始化微信小程序 - * - * @return - */ - private WxMaSubscribeServiceImpl initMiniProgramService(WeChatMiniProgramAccount miniProgramAccount) { - WxMaService wxMaService = new WxMaServiceImpl(); - WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl(); - wxMaConfig.setAppid(miniProgramAccount.getAppId()); - wxMaConfig.setSecret(miniProgramAccount.getAppSecret()); - wxMaService.setWxMaConfig(wxMaConfig); - return new WxMaSubscribeServiceImpl(wxMaService); - } -} diff --git a/austin-web/src/main/java/com/java3y/austin/web/config/WeChatLoginConfig.java b/austin-web/src/main/java/com/java3y/austin/web/config/WeChatLoginConfig.java index 01056bd..d44fd2f 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/config/WeChatLoginConfig.java +++ b/austin-web/src/main/java/com/java3y/austin/web/config/WeChatLoginConfig.java @@ -2,7 +2,7 @@ package com.java3y.austin.web.config; import com.java3y.austin.common.constant.OfficialAccountParamConstant; import com.java3y.austin.common.dto.account.WeChatOfficialAccount; -import com.java3y.austin.support.utils.WxServiceUtils; +import com.java3y.austin.support.utils.AccountUtils; import lombok.Data; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.api.WxMpMessageHandler; @@ -39,7 +39,7 @@ public class WeChatLoginConfig { private String token; @Autowired - private WxServiceUtils wxServiceUtils; + private AccountUtils accountUtils; /** * 微信服务号 登录 相关对象 @@ -55,7 +55,7 @@ public class WeChatLoginConfig { @PostConstruct private void init() { WeChatOfficialAccount account = WeChatOfficialAccount.builder().appId(appId).secret(secret).token(token).build(); - officialAccountLoginService = wxServiceUtils.initOfficialAccountService(account); + officialAccountLoginService = accountUtils.initOfficialAccountService(account); initConfig(); initRouter(); } diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/MiniProgramController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/MiniProgramController.java index c5ac85e..800763d 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/MiniProgramController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/MiniProgramController.java @@ -1,12 +1,12 @@ package com.java3y.austin.web.controller; -import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; +import cn.binarywang.wx.miniapp.api.WxMaService; import cn.hutool.http.HttpUtil; import com.google.common.base.Throwables; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; -import com.java3y.austin.support.utils.WxServiceUtils; +import com.java3y.austin.support.utils.AccountUtils; import com.java3y.austin.web.utils.Convert4Amis; import com.java3y.austin.web.vo.amis.CommonAmisVo; import io.swagger.annotations.Api; @@ -35,15 +35,15 @@ import java.util.Objects; public class MiniProgramController { @Autowired - private WxServiceUtils wxServiceUtils; + private AccountUtils accountUtils; @GetMapping("/template/list") @ApiOperation("/根据账号Id获取模板列表") - public BasicResultVO queryList(Long id) { + public BasicResultVO queryList(Integer id) { try { List result = new ArrayList<>(); - WxMaSubscribeService wxMaSubscribeService = wxServiceUtils.getMiniProgramServiceMap().get(id); - List templateList = wxMaSubscribeService.getTemplateList(); + WxMaService wxMaService = accountUtils.getAccountById(id, WxMaService.class); + List templateList = wxMaService.getSubscribeService().getTemplateList(); for (TemplateInfo templateInfo : templateList) { CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(templateInfo.getTitle()).value(templateInfo.getPriTmplId()).build(); result.add(commonAmisVo); @@ -63,13 +63,13 @@ public class MiniProgramController { */ @PostMapping("/detailTemplate") @ApiOperation("/根据账号Id和模板ID获取模板列表") - public BasicResultVO queryDetailList(Long id, String wxTemplateId) { + public BasicResultVO queryDetailList(Integer id, String wxTemplateId) { if (Objects.isNull(id) || Objects.isNull(wxTemplateId)) { return BasicResultVO.success(RespStatusEnum.CLIENT_BAD_PARAMETERS); } try { - WxMaSubscribeService wxMaSubscribeService = wxServiceUtils.getMiniProgramServiceMap().get(id); - List templateList = wxMaSubscribeService.getTemplateList(); + WxMaService wxMaService = accountUtils.getAccountById(id, WxMaService.class); + List templateList = wxMaService.getSubscribeService().getTemplateList(); CommonAmisVo wxMpTemplateParam = Convert4Amis.getWxMaTemplateParam(wxTemplateId, templateList); return BasicResultVO.success(wxMpTemplateParam); } catch (Exception e) { diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java index d73284f..cf14aac 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java @@ -10,7 +10,7 @@ import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.constant.OfficialAccountParamConstant; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; -import com.java3y.austin.support.utils.WxServiceUtils; +import com.java3y.austin.support.utils.AccountUtils; import com.java3y.austin.web.config.WeChatLoginConfig; import com.java3y.austin.web.utils.Convert4Amis; import com.java3y.austin.web.utils.LoginUtils; @@ -46,7 +46,7 @@ import java.util.*; public class OfficialAccountController { @Autowired - private WxServiceUtils wxServiceUtils; + private AccountUtils accountUtils; @Autowired private LoginUtils loginUtils; @@ -60,10 +60,10 @@ public class OfficialAccountController { */ @GetMapping("/template/list") @ApiOperation("/根据账号Id获取模板列表") - public BasicResultVO queryList(Long id) { + public BasicResultVO queryList(Integer id) { try { List result = new ArrayList<>(); - WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(id); + WxMpService wxMpService = accountUtils.getAccountById(id, WxMpService.class); List allPrivateTemplate = wxMpService.getTemplateMsgService().getAllPrivateTemplate(); for (WxMpTemplate wxMpTemplate : allPrivateTemplate) { @@ -85,12 +85,12 @@ public class OfficialAccountController { */ @PostMapping("/detailTemplate") @ApiOperation("/根据账号Id和模板ID获取模板列表") - public BasicResultVO queryDetailList(Long id, String wxTemplateId) { + public BasicResultVO queryDetailList(Integer id, String wxTemplateId) { if (Objects.isNull(id) || Objects.isNull(wxTemplateId)) { return BasicResultVO.success(RespStatusEnum.CLIENT_BAD_PARAMETERS); } try { - WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(id); + WxMpService wxMpService = accountUtils.getAccountById(id, WxMpService.class); List allPrivateTemplate = wxMpService.getTemplateMsgService().getAllPrivateTemplate(); CommonAmisVo wxMpTemplateParam = Convert4Amis.getWxMpTemplateParam(wxTemplateId, allPrivateTemplate); return BasicResultVO.success(wxMpTemplateParam); diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java b/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java index af9e4f8..2e9d577 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java @@ -6,7 +6,6 @@ import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.support.dao.ChannelAccountDao; import com.java3y.austin.support.domain.ChannelAccount; -import com.java3y.austin.support.utils.WxServiceUtils; import com.java3y.austin.web.service.ChannelAccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,8 +21,6 @@ public class ChannelAccountServiceImpl implements ChannelAccountService { @Autowired private ChannelAccountDao channelAccountDao; - @Autowired - private WxServiceUtils wxServiceUtils; @Override public ChannelAccount save(ChannelAccount channelAccount) { @@ -33,9 +30,7 @@ public class ChannelAccountServiceImpl implements ChannelAccountService { } channelAccount.setCreator(StrUtil.isBlank(channelAccount.getCreator()) ? AustinConstant.DEFAULT_CREATOR : channelAccount.getCreator()); channelAccount.setUpdated(Math.toIntExact(DateUtil.currentSeconds())); - ChannelAccount result = channelAccountDao.save(channelAccount); - wxServiceUtils.fresh(); - return result; + return channelAccountDao.save(channelAccount); } @Override