Commit a31c529b by huangjy

feat:支持对接多小程序

parent bf3e8cf1
ALTER TABLE `plat_device_other` ALTER TABLE `plat_device_other`
...@@ -34,3 +34,7 @@ ADD COLUMN `license_info` varchar(255) COMMENT '许可证信息' AFTER `license` ...@@ -34,3 +34,7 @@ ADD COLUMN `license_info` varchar(255) COMMENT '许可证信息' AFTER `license`
ALTER TABLE `plat_device` ALTER TABLE `plat_device`
ADD COLUMN `expire_time` int8 COMMENT '过期时间' AFTER `license_info`, ADD COLUMN `expire_time` int8 COMMENT '过期时间' AFTER `license_info`,
ADD COLUMN `activation_time` int8 COMMENT '激活时间' AFTER `expire_time`; ADD COLUMN `activation_time` int8 COMMENT '激活时间' AFTER `expire_time`;
ALTER TABLE `plat_tenant`
ADD COLUMN `appid` varchar(64) COMMENT 'appid' AFTER `url`,
ADD COLUMN `secret` varchar(64) COMMENT 'secret' AFTER `appid`;
\ No newline at end of file
...@@ -61,4 +61,8 @@ public class PlatTenantDTOVO extends BaseIdDTO { ...@@ -61,4 +61,8 @@ public class PlatTenantDTOVO extends BaseIdDTO {
@ApiModelProperty(value = "租户平台地址") @ApiModelProperty(value = "租户平台地址")
private String url; private String url;
@ApiModelProperty(value = "appid")
private String appid;
@ApiModelProperty(value = "secret")
private String secret;
} }
...@@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService; ...@@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig; import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedissonConfigImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaRedissonConfigImpl;
import lombok.Data;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage; import me.chanjar.weixin.mp.config.WxMpConfigStorage;
...@@ -15,6 +16,7 @@ import org.springframework.context.annotation.Bean; ...@@ -15,6 +16,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
@Data
public class WxConfig { public class WxConfig {
@Value("${wx.miniapp.config.appid}") @Value("${wx.miniapp.config.appid}")
......
...@@ -35,6 +35,10 @@ public class WechatLoginPhoneDTO { ...@@ -35,6 +35,10 @@ public class WechatLoginPhoneDTO {
@ApiModelProperty(value = "组织路径") @ApiModelProperty(value = "组织路径")
private String orgPath; private String orgPath;
@ApiModelProperty(value = "微信appid")
private String appid;
@ApiModelProperty(value = "微信secret")
private String secret;
} }
...@@ -3,6 +3,8 @@ package com.makeit.utils.third.wechat; ...@@ -3,6 +3,8 @@ package com.makeit.utils.third.wechat;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.makeit.config.WxMaConfiguration; import com.makeit.config.WxMaConfiguration;
import com.makeit.enums.CodeMessageEnum; import com.makeit.enums.CodeMessageEnum;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
...@@ -21,6 +23,10 @@ public class WechatUtil { ...@@ -21,6 +23,10 @@ public class WechatUtil {
} }
WxMaService wxService = WxMaConfiguration.getMaService(); WxMaService wxService = WxMaConfiguration.getMaService();
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(dto.getAppid());
config.setSecret(dto.getSecret());
wxService.setWxMaConfig(config);
try { try {
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code); WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
......
...@@ -63,6 +63,8 @@ public class PlatTenant extends BaseEntity { ...@@ -63,6 +63,8 @@ public class PlatTenant extends BaseEntity {
* 租户平台地址 * 租户平台地址
*/ */
private String url; private String url;
private String appid;
private String secret;
} }
\ No newline at end of file
package com.makeit.service.saas.impl; package com.makeit.service.saas.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
...@@ -8,6 +9,7 @@ import com.makeit.common.entity.BaseBusEntity; ...@@ -8,6 +9,7 @@ import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity; import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO; import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO; import com.makeit.common.page.PageVO;
import com.makeit.config.WxMaConfiguration;
import com.makeit.dto.platform.sys.PlatLogoConfigDTO; import com.makeit.dto.platform.sys.PlatLogoConfigDTO;
import com.makeit.entity.platform.auth.PlatOrg; import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.auth.PlatUser; import com.makeit.entity.platform.auth.PlatUser;
...@@ -38,6 +40,7 @@ import com.makeit.service.saas.SaasUserService; ...@@ -38,6 +40,7 @@ import com.makeit.service.saas.SaasUserService;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.PageUtil; import com.makeit.utils.data.convert.PageUtil;
import com.makeit.utils.data.convert.StreamUtil; import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.msg.config.WxConfig;
import com.makeit.utils.redis.RedisCacheUtil; import com.makeit.utils.redis.RedisCacheUtil;
import com.makeit.utils.user.plat.PlatUserUtil; import com.makeit.utils.user.plat.PlatUserUtil;
import com.makeit.utils.user.plat.PlatUserVO; import com.makeit.utils.user.plat.PlatUserVO;
...@@ -85,6 +88,8 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen ...@@ -85,6 +88,8 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen
private IotOrgService iotOrgService; private IotOrgService iotOrgService;
@Autowired @Autowired
private PlatLogoConfigService platLogoConfigService; private PlatLogoConfigService platLogoConfigService;
@Autowired
private WxConfig wxConfig;
private LambdaQueryWrapper<PlatTenant> listLambdaQueryWrapper(PlatTenantVO dto, boolean userAccountLike) { private LambdaQueryWrapper<PlatTenant> listLambdaQueryWrapper(PlatTenantVO dto, boolean userAccountLike) {
...@@ -258,6 +263,13 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen ...@@ -258,6 +263,13 @@ public class PlatTenantServiceImpl extends ServiceImpl<PlatTenantMapper, PlatTen
checkCode(dto); checkCode(dto);
PlatTenant tntTenant = BeanDtoVoUtils.convert(dto, PlatTenant.class); PlatTenant tntTenant = BeanDtoVoUtils.convert(dto, PlatTenant.class);
if (StringUtils.isEmpty(tntTenant.getAppid())) {
tntTenant.setAppid(wxConfig.getAppId());
}
if (StringUtils.isEmpty(tntTenant.getSecret())) {
tntTenant.setSecret(wxConfig.getMpSecret());
}
//新租户同步到iot //新租户同步到iot
PlatTenantVO platTenantVO = new PlatTenantVO(); PlatTenantVO platTenantVO = new PlatTenantVO();
platTenantVO.setName(dto.getName()); platTenantVO.setName(dto.getName());
......
...@@ -3,14 +3,17 @@ package com.makeit.service.wechat.impl; ...@@ -3,14 +3,17 @@ package com.makeit.service.wechat.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.dto.platform.auth.PlatOrgSplitDTO; import com.makeit.dto.platform.auth.PlatOrgSplitDTO;
import com.makeit.entity.platform.elder.PlatElderChildrenInfo; import com.makeit.entity.platform.elder.PlatElderChildrenInfo;
import com.makeit.entity.saas.PlatTenant;
import com.makeit.enums.Const; import com.makeit.enums.Const;
import com.makeit.enums.HeaderConst; import com.makeit.enums.HeaderConst;
import com.makeit.global.aspect.misc.nofill.NoFillUtil; import com.makeit.global.aspect.misc.nofill.NoFillUtil;
import com.makeit.service.platform.auth.PlatOrgService; import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.elder.PlatElderChildrenInfoService; import com.makeit.service.platform.elder.PlatElderChildrenInfoService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.service.wechat.PlatElderChildrenInfoUserLoginWechatService; import com.makeit.service.wechat.PlatElderChildrenInfoUserLoginWechatService;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.id.IdGen; import com.makeit.utils.data.id.IdGen;
import com.makeit.utils.msg.config.WxConfig;
import com.makeit.utils.request.RequestUtil; import com.makeit.utils.request.RequestUtil;
import com.makeit.utils.sys.FileUtil; import com.makeit.utils.sys.FileUtil;
import com.makeit.utils.third.wechat.WechatLoginPhoneDTO; import com.makeit.utils.third.wechat.WechatLoginPhoneDTO;
...@@ -35,7 +38,9 @@ public class PlatElderChildrenInfoUserLoginWechatServiceImpl implements PlatElde ...@@ -35,7 +38,9 @@ public class PlatElderChildrenInfoUserLoginWechatServiceImpl implements PlatElde
private PlatElderChildrenInfoService platElderChildrenInfoService; private PlatElderChildrenInfoService platElderChildrenInfoService;
@Autowired @Autowired
private PlatOrgService platOrgService; private PlatTenantService platTenantService;
@Autowired
private WxConfig wxConfig;
private static final Logger logger = LoggerFactory.getLogger(PlatElderChildrenInfoUserLoginWechatServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(PlatElderChildrenInfoUserLoginWechatServiceImpl.class);
...@@ -43,6 +48,16 @@ public class PlatElderChildrenInfoUserLoginWechatServiceImpl implements PlatElde ...@@ -43,6 +48,16 @@ public class PlatElderChildrenInfoUserLoginWechatServiceImpl implements PlatElde
@Transactional @Transactional
public WechatUserInfo login(WechatLoginPhoneDTO dto) { public WechatUserInfo login(WechatLoginPhoneDTO dto) {
PlatTenant platTenant = platTenantService.getOne(new QueryWrapper<PlatTenant>().lambda()
.eq(PlatTenant::getAppid, dto.getAppid())
.last("limit 1"));
if (platTenant != null) {
dto.setAppid(platTenant.getAppid());
dto.setSecret(platTenant.getSecret());
} else {
dto.setAppid(wxConfig.getAppId());
dto.setSecret(wxConfig.getAppSecret());
}
WxUserInfo userInfo = WechatUtil.login(dto); WxUserInfo userInfo = WechatUtil.login(dto);
logger.info("userinfo:{}", userInfo); logger.info("userinfo:{}", userInfo);
......
...@@ -19,7 +19,7 @@ public class IotSyncTask { ...@@ -19,7 +19,7 @@ public class IotSyncTask {
* 启用状态的租户才同步 * 启用状态的租户才同步
* 新增和更新平台端设备表 * 新增和更新平台端设备表
*/ */
@Scheduled(cron = "0 0/1 * * * ?") // @Scheduled(cron = "0 0/1 * * * ?")
public void syncEquipmentInfo() { public void syncEquipmentInfo() {
platDeviceService.savePlatDevice(); platDeviceService.savePlatDevice();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment