|
|
@@ -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,6 +15,8 @@ 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;
|
|
|
@@ -69,6 +72,9 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
@Autowired
|
|
|
private ISmsService smsService;
|
|
|
+ @Autowired
|
|
|
+ private IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
|
|
|
+
|
|
|
@ApiOperation("注册app用户")
|
|
|
@PostMapping("/register")
|
|
|
@RepeatSubmit
|
|
|
@@ -236,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();
|
|
|
|
|
|
@@ -257,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())) {
|
|
|
@@ -274,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());
|
|
|
@@ -283,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())) {
|
|
|
@@ -305,7 +334,6 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@ApiOperation("苹果登录")
|
|
|
@PostMapping("/loginByApple")
|
|
|
@Transactional
|
|
|
@@ -323,12 +351,6 @@ public class AppLoginController extends AppBaseController{
|
|
|
} else {
|
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
updateExistingUserJpushId(user, param.getJpushId());
|
|
|
- try {
|
|
|
- //发送注册优惠券
|
|
|
- fsUserCouponService.sendRegisterCoupon(user);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("发送注册优惠券失败:{}",e.getMessage());
|
|
|
- }
|
|
|
}
|
|
|
if (StringUtils.isEmpty(user.getPhone())) {
|
|
|
map.put("isNew", true);
|
|
|
@@ -351,6 +373,52 @@ public class AppLoginController extends AppBaseController{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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");
|
|
|
@@ -525,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);
|
|
|
}
|
|
|
@@ -544,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);
|
|
|
}
|
|
|
|