| | |
| | | import javax.servlet.http.HttpSession;
|
| | |
|
| | | import com.yeshi.fanli.entity.SystemEnum;
|
| | | import com.yeshi.fanli.entity.system.BusinessSystem;
|
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.util.*;
|
| | | import com.yeshi.fanli.vo.taobao.TaoBaoUser;
|
| | | import org.springframework.context.annotation.Lazy;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.SystemUtil;
|
| | | import org.yeshi.utils.entity.FileUploadResult;
|
| | | import org.yeshi.utils.entity.ProxyIP;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
| | | import com.google.gson.Gson;
|
| | | import com.qcloud.cos.model.COSObjectSummary;
|
| | | import com.qcloud.cos.model.ObjectListing;
|
| | | 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;
|
| | |
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | // @Resource
|
| | | // private UserInfoMapper userInfoMapper;
|
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | |
| | | @Resource
|
| | | private UserInfoDeleteRecordService userInfoDeleteRecordService;
|
| | |
|
| | |
|
| | | @Resource
|
| | | private JedisPool jedisPool;
|
| | | private ConfigService configService;
|
| | |
|
| | | @Lazy
|
| | | @Resource
|
| | |
| | | LogHelper.lgoinInfo(logInfo.toString());
|
| | |
|
| | | HttpSession session = request.getSession();
|
| | | if (first != null && first == true)
|
| | | if (first != null && first == true) {
|
| | | session.removeAttribute("LAST_LOGIN_USER");
|
| | | // 会话中上次登录的用户
|
| | | }
|
| | | // 会话中上次登录的用户
|
| | | if (wxinstall) {// 安装了微信的状态
|
| | | UserInfo lastUser = (UserInfo) session.getAttribute("LAST_LOGIN_USER");
|
| | | UserInfo userInfo = null;
|
| | |
| | |
|
| | | /**
|
| | | * 根据系统与unionid寻找用户
|
| | | *
|
| | | * @param system
|
| | | * @param unionId
|
| | | * @return
|
| | |
| | |
|
| | |
|
| | | /**
|
| | | *根据系统和淘宝的Openid寻找用户
|
| | | * 根据系统和淘宝的Openid寻找用户
|
| | | *
|
| | | * @param system
|
| | | * @param openId
|
| | | * @return
|
| | |
| | |
|
| | | /**
|
| | | * 根据系统和电话号码寻找用户
|
| | | *
|
| | | * @param system
|
| | | * @param phone
|
| | | * @return
|
| | |
| | | user.setRank(0);
|
| | | if (StringUtil.isNullOrEmpty(user.getPortrait()))
|
| | | user.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
|
| | | userInfoService.createUser(user,user.getSystem());
|
| | | userInfoService.createUser(user, user.getSystem());
|
| | | // 昵称为空时 默认昵称
|
| | | if (StringUtil.isNullOrEmpty(user.getNickName())) {
|
| | | UserInfo updateUserInfo = new UserInfo(user.getId());
|
| | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public UserInfo loginPhone(ProxyIP ipInfo, AcceptData acceptData, int loginType, String vcode, String phone, String appId)
|
| | | public UserInfo loginPhone(ProxyIP ipInfo, int loginType, String vcode, String phone, BusinessSystem businessSystem)
|
| | | throws UserAccountException {
|
| | |
|
| | | // 空额清理
|
| | |
| | | throw new UserAccountException(1, "请输入手机号码");
|
| | | }
|
| | | phone = phone.replaceAll(" ", "");
|
| | | boolean isDemo=false;
|
| | | //查询上线测试的号码与验证码
|
| | | String demoLogin = configService.getValue(ConfigKeyEnum.demoLoginUser, businessSystem.getSystem());
|
| | | if (!StringUtil.isNullOrEmpty(demoLogin)) {
|
| | | String demoPhone = demoLogin.split("#")[0];
|
| | | String demoCode = demoLogin.split("#")[1];
|
| | | if(phone.equalsIgnoreCase(demoPhone)&&demoCode.equalsIgnoreCase(vcode)){
|
| | | isDemo=true;
|
| | | }
|
| | | }
|
| | |
|
| | | // "17316780233".equalsIgnoreCase(phone) && "2581".equalsIgnoreCase(vcode);
|
| | |
|
| | | // 苹果应用商店上线测试号码
|
| | | if ("17316780233".equalsIgnoreCase(phone) && "2581".equalsIgnoreCase(vcode)) {
|
| | | if (isDemo) {//测试号码
|
| | | ;
|
| | | } else {
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(vcode)) {
|
| | | throw new UserAccountException(1, "请输入验证码");
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | | logInfo.put("appId", businessSystem.getAppid());
|
| | | logInfo.put("phone", phone);
|
| | | logInfo.put("loginType", loginType);
|
| | | LogHelper.lgoinInfo(logInfo.toString());
|
| | |
| | |
|
| | | // 采用redis事务防止一个手机号多次注册问题
|
| | | String watchKey = StringUtil.Md5("REGISTER:" + phone);
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = redisManager.getJedis();
|
| | | try {
|
| | | jedis.watch(watchKey);
|
| | | if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
|
| | |
| | | } else {
|
| | |
|
| | | // 查询是否存在该电话历史用户
|
| | | UserInfo userInfo = userInfoService.getEffectiveUserInfoByPhone(phone, SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()));
|
| | | UserInfo userInfo = userInfoService.getEffectiveUserInfoByPhone(phone, businessSystem.getSystem());
|
| | | if (userInfo != null) {
|
| | | // 更新账户登录信息
|
| | | updateLonginInfo(userInfo, loginType, ipInfo);
|
| | | } else {
|
| | | userInfo = new UserInfo();
|
| | | userInfo.setAppId(appId);
|
| | | // userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
|
| | | userInfo.setAppId(businessSystem.getAppid());
|
| | | userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
|
| | | userInfo.setPhone(phone);
|
| | | userInfo.setLoginType(loginType);
|
| | | userInfo.setState(UserInfo.STATE_NORMAL);
|
| | | userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
|
| | | userInfo.setSystem(businessSystem.getSystem());
|
| | | // 创建用户
|
| | | addUser(userInfo);
|
| | |
|
| | |
| | | throw new UserAccountException(10, "请稍后再试");
|
| | | }
|
| | |
|
| | | @Override
|
| | | public UserInfo loginTB(ProxyIP ipInfo, TaoBaoUser taoBaoUser, BusinessSystem businessSystem) throws UserAccountException {
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(taoBaoUser.getUserid()))
|
| | | throw new UserAccountException(1, "淘宝授权信息不完整");
|
| | |
|
| | | UserInfo userInfo = userInfoService.getEffectiveUserInfoByOpenId(taoBaoUser.getOpenId(), businessSystem.getSystem());
|
| | | if (userInfo != null) {
|
| | | // 更新账户登录信息
|
| | | updateLonginInfo(userInfo, 1, ipInfo);
|
| | | } else {
|
| | | userInfo = new UserInfo();
|
| | | userInfo.setNickName(taoBaoUser.getNick());
|
| | | userInfo.setPortrait(taoBaoUser.getAvatarUrl());
|
| | | userInfo.setAppId(businessSystem.getAppid());
|
| | | userInfo.setTaoBaoUid(taoBaoUser.getUserid());
|
| | | userInfo.setOpenid(taoBaoUser.getOpenId());
|
| | | userInfo.setLoginType(1);
|
| | | userInfo.setState(UserInfo.STATE_NORMAL);
|
| | | userInfo.setSystem(businessSystem.getSystem());
|
| | | // 创建用户
|
| | | addUser(userInfo);
|
| | | try {
|
| | | // 第一次登录时创建用户额外信息
|
| | | userInfoExtraService.createUserInfoExtra(userInfo.getId());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | return userInfo;
|
| | | }
|
| | |
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public UserInfo loginPhoneNew(ProxyIP ipInfo, AcceptData acceptData, int loginType, String vcode, String phone, String appId)
|
| | | public UserInfo loginPhoneNew(ProxyIP ipInfo, AcceptData acceptData, int loginType, String vcode, String
|
| | | phone, String appId)
|
| | | throws UserAccountException {
|
| | | // 空额清理
|
| | | if (phone == null || phone.trim().length() == 0) {
|
| | |
| | |
|
| | | // 采用redis事务防止一个手机号多次注册问题
|
| | | String watchKey = StringUtil.Md5("REGISTER:" + phone);
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = redisManager.getJedis();
|
| | | try {
|
| | | jedis.watch(watchKey);
|
| | | if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
|
| | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public UserInfo loginWinXin(ProxyIP ipInfo, AcceptData acceptData, int loginType, String code,
|
| | | String appId) throws UserAccountException {
|
| | | public UserInfo loginWeiXin(ProxyIP ipInfo, int loginType, String code,
|
| | | BusinessSystem businessSystem) throws UserAccountException {
|
| | | // 日志信息
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | | logInfo.put("appId", businessSystem.getAppid());
|
| | | logInfo.put("code", code);
|
| | | logInfo.put("loginType", loginType);
|
| | | LogHelper.lgoinInfo(logInfo.toString());
|
| | |
|
| | | // 通过Code换取信息
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, businessSystem.getWxAppId(), businessSystem.getWxAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(1, "微信帐号授权失败");
|
| | | }
|
| | |
| | |
|
| | | // 采用redis事务防止一个微信号多次注册问题
|
| | | String watchKey = StringUtil.Md5("REGISTER:" + weiXinUser.getUnionid());
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = redisManager.getJedis();
|
| | | try {
|
| | | jedis.watch(watchKey);
|
| | | if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
|
| | |
| | | if (exec == null || exec.size() == 0) {
|
| | | throw new UserAccountException(10, "请稍后再试");
|
| | | } else {
|
| | | UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), SystemInfoUtil.getSystem(acceptData.getPlatform(), acceptData.getPackages()));
|
| | | UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), businessSystem.getSystem());
|
| | | // 直接用的微信登录
|
| | | if (userInfo != null) {
|
| | | LogHelper.test("微信unionID存在:" + weiXinUser.getUnionid());
|
| | | // 更新账户登录信息
|
| | | updateLonginInfo(userInfo, loginType,ipInfo );
|
| | | updateLonginInfo(userInfo, loginType, ipInfo);
|
| | | // 删除邀请分享图
|
| | | spreadUserImgService.deleteImgUrl(userInfo.getId());
|
| | | } else {
|
| | |
| | | // 创建新账户
|
| | | userInfo = new UserInfo();
|
| | | userInfo.setPortrait(portrait);
|
| | | userInfo.setAppId(appId);
|
| | | userInfo.setAppId(businessSystem.getAppid());
|
| | | userInfo.setNickName(weiXinUser.getNickname());
|
| | | userInfo.setWxName(weiXinUser.getNickname());
|
| | | userInfo.setWxOpenId(weiXinUser.getOpenid());
|
| | |
| | | userInfo.setLoginType(loginType);
|
| | | userInfo.setLastLoginIp(ipInfo.getIp());
|
| | | userInfo.setState(UserInfo.STATE_NORMAL);
|
| | | userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
|
| | | userInfo.setSystem(businessSystem.getSystem());
|
| | | addUser(userInfo);
|
| | |
|
| | | try {
|
| | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public UserInfo loginWeiXinNew(ProxyIP ipInfo, AcceptData acceptData, int loginType, String wxCode,
|
| | | String appId) throws UserAccountException {
|
| | | public UserInfo loginWeiXinNew(ProxyIP ipInfo, int loginType, String wxCode,
|
| | | BusinessSystem businessSystem) throws UserAccountException {
|
| | | // 日志信息
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | | logInfo.put("appId", businessSystem.getAppid());
|
| | | logInfo.put("wxCode", wxCode);
|
| | | logInfo.put("loginType", loginType);
|
| | | LogHelper.lgoinInfo(logInfo.toString());
|
| | |
|
| | | // 通过Code换取信息
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, wxAccount.getAppId(), wxAccount.getAppSecret());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, businessSystem.getWxAppId(), businessSystem.getWxAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(1, "微信帐号授权失败");
|
| | | }
|
| | |
| | | throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
|
| | | }
|
| | |
|
| | | UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), SystemInfoUtil.getSystem(acceptData));
|
| | | UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), businessSystem.getSystem());
|
| | | if (userInfo == null) {
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey,
|
| | | StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()));
|
| | |
| | | throw new UserAccountException(2, "您已经绑定了该电话号码");
|
| | | }
|
| | |
|
| | | UserInfo phoneUser = userInfoService.getEffectiveUserInfoByPhone(phone,user.getSystem());
|
| | | UserInfo phoneUser = userInfoService.getEffectiveUserInfoByPhone(phone, user.getSystem());
|
| | | if (phoneUser != null) {
|
| | | throw new UserAccountException(2, "号码已经被占用");
|
| | | }
|
| | |
| | |
|
| | |
|
| | | @Override
|
| | | public UserInfo bindWXToLogin(ProxyIP ipInfo, AcceptData acceptData, String code, String appId, String key) throws UserAccountException {
|
| | | public UserInfo bindWXToLogin(ProxyIP ipInfo, AcceptData acceptData, String code, String appId, String key) throws
|
| | | UserAccountException {
|
| | | // 日志信息
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | |
| | |
|
| | | // 采用redis事务防止一个微信号多次注册问题
|
| | | String watchKey = StringUtil.Md5("REGISTER:" + weiXinUser.getUnionid());
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | Jedis jedis = redisManager.getJedis();
|
| | | try {
|
| | | jedis.watch(watchKey);
|
| | | if (jedis.get(watchKey) != null && Integer.parseInt(jedis.get(watchKey)) > 1)
|