Commit a8221d51 authored by xuepeng.chang's avatar xuepeng.chang

小程序 解绑 清除 小程序的登录状态

parent 782f6d1b
...@@ -22,6 +22,7 @@ import cn.quantgroup.xyqb.service.session.impl.SessionServiceImpl; ...@@ -22,6 +22,7 @@ import cn.quantgroup.xyqb.service.session.impl.SessionServiceImpl;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.StringUtils; import cn.quantgroup.xyqb.util.StringUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.qiniu.util.Json;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -189,6 +190,7 @@ public class AppletServiceImpl implements IAppletService { ...@@ -189,6 +190,7 @@ public class AppletServiceImpl implements IAppletService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean unbind(UnbindParam unbindParam) { public boolean unbind(UnbindParam unbindParam) {
log.info("微信解绑,unbindParam:{} ", JSON.toJSONString(unbindParam));
// 获取当前用户绑定了对应的微信小程序 // 获取当前用户绑定了对应的微信小程序
List<WechatUserInfo> wechatUserInfoList = iWeChatUserRepository.findByUserIdAndAppNameAndAppIdAndTenantId(unbindParam.getUserId(), unbindParam.getAppName(), List<WechatUserInfo> wechatUserInfoList = iWeChatUserRepository.findByUserIdAndAppNameAndAppIdAndTenantId(unbindParam.getUserId(), unbindParam.getAppName(),
unbindParam.getAppId(), unbindParam.getTenantId()); unbindParam.getAppId(), unbindParam.getTenantId());
...@@ -205,15 +207,22 @@ public class AppletServiceImpl implements IAppletService { ...@@ -205,15 +207,22 @@ public class AppletServiceImpl implements IAppletService {
wechatBindLogRepository.save(wechatBindLog); wechatBindLogRepository.save(wechatBindLog);
} }
// 删除微信关联记录后,清除微信渠道的登陆token // 删除微信关联记录后,清除微信渠道的登陆token
if(org.apache.commons.lang3.StringUtils.isNotEmpty(unbindParam.getWechatChannelId())){ // if(org.apache.commons.lang3.StringUtils.isNotEmpty(unbindParam.getWechatChannelId())){
List<String> wechatChannelIds = Arrays.stream(unbindParam.getWechatChannelId().split(",")).collect(Collectors.toList()); // List<String> wechatChannelIds = Arrays.stream(unbindParam.getWechatChannelId().split(",")).collect(Collectors.toList());
for (String wechatChannelId : wechatChannelIds) { // for (String wechatChannelId : wechatChannelIds) {
LoginProperties loginProperties = new LoginProperties(1, Long.valueOf(wechatChannelId), unbindParam.getTenantId()); // LoginProperties loginProperties = new LoginProperties(1, Long.valueOf(wechatChannelId), unbindParam.getTenantId());
sessionService.deleteWechatSession(unbindParam.getUserId(),loginProperties,unbindParam.getTenantId()); // sessionService.deleteWechatSession(unbindParam.getUserId(),loginProperties,unbindParam.getTenantId());
log.info("微信解绑成功,清除微信的登陆token,userId:{},wechatChannelId:{}", unbindParam.getUserId(),wechatChannelId); // log.info("微信解绑成功,清除微信的登陆token,userId:{},wechatChannelId:{}", unbindParam.getUserId(),wechatChannelId);
} // }
} // }
log.info("微信解绑成功,unbindParam:{} ", JSON.toJSONString(unbindParam)); User user = userService.findById(unbindParam.getUserId(), unbindParam.getTenantId());
// 老的微信登录的时候用的是下边的方式,删除的时候也只能这么删
LoginProperties loginProperties = LoginProperties.builder()
.createdFrom(user.getRegisteredFrom())
.tenantId(unbindParam.getTenantId())
.build();
sessionService.deleteWechatSession(unbindParam.getUserId(),loginProperties,unbindParam.getTenantId());
log.info("微信解绑成功,清除微信的登陆token,userId:{},loginProperties:{}", unbindParam.getUserId(), JSON.toJSONString(loginProperties));
return true; return true;
} }
......
...@@ -435,8 +435,8 @@ public class SessionServiceImpl implements ISessionService { ...@@ -435,8 +435,8 @@ public class SessionServiceImpl implements ISessionService {
public void deleteWechatSession(Long userId, LoginProperties loginProperties, Integer tenantId) { public void deleteWechatSession(Long userId, LoginProperties loginProperties, Integer tenantId) {
String key = generateLoginPropertiesKey(userId, loginProperties, tenantId); String key = generateLoginPropertiesKey(userId, loginProperties, tenantId);
String token = stringRedisTemplate.opsForValue().get(key); String token = stringRedisTemplate.opsForValue().get(key);
log.info("deleteWechatSession,通过用户获取token结果,token:{} , userId: {},loginProperties:{},tenantId:{}", log.info("deleteWechatSession,通过用户获取token结果,key :{},token:{} , userId: {},loginProperties:{},tenantId:{}",
token, userId,JSON.toJSONString(loginProperties),tenantId); key,token, userId,JSON.toJSONString(loginProperties),tenantId);
deleteSession(token, tenantId); deleteSession(token, tenantId);
} }
......
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