@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 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; }