| | |
| | | private static final String OFFICIAL_BIND_TOKEN_PREFIX = "official:bind:"; |
| | | private static final Duration OFFICIAL_BIND_TOKEN_TTL = Duration.ofMinutes(10); |
| | | private static final String OFFICIAL_OPEN_ID_PLACEHOLDER_PREFIX = "OA_PLACEHOLDER_"; |
| | | private static final String UNBOUND_OPEN_ID_PREFIX = "UNBOUND_"; |
| | | |
| | | private final MpUserMapper mpUserMapper; |
| | | private final SysDeptMapper sysDeptMapper; |
| | |
| | | String currentOpenId = user.getOpenId(); |
| | | if (StringUtils.hasText(currentOpenId) |
| | | && !Objects.equals(currentOpenId, openId) |
| | | && !MpStaffConstants.isPlaceholderOpenId(currentOpenId)) { |
| | | && !MpStaffConstants.isPlaceholderOpenId(currentOpenId) |
| | | && !isUnboundOpenId(currentOpenId)) { |
| | | throw new BizException(BizErrorCode.AUTH_FORBIDDEN, "该手机号已绑定其他微信账号"); |
| | | } |
| | | if (MiniUserType.EMPLOYEE.equals(user.getUserType()) |
| | |
| | | MiniStpUtil.logout(); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void unbindMiniOpenIdAndLogout() { |
| | | MpUser user = currentMpUser(); |
| | | user.setOpenId(UNBOUND_OPEN_ID_PREFIX + UUID.randomUUID().toString().replace("-", "")); |
| | | mpUserMapper.updateById(user); |
| | | MiniStpUtil.logout(user.getId()); |
| | | } |
| | | |
| | | private boolean isUnboundOpenId(String openId) { |
| | | return StringUtils.hasText(openId) && openId.startsWith(UNBOUND_OPEN_ID_PREFIX); |
| | | } |
| | | |
| | | private MiniLoginResponse buildResponse(MpUser user) { |
| | | String name = |
| | | user.getNickName() != null && !user.getNickName().isBlank() |