@Override public void cancelBindSite(Long bindSiteId) { BindSite bs = bindSiteDao.queryById(bindSiteId); if (bs == null) { throw new ServiceException(ErrService.UserS.ACC_108, "已经解绑成功,不允许再次操作!"); } if (bs.getRegFlag()) { throw new ServiceException(ErrService.UserS.ACC_108, "第三方账号注册,不允许解除绑定关系!"); } bindSiteDao.deletById(bindSiteId); }
private void changeToken(BindSite bsOther, long tokenExpireIn) { bsOther.setStartDate(new Date()); bindSiteDao.updateToken( bsOther.getBindSiteId(), bsOther.getAccessToken(), bsOther.getNickName(), bsOther.getPhotoPath(), bsOther.getStartDate(), new Date(bsOther.getStartDate().getTime() + tokenExpireIn)); }
@Override public BindSite bindSiteUser( Long userId, SiteMark siteMark, String openId, String accessToken, long tokenExpireIn, boolean regFlag) { if (userId == null || userId <= 0) { throw new IllegalArgumentException(); } BindSite bs3 = bindSiteDao.queryByOpenId(siteMark, openId); if (bs3 != null) { throw new ServiceException(ErrService.UserS.ACC_108, "当前第三方账号已经被其他账号绑定!"); } // 当前用户是否已经绑定 BindSite bs = bindSiteDao.queryByUserId(siteMark, userId); // 获取第三方用户信息 BindSite bsOther = UserServiceImpl.getBindSite(siteMark, openId, accessToken); if (bs != null) { // 更新token等信息 bsOther.setBindSiteId(bs.getBindSiteId()); this.changeToken(bsOther, tokenExpireIn); } else { // 绑定平台 bs = new BindSite(); bs.setAccessToken(accessToken); bs.setOpenId(openId); bs.setNickName(bsOther.getNickName()); bs.setRegFlag(regFlag); bs.setSiteMark(siteMark); bs.setUserId(userId); bs.setStartDate(new Date()); bs.setEndDate(new Date(bs.getStartDate().getTime() + tokenExpireIn)); bs.setPhotoPath(bsOther.getPhotoPath()); bindSiteDao.insert(bs); } return bs; }
@Override public BindSite checkLogin( BindSite.SiteMark siteMark, String openId, String accessToken, long tokenExpireIn) { // 第三方用户信息在当前平台保存的信息 BindSite bs = bindSiteDao.queryByOpenId(siteMark, openId); // 获取第三方用户信息 BindSite bsOther = UserServiceImpl.getBindSite(siteMark, openId, accessToken); if (bs != null) { // 更新token等信息 bsOther.setBindSiteId(bs.getBindSiteId()); this.changeToken(bsOther, tokenExpireIn); } else { // 注册用户 User user = register(bsOther.getNickName(), bsOther.getPhotoPath()); // 绑定平台 bs = bindSiteUser(user.getUserId(), siteMark, openId, accessToken, tokenExpireIn, true); } return bs; }
@Override public List<BindSite> getBindSiteListByUser(Long userId) { return bindSiteDao.queryListByUserId(userId); }