| | |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.domain.user.LoginUserExtra; |
| | | import com.yeshi.buwan.exception.LoginUserException; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.pptv.PPTVApiUtil; |
| | | import com.yeshi.buwan.pptv.PPTVUtil; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | loginUserDao.update(user); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void bindQQ(String loginUid, String openId, String nickName, String portrait) throws LoginUserException { |
| | | |
| | |
| | | } |
| | | |
| | | LoginUser other = getLoginUserByQQOpenId(user.getSystemId(), openId); |
| | | if (other != null) { |
| | | if (other != null && !other.getId().equalsIgnoreCase(loginUid)) { |
| | | throw new LoginUserException("QQ已被其他账户绑定"); |
| | | } |
| | | LoginUser update = new LoginUser(); |
| | | update.setId(loginUid); |
| | | update.setQqOpenId(openId); |
| | | loginUserDao.updateSelective(update); |
| | | |
| | | user.setQqOpenId(openId); |
| | | loginUserDao.update(user); |
| | | |
| | | LoginUserExtra extra = new LoginUserExtra(); |
| | | extra.setId(loginUid); |
| | | LoginUserExtra extra = loginUserExtraDao.get(loginUid); |
| | | if (extra == null) { |
| | | extra = new LoginUserExtra(); |
| | | extra.setId(loginUid); |
| | | } |
| | | extra.setQqNickName(nickName); |
| | | extra.setQqOpenId(openId); |
| | | extra.setQqPortrait(portrait); |
| | | if (loginUserExtraDao.get(loginUid) == null) { |
| | | if (extra.getId() == null) { |
| | | initExtra(extra); |
| | | } else { |
| | | loginUserExtraDao.updateSelective(extra); |
| | | loginUserExtraDao.save(extra); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void bindWX(String loginUid, WeiXinUser weiXinUser) throws LoginUserException { |
| | | LoginUser user = getLoginUser(loginUid); |
| | |
| | | } |
| | | |
| | | LoginUser other = getLoginUserByWxUnionId(user.getSystemId(), weiXinUser.getUnionid()); |
| | | if (other != null) { |
| | | if (other != null && !other.getId().equalsIgnoreCase(loginUid)) { |
| | | throw new LoginUserException("微信已被其他账户绑定"); |
| | | } |
| | | user.setWxOpenId(weiXinUser.getOpenid()); |
| | | user.setWxUnionId(weiXinUser.getUnionid()); |
| | | loginUserDao.update(user); |
| | | LoginUser update = new LoginUser(); |
| | | update.setId(loginUid); |
| | | update.setWxOpenId(weiXinUser.getOpenid()); |
| | | update.setWxUnionId(weiXinUser.getUnionid()); |
| | | loginUserDao.updateSelective(update); |
| | | |
| | | LoginUserExtra extra = new LoginUserExtra(); |
| | | extra.setId(loginUid); |
| | | LoginUserExtra extra = null;//loginUserExtraDao.get(loginUid); |
| | | if (extra == null) { |
| | | extra = new LoginUserExtra(); |
| | | extra.setId(loginUid); |
| | | } |
| | | extra.setWxNickName(weiXinUser.getNickname()); |
| | | extra.setWxOpenId(weiXinUser.getOpenid()); |
| | | extra.setWxUnionId(weiXinUser.getUnionid()); |
| | |
| | | if (loginUserExtraDao.get(loginUid) == null) { |
| | | initExtra(extra); |
| | | } else { |
| | | extra.setUpdateTime(new Date()); |
| | | loginUserExtraDao.updateSelective(extra); |
| | | } |
| | | |
| | | System.out.println("12213"); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public LoginUserExtra getExtra(String uid) { |
| | | return loginUserExtraDao.get(uid); |
| | | } |
| | | |
| | | @Override |
| | | public LoginUserExtra initExtra(String uid) { |
| | | LoginUser user = getLoginUser(uid); |
| | | if (user == null) |
| | | return null; |
| | | LoginUserExtra extra = new LoginUserExtra(); |
| | | extra.setId(uid); |
| | | extra.setCreateTime(new Date()); |
| | | //之前的用户邮箱登录 |
| | | if (user.getLoginType() == LoginUser.LOGIN_TYPE_QQ) { |
| | | user.setQqOpenId(user.getOpenid()); |
| | | extra.setQqOpenId(user.getOpenid()); |
| | | extra.setQqPortrait(user.getPortrait()); |
| | | } else if (user.getLoginType() == LoginUser.LOGIN_TYPE_EMAIL) { |
| | | user.setEmail(user.getOpenid()); |
| | | extra.setEmail(user.getOpenid()); |
| | | } else if (user.getLoginType() == LoginUser.LOGIN_TYPE_WX) { |
| | | user.setWxOpenId(user.getOpenid()); |
| | | extra.setWxOpenId(user.getOpenid()); |
| | | extra.setWxPortrait(user.getPortrait()); |
| | | } |
| | | |
| | | extra.setBirthday(user.getBirthday()); |
| | | extra.setSex(user.getSex()); |
| | | extra.setSign(user.getSign()); |
| | | extra.setIpinfo(user.getIpinfo()); |
| | | extra.setDevice(user.getDevice()); |
| | | extra.setPptvUid(PPTVUtil.getPPTVUid(uid)); |
| | | //TODO 初始化附加信息 |
| | | loginUserDao.update(user); |
| | | loginUserExtraDao.save(extra); |
| | | return extra; |
| | | } |
| | | |
| | | @Override |
| | | public void updateSelectiveByPrimaryKey(LoginUser loginUser) { |
| | | loginUserDao.updateSelective(loginUser); |
| | | } |
| | | |
| | | @Override |
| | | public void updateSelectiveByPrimaryKey(LoginUserExtra extra) { |
| | | loginUserExtraDao.updateSelective(extra); |
| | | } |
| | | |
| | | @Override |
| | | public String updatePPTVOpenId(String uid) throws PPTVException { |
| | | LoginUserExtra extra = getExtra(uid); |
| | | if (extra == null) { |
| | | extra = initExtra(uid); |
| | | } |
| | | String code = PPTVUtil.getPPTVCode(extra.getPptvUid()); |
| | | |
| | | boolean login = PPTVApiUtil.login(code); |
| | | if (!login) { |
| | | throw new PPTVException(101, "登录失败"); |
| | | } |
| | | |
| | | String openId = PPTVApiUtil.getOpenId(extra.getPptvUid()); |
| | | if (StringUtil.isNullOrEmpty(openId)) { |
| | | throw new PPTVException(102, "openId获取失败"); |
| | | } |
| | | LoginUserExtra update=new LoginUserExtra(); |
| | | update.setId(uid); |
| | | update.setPptvOpenId(openId); |
| | | updateSelectiveByPrimaryKey(update); |
| | | return openId; |
| | | } |
| | | } |