| | |
| | | import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserConnectHistoryMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dto.wx.WXAccountInfoDTO;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.user.BindingAccount;
|
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode;
|
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum;
|
| | |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.WeiXinUser;
|
| | | import com.yeshi.fanli.exception.UserAccountException;
|
| | | import com.yeshi.fanli.exception.user.ForbiddenUserIdentifyCodeException;
|
| | | import com.yeshi.fanli.exception.user.UserAccountException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.msg.UserAccountMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.BindingAccountService;
|
| | | import com.yeshi.fanli.service.inter.money.extract.BindingAccountService;
|
| | | import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
|
| | | import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
|
| | | import com.yeshi.fanli.service.inter.user.UserAccountBindingHistoryService;
|
| | | import com.yeshi.fanli.service.inter.user.UserAccountService;
|
| | | import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoDeleteRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.FileUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | |
| | |
|
| | | @Resource
|
| | | private JedisPool jedisPool;
|
| | | |
| | | |
| | |
|
| | | @Lazy
|
| | | @Resource
|
| | | private UserInfoModifyRecordService userInfoModifyRecordService;
|
| | | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public LoginResult login(HttpServletRequest request, Boolean first, String appId, String code, String phone,
|
| | | UserInfo tbUserInfo, boolean wxinstall, int loginType) throws UserAccountException {
|
| | | public LoginResult login(HttpServletRequest request, AcceptData acceptData, Boolean first, String appId,
|
| | | String code, String phone, UserInfo tbUserInfo, boolean wxinstall, int loginType)
|
| | | throws UserAccountException {
|
| | |
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | |
| | |
|
| | | case 2:// 微信
|
| | | // 通过Code换取信息
|
| | | weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | if (weiXinUser == null)
|
| | | throw new UserAccountException(1001, "无法获取到微信个人信息");
|
| | | LogHelper.test("微信授权用户信息:" + new Gson().toJson(weiXinUser));
|
| | |
| | | }
|
| | |
|
| | | } else {// 没有安装微信
|
| | | LoginResult result = loginNoInstallWX(appId, code, phone, tbUserInfo, loginType);
|
| | | LoginResult result = loginNoInstallWX(acceptData, appId, code, phone, tbUserInfo, loginType);
|
| | | if (result.getType() == LoginResult.TYPE_CREATE)
|
| | | session.setAttribute("LAST_LOGIN_USER", result.getUser());
|
| | | return result;
|
| | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public LoginResult loginNoInstallWX(String appId, String code, String phone, UserInfo tbUserInfo, int loginType)
|
| | | throws UserAccountException {
|
| | | public LoginResult loginNoInstallWX(AcceptData acceptData, String appId, String code, String phone,
|
| | | UserInfo tbUserInfo, int loginType) throws UserAccountException {
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | | logInfo.put("code", code);
|
| | |
| | | break;
|
| | | case 2:// 微信
|
| | | // 通过Code换取信息
|
| | | weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | if (weiXinUser == null)
|
| | | throw new UserAccountException(1001, "无法获取到微信个人信息");
|
| | |
|
| | |
| | | user.setRank(0);
|
| | | if (StringUtil.isNullOrEmpty(user.getPortrait()))
|
| | | user.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
|
| | |
|
| | | userInfoMapper.insertSelective(user);
|
| | |
|
| | | // 昵称为空时 默认昵称
|
| | | if (StringUtil.isNullOrEmpty(user.getNickName())) {
|
| | | UserInfo updateUserInfo = new UserInfo(user.getId());
|
| | | updateUserInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName() + user.getId());
|
| | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | |
| | | if (!StringUtil.isNullOrEmpty(user.getPhone())) |
| | |
|
| | | if (!StringUtil.isNullOrEmpty(user.getPhone()))
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, user.getPhone());
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(user.getWxUnionId())) |
| | |
|
| | | if (!StringUtil.isNullOrEmpty(user.getWxUnionId()))
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, user.getWxUnionId());
|
| | | |
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | @Override
|
| | | public void bindPhone(Long uid, String phone) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null)
|
| | | throw new UserAccountException(4, "用户不存在");
|
| | |
|
| | |
| | | update.setPhone(phone);
|
| | | userInfoMapper.updateByPrimaryKeySelective(update);
|
| | | userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
|
| | | |
| | | |
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, phone);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void unBindPhone(Long uid, String phone) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null)
|
| | | throw new UserAccountException(4, "用户不存在");
|
| | |
|
| | |
| | | @Override
|
| | | public void bindTaoBao(Long uid, String tbOpenId, String tbNickName, String tbPortrait)
|
| | | throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null)
|
| | | throw new UserAccountException(4, "用户不存在");
|
| | |
|
| | |
| | |
|
| | | @Override
|
| | | public void unBindTaoBao(Long uid) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null)
|
| | | throw new UserAccountException(4, "用户不存在");
|
| | | if (StringUtil.isNullOrEmpty(user.getOpenid()))
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public void changeWXBind(Long uid, String code) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | public void changeWXBind(AcceptData acceptData, Long uid, String code) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null)
|
| | | throw new UserAccountException(4, "用户不存在");
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | if (weiXinUser == null)
|
| | | throw new UserAccountException(10, "获取微信用户信息失败");
|
| | | if (weiXinUser.getUnionid().equalsIgnoreCase(user.getWxUnionId()))
|
| | |
| | |
|
| | | UserInfo newUser = getUserInfoByWXUnionId(user.getAppId(), weiXinUser.getUnionid());
|
| | | if (newUser != null)
|
| | | throw new UserAccountException(13, "亲,你要更换绑定的微信号已被其他账号绑定");
|
| | | throw new UserAccountException(13, "该微信号已被其他账号绑定");
|
| | |
|
| | | UserInfo updateUserInfo = new UserInfo(uid);
|
| | | updateUserInfo.setWxName(weiXinUser.getNickname());
|
| | | updateUserInfo.setWxOpenId(weiXinUser.getOpenid());
|
| | | updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
|
| | | updateUserInfo.setWxUnionId(weiXinUser.getUnionid());
|
| | | updateUserInfo.setNickName(weiXinUser.getNickname());
|
| | | updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
|
| | | if (StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
|
| | | updateUserInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
|
| | |
|
| | | // 将默认昵称替换成微信昵称
|
| | | String defaultNickName = Constant.systemCommonConfig.getDefaultNickName();
|
| | | if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
|
| | | defaultNickName = defaultNickName + uid;
|
| | | if ((defaultNickName.equals(user.getNickName()) || "板栗快省".equals(user.getNickName()))) {
|
| | | updateUserInfo.setNickName(weiXinUser.getNickname());
|
| | | }
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
|
| | | updateUserInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
|
| | | // 将默认头像替换成微信头像
|
| | | String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait();
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait)
|
| | | && defaultPortrait.equals(user.getPortrait())) {
|
| | | updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
|
| | | }
|
| | |
|
| | | userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
|
| | |
|
| | | userAccountMsgNotificationService.changeBindingSuccess(uid, MsgAccountDetailFactory.TYPE_WX);
|
| | | |
| | | |
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid());
|
| | | }
|
| | |
|
| | |
| | | TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMddHHmmss"));
|
| | |
|
| | | // 备份用户信息
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | |
|
| | | // TODO 备份资金明细
|
| | |
|
| | |
| | | public void clearUserPortrait(Long uid) {
|
| | | if (uid == null)
|
| | | return;
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | String prefix = String.format("/portrait/wx/%s_", user.getWxUnionId());
|
| | | ObjectListing list = COSManager.getInstance().getObjectList(prefix, null, 30);
|
| | | if (list != null && list.getObjectSummaries() != null)
|
| | |
| | | public String repairPortrait(Long uid) {
|
| | | if (uid == null)
|
| | | return null;
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null)
|
| | | return null;
|
| | | String prefix = String.format("/portrait/wx/%s_", user.getWxUnionId());
|
| | |
| | | if (exec == null || exec.size() == 0) {
|
| | | throw new UserAccountException(10, "请稍后再试");
|
| | | } else {
|
| | | |
| | |
|
| | | // 查询是否存在该电话历史用户
|
| | | UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByPhone(phone);
|
| | | if (userInfo != null) {
|
| | |
| | | } else {
|
| | | userInfo = new UserInfo();
|
| | | userInfo.setAppId(appId);
|
| | | userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
|
| | | // userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
|
| | | userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
|
| | | userInfo.setPhone(phone);
|
| | | userInfo.setLoginType(loginType);
|
| | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(userInfo.getId(), ModifyTypeEnum.bindPhone, phone);
|
| | | }
|
| | | |
| | |
|
| | | return userInfo;
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public UserInfo loginWinXin(HttpServletRequest request, int loginType, String code, String appId)
|
| | | throws UserAccountException {
|
| | | public UserInfo loginWinXin(HttpServletRequest request, AcceptData acceptData, int loginType, String code,
|
| | | String appId) throws UserAccountException {
|
| | | // 日志信息
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | |
| | | LogHelper.lgoinInfo(logInfo.toString());
|
| | |
|
| | | // 通过Code换取信息
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(1, "微信帐号授权失败");
|
| | | }
|
| | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | userInfoModifyRecordService.addModifyRecord(userInfo.getId(), ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid());
|
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(userInfo.getId(), ModifyTypeEnum.bindWeiXin,
|
| | | weiXinUser.getUnionid());
|
| | | }
|
| | | return userInfo;
|
| | | }
|
| | |
| | |
|
| | | @Override
|
| | | public void bindPhoneNew(Long uid, String phone) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null) {
|
| | | throw new UserAccountException(1, "用户不存在");
|
| | | }
|
| | |
| | |
|
| | | // 发送消息
|
| | | userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
|
| | | |
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, phone);
|
| | | |
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void bindWeiXin(Long uid, String code) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | | public void bindWeiXin(AcceptData acceptData, Long uid, String code) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null) {
|
| | | throw new UserAccountException(1, "用户不存在");
|
| | | }
|
| | |
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(2, "微信帐号授权失败");
|
| | | }
|
| | |
| | |
|
| | | // 将默认昵称替换成微信昵称
|
| | | String defaultNickName = Constant.systemCommonConfig.getDefaultNickName();
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getNickname()) && !StringUtil.isNullOrEmpty(defaultNickName)
|
| | | && defaultNickName.equals(user.getNickName())) {
|
| | | updateUserInfo.setNickName(weiXinUser.getNickname());
|
| | | if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
|
| | | defaultNickName = defaultNickName + uid;
|
| | | if ((defaultNickName.equals(user.getNickName()) || "板栗快省".equals(user.getNickName()))) {
|
| | | updateUserInfo.setNickName(weiXinUser.getNickname());
|
| | | }
|
| | | }
|
| | |
|
| | | // 将默认头像替换成微信头像
|
| | |
| | | userAccountBindingHistoryService.addUserAccountBindingHistory(history);
|
| | |
|
| | | userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_WX);
|
| | | |
| | | |
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, wxUnionId);
|
| | | }
|
| | |
|