|
|
@@ -3,6 +3,7 @@ package com.fs.app.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.param.*;
|
|
|
import com.fs.app.utils.WxUtil;
|
|
|
@@ -14,10 +15,13 @@ import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.service.ISmsService;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
import com.fs.core.config.WxOpenProperties;
|
|
|
+import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
+import com.fs.course.service.IFsCoursePlaySourceConfigService;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserNewTask;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
+import com.fs.his.service.IFsUserCouponService;
|
|
|
import com.fs.his.service.IFsUserNewTaskService;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
@@ -63,8 +67,14 @@ public class AppLoginController extends AppBaseController{
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFsUserCouponService fsUserCouponService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISmsService smsService;
|
|
|
+ @Autowired
|
|
|
+ private IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
|
|
|
+
|
|
|
@ApiOperation("注册app用户")
|
|
|
@PostMapping("/register")
|
|
|
@RepeatSubmit
|
|
|
@@ -232,8 +242,29 @@ public class AppLoginController extends AppBaseController{
|
|
|
if (StringUtils.isBlank(param.getCode())) {
|
|
|
return R.error("code不存在");
|
|
|
}
|
|
|
- logger.info("zyp app微信登录,param:{},输出appid,{},secret:{}", param, openProperties.getAppId(), openProperties.getSecret());
|
|
|
- Map result = WxUtil.getAccessToken(param.getCode(), openProperties.getAppId(), openProperties.getSecret());
|
|
|
+
|
|
|
+ String appId = param.getAppId();
|
|
|
+ String appSecret = "";
|
|
|
+ if (StringUtils.isBlank(appId)) {
|
|
|
+ List<FsCoursePlaySourceConfig> list = fsCoursePlaySourceConfigService.list(new QueryWrapper<FsCoursePlaySourceConfig>().eq("name", "app").eq("is_del", 0));
|
|
|
+ if(!list.isEmpty()){
|
|
|
+ FsCoursePlaySourceConfig fsCoursePlaySourceConfig = list.get(0);
|
|
|
+ appId = fsCoursePlaySourceConfig.getAppid();
|
|
|
+ appSecret = fsCoursePlaySourceConfig.getSecret();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigService.getOne(new QueryWrapper<FsCoursePlaySourceConfig>().eq("appid", appId).eq("is_del", 0));
|
|
|
+ if(fsCoursePlaySourceConfig != null){
|
|
|
+ appId = fsCoursePlaySourceConfig.getAppid();
|
|
|
+ appSecret = fsCoursePlaySourceConfig.getSecret();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(appId) || StringUtils.isBlank(appSecret)) {
|
|
|
+ appId = openProperties.getAppId();
|
|
|
+ appSecret = openProperties.getSecret();
|
|
|
+ }
|
|
|
+ logger.info("zyp app微信登录,param:{},输出appid,{},secret:{}", param, appId, appSecret);
|
|
|
+ Map result = WxUtil.getAccessToken(param.getCode(),appId,appSecret);
|
|
|
String accessToken = result.get("access_token").toString();
|
|
|
String unionid = result.get("unionid").toString();
|
|
|
|
|
|
@@ -253,12 +284,13 @@ public class AppLoginController extends AppBaseController{
|
|
|
user.setSource(param.getSource()!=null ? param.getSource() : null);
|
|
|
user.setNickName(nickname);
|
|
|
user.setAvatar(avatar);
|
|
|
+ user.setAppOpenId(openid);
|
|
|
if (sex!=0){
|
|
|
user.setSex(sex);
|
|
|
}
|
|
|
user.setUnionId(unionid);
|
|
|
// 新用户 - 添加 appId
|
|
|
- user.setAppId(openProperties.getAppId());
|
|
|
+ user.setAppId(appId);
|
|
|
user.setCreateTime(new Date());
|
|
|
user.setStatus(1);
|
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
@@ -270,7 +302,7 @@ public class AppLoginController extends AppBaseController{
|
|
|
return R.ok(map);
|
|
|
} else {
|
|
|
// 老用户 - 检查并添加appId(不重复添加)
|
|
|
- String updatedAppId = addAppIdIfNotExists(user.getAppId(), openProperties.getAppId());
|
|
|
+ String updatedAppId = addAppIdIfNotExists(user.getAppId(), appId);
|
|
|
if (!updatedAppId.equals(user.getAppId())) {
|
|
|
FsUser userMap = new FsUser();
|
|
|
userMap.setUserId(user.getUserId());
|
|
|
@@ -279,6 +311,7 @@ public class AppLoginController extends AppBaseController{
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
+ user.setAppOpenId(openid);
|
|
|
updateExistingUserJpushId(user, param.getJpushId());
|
|
|
}
|
|
|
if (StringUtils.isEmpty(user.getPhone())) {
|
|
|
@@ -301,6 +334,91 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("苹果登录")
|
|
|
+ @PostMapping("/loginByApple")
|
|
|
+ @Transactional
|
|
|
+ public R loginByApple(@Validated @RequestBody FsUserLoginByAppleParam param) {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(param.getAppleKey())) {
|
|
|
+ return R.error("获取苹果key失败");
|
|
|
+ }
|
|
|
+ // 根据苹果key查询用户
|
|
|
+ FsUser user = userMapper.findUserByAppleKey(param.getAppleKey());
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ if (user == null) {
|
|
|
+ map.put("isNew", true);
|
|
|
+ return R.ok(map);
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
+ updateExistingUserJpushId(user, param.getJpushId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(user.getPhone())) {
|
|
|
+ map.put("isNew", true);
|
|
|
+ return R.ok(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*if (user.getStatus()==0){
|
|
|
+ return R.error("登录失败,账户被禁用");
|
|
|
+ }*/
|
|
|
+ int isFirstLogin = userNewTaskService.performTaskOne(user.getUserId());
|
|
|
+ String token = jwtUtils.generateToken(user.getUserId());
|
|
|
+ redisCache.setCacheObject("userToken:" + user.getUserId(), token, 604800, TimeUnit.SECONDS);
|
|
|
+ map.put("token", token);
|
|
|
+ map.put("user", user);
|
|
|
+ map.put("isFirst",isFirstLogin);
|
|
|
+ return R.ok(map);
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("zyp 苹果登录失败:{}", e.getMessage());
|
|
|
+ return R.error("登录失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private FsUser createNewAppleUser(FsUserEditPhoneParam param, String phoneNumber) {
|
|
|
+ FsUser newUser = new FsUser();
|
|
|
+ newUser.setLoginDevice(param.getLoginDevice()!=null ? param.getLoginDevice() : null);
|
|
|
+ newUser.setSource(param.getSource()!=null ? param.getSource() : null);
|
|
|
+ newUser.setAppleKey(param.getAppleKey());
|
|
|
+ newUser.setPhone(param.getPhone());
|
|
|
+ newUser.setPassword(Md5Utils.hash(param.getPassword()));
|
|
|
+ newUser.setNickName("苹果用户" + param.getPhone().substring(param.getPhone().length() - 4));
|
|
|
+ newUser.setCreateTime(new Date());
|
|
|
+ newUser.setStatus(1);
|
|
|
+ newUser.setAvatar("https://cos.his.cdwjyyh.com/fs/20240926/420728ee06e54575ba82665dedb4756b.png");
|
|
|
+ if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
+ newUser.setJpushId(param.getJpushId());
|
|
|
+ }
|
|
|
+ userService.insertFsUser(newUser);
|
|
|
+ return newUser;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("绑定手机号")
|
|
|
+ @PostMapping("/setIPhoneNumber")
|
|
|
+ public R setIPhoneNumber(@Validated @RequestBody FsUserEditPhoneParam param) {
|
|
|
+ FsUser userMap = findUserByPhone(param.getPhone());
|
|
|
+ if (userMap != null) {
|
|
|
+ if (StringUtils.isNotEmpty(userMap.getAppleKey()) && !param.getAppleKey().equals(userMap.getAppleKey())) {
|
|
|
+ return R.error("该手机号已绑定其他账号");
|
|
|
+ }
|
|
|
+ if (param.getSimExist() == 0 && !Md5Utils.hash(param.getPassword()).equals(userMap.getPassword())) {
|
|
|
+ return R.error("密码不正确");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ userMap = createNewAppleUser(param, param.getPhone());
|
|
|
+ }
|
|
|
+
|
|
|
+ userMap.setLoginDevice(param.getLoginDevice());
|
|
|
+ userMap.setSource(param.getSource());
|
|
|
+ if (userMap.getNickName().equals("匿名用户**")) {
|
|
|
+ userMap.setNickName("苹果用户" + param.getPhone().substring(param.getPhone().length() - 4));
|
|
|
+ }
|
|
|
+ userMap.setAppleKey(param.getAppleKey());
|
|
|
+ if (userService.updateFsUser(userMap)>0){
|
|
|
+ return generateTokenAndReturn(userMap);
|
|
|
+ }
|
|
|
+ return R.error("绑定手机号失败");
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/loginByPhone")
|
|
|
public R loginByPhone(@RequestBody Map<String,String> map){
|
|
|
String phone = map.get("phone");
|
|
|
@@ -368,15 +486,33 @@ public class AppLoginController extends AppBaseController{
|
|
|
FsUser userMap = findUserByPhone(param.getPhone());
|
|
|
//绑定的手机号已存在用户的情况,将微信登录的时候创建的新号的UnionId移动到老号中,删除新号(将两个号合并)
|
|
|
if (userMap!=null){
|
|
|
+ if (userMap.getUserId().equals(user.getUserId())) {
|
|
|
+ user.setPhone(param.getPhone());
|
|
|
+ user.setLoginDevice(param.getLoginDevice());
|
|
|
+ user.setSource(param.getSource());
|
|
|
+ userService.updateFsUser(user);
|
|
|
+ return generateTokenAndReturn(user);
|
|
|
+ }
|
|
|
if (StringUtils.isNotEmpty(userMap.getUnionId())&&!userMap.getUnionId().equals(user.getUnionId())){
|
|
|
return R.error("该手机号已绑定其他微信");
|
|
|
}
|
|
|
- userMap.setLoginDevice(param.getLoginDevice() != null ? param.getLoginDevice() : null);
|
|
|
- userMap.setSource(param.getSource());
|
|
|
- userMap.setUnionId(user.getUnionId());
|
|
|
- if (userService.updateFsUser(userMap)>0){
|
|
|
- userService.realDeleteFsUserByUserId(user.getUserId());
|
|
|
- return generateTokenAndReturn(userMap);
|
|
|
+ //如果存在手机号也有用户,微信也有用户,保留创建时间比较久的用户
|
|
|
+ FsUser keepUser;
|
|
|
+ FsUser deleteUser;
|
|
|
+ if (userMap.getCreateTime().before(user.getCreateTime())){
|
|
|
+ keepUser = userMap;
|
|
|
+ deleteUser = user;
|
|
|
+ }else {
|
|
|
+ keepUser = user;
|
|
|
+ deleteUser = userMap;
|
|
|
+ }
|
|
|
+ keepUser.setLoginDevice(param.getLoginDevice() != null ? param.getLoginDevice() : null);
|
|
|
+ keepUser.setSource(param.getSource());
|
|
|
+ keepUser.setUnionId(user.getUnionId());
|
|
|
+ keepUser.setPhone(param.getPhone());
|
|
|
+ if (userService.updateFsUser(keepUser)>0){
|
|
|
+ userService.realDeleteFsUserByUserId(deleteUser.getUserId());
|
|
|
+ return generateTokenAndReturn(keepUser);
|
|
|
}
|
|
|
return R.error("绑定手机号失败");
|
|
|
}
|
|
|
@@ -414,20 +550,38 @@ public class AppLoginController extends AppBaseController{
|
|
|
FsUser user = findUserByPhone(param.getPhone());
|
|
|
if (user!=null && StringUtils.isEmpty(user.getUnionId())){
|
|
|
FsUser userByUnionId = userMapper.selectFsUserByUnionid(unionid);
|
|
|
- //绑定的微信已存在用户的情况,将手机号一键登录的时候创建的新号的UnionId移动到老号中,删除新号(将两个号合并)
|
|
|
+ //绑定的微信已存在用户的情况,将手机号一键登录的时候创建的新号的手机号移动到老号中,删除新号(将两个号合并)
|
|
|
if (userByUnionId!=null){
|
|
|
if (StringUtils.isNotEmpty(userByUnionId.getPhone())&&!user.getPhone().equals(userByUnionId.getPhone())){
|
|
|
return R.error("该微信已绑定其他手机号");
|
|
|
}
|
|
|
- userByUnionId.setPhone(user.getPhone());
|
|
|
- userByUnionId.setSource(param.getSource() != null ? param.getSource() : null );
|
|
|
- userByUnionId.setLoginDevice(param.getLoginDevice() != null ? param.getLoginDevice() : null);
|
|
|
- userByUnionId.setNickName(nickname);
|
|
|
- userByUnionId.setAvatar(avatar);
|
|
|
- userByUnionId.setSex(sex);
|
|
|
- if (userService.updateFsUser(userByUnionId)>0){
|
|
|
- userService.realDeleteFsUserByUserId(user.getUserId());
|
|
|
- return generateTokenAndReturn(userByUnionId);
|
|
|
+ if (userByUnionId.getUserId().equals(user.getUserId())) {
|
|
|
+ user.setPhone(param.getPhone());
|
|
|
+ user.setLoginDevice(param.getLoginDevice());
|
|
|
+ user.setSource(param.getSource());
|
|
|
+ user.setUnionId(unionid);
|
|
|
+ userService.updateFsUser(user);
|
|
|
+ return generateTokenAndReturn(user);
|
|
|
+ }
|
|
|
+ FsUser keepUser;
|
|
|
+ FsUser deleteUser;
|
|
|
+ if (user.getCreateTime().before(userByUnionId.getCreateTime())){
|
|
|
+ keepUser = user;
|
|
|
+ deleteUser = userByUnionId;
|
|
|
+ } else {
|
|
|
+ keepUser = userByUnionId;
|
|
|
+ deleteUser = user;
|
|
|
+ }
|
|
|
+ keepUser.setUnionId(unionid);
|
|
|
+ keepUser.setPhone(param.getPhone());
|
|
|
+ keepUser.setSource(param.getSource() != null ? param.getSource() : null );
|
|
|
+ keepUser.setLoginDevice(param.getLoginDevice() != null ? param.getLoginDevice() : null);
|
|
|
+ keepUser.setNickName(nickname);
|
|
|
+ keepUser.setAvatar(avatar);
|
|
|
+ keepUser.setSex(sex);
|
|
|
+ if (userService.updateFsUser(keepUser)>0){
|
|
|
+ userService.realDeleteFsUserByUserId(deleteUser.getUserId());
|
|
|
+ return generateTokenAndReturn(keepUser);
|
|
|
}
|
|
|
else {
|
|
|
return R.error("绑定微信失败");
|
|
|
@@ -439,6 +593,7 @@ public class AppLoginController extends AppBaseController{
|
|
|
user.setAvatar(avatar);
|
|
|
user.setSex(sex);
|
|
|
user.setUnionId(unionid);
|
|
|
+ user.setAppOpenId(openid);
|
|
|
if (userService.updateFsUser(user)>0){
|
|
|
return generateTokenAndReturn(user);
|
|
|
}
|
|
|
@@ -458,6 +613,9 @@ public class AppLoginController extends AppBaseController{
|
|
|
FsUser userMap = new FsUser();
|
|
|
userMap.setUserId(user.getUserId());
|
|
|
userMap.setJpushId(jpushId);
|
|
|
+ if (StringUtils.isNotEmpty(user.getAppOpenId())) {
|
|
|
+ userMap.setAppOpenId(user.getAppOpenId());
|
|
|
+ }
|
|
|
userService.updateFsUser(userMap);
|
|
|
}
|
|
|
|