|
@@ -3,6 +3,7 @@ package com.fs.app.controller;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fs.app.annotation.Login;
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.param.*;
|
|
import com.fs.app.param.*;
|
|
|
import com.fs.app.utils.WxUtil;
|
|
import com.fs.app.utils.WxUtil;
|
|
@@ -14,6 +15,8 @@ import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.service.ISmsService;
|
|
import com.fs.common.service.ISmsService;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
import com.fs.core.config.WxOpenProperties;
|
|
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.config.FsSysConfig;
|
|
|
import com.fs.his.domain.FsUser;
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserNewTask;
|
|
import com.fs.his.domain.FsUserNewTask;
|
|
@@ -65,6 +68,9 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISmsService smsService;
|
|
private ISmsService smsService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
|
|
|
|
|
+
|
|
|
@ApiOperation("注册app用户")
|
|
@ApiOperation("注册app用户")
|
|
|
@PostMapping("/register")
|
|
@PostMapping("/register")
|
|
|
@RepeatSubmit
|
|
@RepeatSubmit
|
|
@@ -232,8 +238,29 @@ public class AppLoginController extends AppBaseController{
|
|
|
if (StringUtils.isBlank(param.getCode())) {
|
|
if (StringUtils.isBlank(param.getCode())) {
|
|
|
return R.error("code不存在");
|
|
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 accessToken = result.get("access_token").toString();
|
|
|
String unionid = result.get("unionid").toString();
|
|
String unionid = result.get("unionid").toString();
|
|
|
|
|
|
|
@@ -253,12 +280,13 @@ public class AppLoginController extends AppBaseController{
|
|
|
user.setSource(param.getSource()!=null ? param.getSource() : null);
|
|
user.setSource(param.getSource()!=null ? param.getSource() : null);
|
|
|
user.setNickName(nickname);
|
|
user.setNickName(nickname);
|
|
|
user.setAvatar(avatar);
|
|
user.setAvatar(avatar);
|
|
|
|
|
+ user.setAppOpenId(openid);
|
|
|
if (sex!=0){
|
|
if (sex!=0){
|
|
|
user.setSex(sex);
|
|
user.setSex(sex);
|
|
|
}
|
|
}
|
|
|
user.setUnionId(unionid);
|
|
user.setUnionId(unionid);
|
|
|
// 新用户 - 添加 appId
|
|
// 新用户 - 添加 appId
|
|
|
- user.setAppId(openProperties.getAppId());
|
|
|
|
|
|
|
+ user.setAppId(appId);
|
|
|
user.setCreateTime(new Date());
|
|
user.setCreateTime(new Date());
|
|
|
user.setStatus(1);
|
|
user.setStatus(1);
|
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
@@ -270,15 +298,16 @@ public class AppLoginController extends AppBaseController{
|
|
|
return R.ok(map);
|
|
return R.ok(map);
|
|
|
} else {
|
|
} else {
|
|
|
// 老用户 - 检查并添加appId(不重复添加)
|
|
// 老用户 - 检查并添加appId(不重复添加)
|
|
|
- String updatedAppId = addAppIdIfNotExists(user.getAppId(), openProperties.getAppId());
|
|
|
|
|
|
|
+ String updatedAppId = addAppIdIfNotExists(user.getAppId(), appId);
|
|
|
if (!updatedAppId.equals(user.getAppId())) {
|
|
if (!updatedAppId.equals(user.getAppId())) {
|
|
|
FsUser userMap = new FsUser();
|
|
FsUser userMap = new FsUser();
|
|
|
userMap.setUserId(user.getUserId());
|
|
userMap.setUserId(user.getUserId());
|
|
|
userMap.setAppId(updatedAppId);
|
|
userMap.setAppId(updatedAppId);
|
|
|
userService.updateFsUser(userMap);
|
|
userService.updateFsUser(userMap);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
|
|
+ user.setAppOpenId(openid);
|
|
|
updateExistingUserJpushId(user, param.getJpushId());
|
|
updateExistingUserJpushId(user, param.getJpushId());
|
|
|
}
|
|
}
|
|
|
if (StringUtils.isEmpty(user.getPhone())) {
|
|
if (StringUtils.isEmpty(user.getPhone())) {
|
|
@@ -301,6 +330,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")
|
|
@PostMapping("/loginByPhone")
|
|
|
public R loginByPhone(@RequestBody Map<String,String> map){
|
|
public R loginByPhone(@RequestBody Map<String,String> map){
|
|
|
String phone = map.get("phone");
|
|
String phone = map.get("phone");
|
|
@@ -358,6 +472,7 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
|
|
@ApiOperation("绑定手机号")
|
|
@ApiOperation("绑定手机号")
|
|
|
@PostMapping("/setPhone")
|
|
@PostMapping("/setPhone")
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R setPhone(@Validated @RequestBody FsUserEditPhoneParam param) {
|
|
public R setPhone(@Validated @RequestBody FsUserEditPhoneParam param) {
|
|
|
logger.info("fcj 绑定手机号入参:{}", param);
|
|
logger.info("fcj 绑定手机号入参:{}", param);
|
|
|
FsUser user = userService.selectFsUserByUnionid(param.getUnionId());
|
|
FsUser user = userService.selectFsUserByUnionid(param.getUnionId());
|
|
@@ -413,6 +528,7 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
|
|
@ApiOperation("绑定微信")
|
|
@ApiOperation("绑定微信")
|
|
|
@PostMapping("/bindWeChat")
|
|
@PostMapping("/bindWeChat")
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R bindWeChat(@Validated @RequestBody FsUserEditUnionidParam param) {
|
|
public R bindWeChat(@Validated @RequestBody FsUserEditUnionidParam param) {
|
|
|
try {
|
|
try {
|
|
|
logger.info("zyp app绑定微信,param:{}", param);
|
|
logger.info("zyp app绑定微信,param:{}", param);
|
|
@@ -473,7 +589,7 @@ public class AppLoginController extends AppBaseController{
|
|
|
user.setAvatar(avatar);
|
|
user.setAvatar(avatar);
|
|
|
user.setSex(sex);
|
|
user.setSex(sex);
|
|
|
user.setUnionId(unionid);
|
|
user.setUnionId(unionid);
|
|
|
-// user.setAppOpenId(openid);
|
|
|
|
|
|
|
+ user.setAppOpenId(openid);
|
|
|
if (userService.updateFsUser(user)>0){
|
|
if (userService.updateFsUser(user)>0){
|
|
|
return generateTokenAndReturn(user);
|
|
return generateTokenAndReturn(user);
|
|
|
}else {
|
|
}else {
|
|
@@ -492,6 +608,9 @@ public class AppLoginController extends AppBaseController{
|
|
|
FsUser userMap = new FsUser();
|
|
FsUser userMap = new FsUser();
|
|
|
userMap.setUserId(user.getUserId());
|
|
userMap.setUserId(user.getUserId());
|
|
|
userMap.setJpushId(jpushId);
|
|
userMap.setJpushId(jpushId);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(user.getAppOpenId())) {
|
|
|
|
|
+ userMap.setAppOpenId(user.getAppOpenId());
|
|
|
|
|
+ }
|
|
|
userService.updateFsUser(userMap);
|
|
userService.updateFsUser(userMap);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -803,12 +922,12 @@ public class AppLoginController extends AppBaseController{
|
|
|
if (StringUtils.isEmpty(newAppId)) {
|
|
if (StringUtils.isEmpty(newAppId)) {
|
|
|
return currentAppIds == null ? "" : currentAppIds;
|
|
return currentAppIds == null ? "" : currentAppIds;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果当前appId为空,直接返回新appId
|
|
// 如果当前appId为空,直接返回新appId
|
|
|
if (StringUtils.isEmpty(currentAppIds)) {
|
|
if (StringUtils.isEmpty(currentAppIds)) {
|
|
|
return newAppId;
|
|
return newAppId;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 检查是否已存在
|
|
// 检查是否已存在
|
|
|
String[] appIdArray = currentAppIds.split(",");
|
|
String[] appIdArray = currentAppIds.split(",");
|
|
|
for (String appId : appIdArray) {
|
|
for (String appId : appIdArray) {
|
|
@@ -817,7 +936,7 @@ public class AppLoginController extends AppBaseController{
|
|
|
return currentAppIds;
|
|
return currentAppIds;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 不存在,追加到末尾
|
|
// 不存在,追加到末尾
|
|
|
return currentAppIds + "," + newAppId;
|
|
return currentAppIds + "," + newAppId;
|
|
|
}
|
|
}
|