Commit 598b36e4 authored by xuepeng.chang's avatar xuepeng.chang

限制微信绑定

parent f29df899
......@@ -14,4 +14,7 @@ public class CommonProperties {
/** 限制用户小程序登陆*/
@Value("${wechat.black.userIds:}")
private String wechatBlackUserIds;
@Value("${wechat.limit.bind:}")
private String wechatLimitBinding;
}
package cn.quantgroup.xyqb.service.middleoffice.applet.impl;
import cn.quantgroup.xyqb.config.data.WechatConfiguration;
import cn.quantgroup.xyqb.constant.CommonProperties;
import cn.quantgroup.xyqb.constant.UserConstant;
import cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule;
import cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo;
......@@ -60,13 +61,16 @@ public class AppletServiceImpl implements IAppletService {
private final ISessionService sessionService;
private final CommonProperties commonProperties;
@Autowired
public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository,
IUserRegisterService iUserRegisterService,
IUserService userService,
ILoginModule loginModule, WechatConfiguration wechatConfiguration,
IWechatBindLogRepository wechatBindLogRepository, ISessionService sessionService) {
IWechatBindLogRepository wechatBindLogRepository, ISessionService sessionService,
CommonProperties commonProperties) {
this.iWeChatUserRepository = iWeChatUserRepository;
this.iUserRegisterService = iUserRegisterService;
this.userService = userService;
......@@ -74,6 +78,7 @@ public class AppletServiceImpl implements IAppletService {
this.wechatConfiguration = wechatConfiguration;
this.wechatBindLogRepository = wechatBindLogRepository;
this.sessionService = sessionService;
this.commonProperties = commonProperties;
}
@Override
......@@ -85,25 +90,27 @@ public class AppletServiceImpl implements IAppletService {
throw new BizException(BizExceptionEnum.ERROR_MATCHING_WECHAT_APP_ID);
}
appletParamEntry.setAppId(appId);
// 校验当前用户的手机号有没有绑定过openId
List<WechatUserInfo> wechatUserInfos = iWeChatUserRepository.findByPhoneNoAndAppNameAndAppIdAndTenantId(appletParamEntry.getMobile(),
appletParamEntry.getAppName(), appletParamEntry.getAppId(), appletParamEntry.getTenantId());
if(org.apache.commons.lang3.StringUtils.isNotEmpty(commonProperties.getWechatLimitBinding())
&& "limit".equals(commonProperties.getWechatLimitBinding())){
// 校验当前用户的手机号有没有绑定过openId
List<WechatUserInfo> wechatUserInfos = iWeChatUserRepository.findByPhoneNoAndAppNameAndAppIdAndTenantId(appletParamEntry.getMobile(),
appletParamEntry.getAppName(), appletParamEntry.getAppId(), appletParamEntry.getTenantId());
if(wechatUserInfos.size()>1){
log.info("微信关联失败[service]:phoneNo:{},openId:{},appName:{}", appletParamEntry.getMobile(), appletParamEntry.getOpenId(),appletParamEntry.getAppName());
throw new AppletException(BizExceptionEnum.USER_WECHAT_BIND_ERROR.getMsg(), BizExceptionEnum.USER_WECHAT_BIND_ERROR.getBusinessCode());
}
if(wechatUserInfos.size() ==1){
WechatUserInfo wechatUserInfoOne = wechatUserInfos.get(0);
if(Objects.equals(wechatUserInfoOne.getOpenId(),appletParamEntry.getOpenId())){
log.info("微信关联成功:重复关联:跳过:[service]:userId:{},phoneNo:{},openId:{}", wechatUserInfoOne.getUserId(), wechatUserInfoOne.getPhoneNo(), wechatUserInfoOne.getOpenId());
return wechatUserInfoOne.getUserId();
}else{
if(wechatUserInfos.size()>1){
log.info("微信关联失败[service]:phoneNo:{},openId:{},appName:{}", appletParamEntry.getMobile(), appletParamEntry.getOpenId(),appletParamEntry.getAppName());
throw new AppletException(BizExceptionEnum.USER_WECHAT_BIND_ERROR.getMsg(), BizExceptionEnum.USER_WECHAT_BIND_ERROR.getBusinessCode());
}
if(wechatUserInfos.size() ==1){
WechatUserInfo wechatUserInfoOne = wechatUserInfos.get(0);
if(Objects.equals(wechatUserInfoOne.getOpenId(),appletParamEntry.getOpenId())){
log.info("微信关联成功:重复关联:跳过:[service]:userId:{},phoneNo:{},openId:{}", wechatUserInfoOne.getUserId(), wechatUserInfoOne.getPhoneNo(), wechatUserInfoOne.getOpenId());
return wechatUserInfoOne.getUserId();
}else{
log.info("微信关联失败[service]:phoneNo:{},openId:{},appName:{}", appletParamEntry.getMobile(), appletParamEntry.getOpenId(),appletParamEntry.getAppName());
throw new AppletException(BizExceptionEnum.USER_WECHAT_BIND_ERROR.getMsg(), BizExceptionEnum.USER_WECHAT_BIND_ERROR.getBusinessCode());
}
}
}
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppNameAndAppIdAndTenantId(appletParamEntry.getOpenId(), appletParamEntry.getAppName(), appletParamEntry.getAppId(), appletParamEntry.getTenantId());
//这个接口先不考虑更换手机号的情况
if (appletParamEntry.getTenantId() == null) {
......
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 to comment