|
|
@@ -3,16 +3,22 @@ package com.fs.app.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.param.*;
|
|
|
import com.fs.app.utils.JsonUtils;
|
|
|
import com.fs.app.utils.WxUtil;
|
|
|
import com.fs.common.VerifyCodeUtil;
|
|
|
+import com.fs.common.annotation.RateLimiter;
|
|
|
import com.fs.common.annotation.RepeatSubmit;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.enums.LimitType;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.service.ISmsService;
|
|
|
+import com.fs.common.utils.ParseUtils;
|
|
|
import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.ip.IpUtils;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
@@ -20,12 +26,15 @@ import com.fs.core.config.WxOpenProperties;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserNewTask;
|
|
|
+import com.fs.his.domain.FsUserWx;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
+import com.fs.his.mapper.FsUserWxMapper;
|
|
|
import com.fs.his.service.IAppUserRewardService;
|
|
|
import com.fs.his.service.IFsUserNewTaskService;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.his.vo.FsUserRegisterParam;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.watch.domain.WatchDeviceSetup;
|
|
|
import com.fs.watch.domain.WatchUser;
|
|
|
import com.fs.watch.service.WatchUserService;
|
|
|
@@ -73,6 +82,17 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserWxMapper fsUserWxMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService sysConfigService;
|
|
|
+
|
|
|
+ //商城小程序appId配置常量
|
|
|
+ private static final String APP_ID_CONFIG_KEY = "appStore.appId.config";
|
|
|
+
|
|
|
+ private static final String DEFAULT_APP_ID = "wx50bcb040b4963a7e";
|
|
|
@ApiOperation("注册app用户")
|
|
|
@PostMapping("/register")
|
|
|
@RepeatSubmit
|
|
|
@@ -733,6 +753,47 @@ public class AppLoginController extends AppBaseController{
|
|
|
return R.ok("验证码已发送");
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/loginByUnionId")
|
|
|
+ @RateLimiter(time = 60, count = 10, limitType = LimitType.IP)
|
|
|
+ public R loginByUnionId(@RequestBody FsUserUnionIdLoginParam param){
|
|
|
+ if (StringUtils.isEmpty(param.getUnionId()) || StringUtils.isEmpty(param.getOpenId())) {
|
|
|
+ return R.error("unionId或openId不能为空");
|
|
|
+ }
|
|
|
+ FsUser fsUser = userMapper.selectFsUserByUnionid(param.getUnionId());
|
|
|
+ if (ObjectUtil.isEmpty(fsUser)){
|
|
|
+ return R.error("账号不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.equals(fsUser.getMpOpenId(), param.getOpenId())) {
|
|
|
+ int rows = userMapper.updateMpOpenIdByUserId(fsUser.getUserId(), param.getOpenId());
|
|
|
+ if (rows <= 0) {
|
|
|
+ return R.error("绑定openId失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String appid = getAppId();
|
|
|
+ FsUserWx userWx = fsUserWxMapper.selectByAppidAndUserId(appid, fsUser.getUserId());
|
|
|
+ if(userWx == null){
|
|
|
+ FsUserWx userWx1 = new FsUserWx();
|
|
|
+ userWx1.setFsUserId(fsUser.getUserId());
|
|
|
+ userWx1.setAppId(appid);
|
|
|
+ userWx1.setUnionId(param.getUnionId());
|
|
|
+ userWx1.setOpenId(param.getOpenId());
|
|
|
+ userWx1.setType(2);
|
|
|
+ userWx1.setCreateTime(new Date());
|
|
|
+ userWx1.setUpdateTime(new Date());
|
|
|
+ fsUserWxMapper.insert(userWx1);
|
|
|
+ }
|
|
|
+ String token = jwtUtils.generateToken(fsUser.getUserId());
|
|
|
+ redisCache.setCacheObject("userToken:" + fsUser.getUserId(), token, 604800, TimeUnit.SECONDS);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("token", token);
|
|
|
+ if (fsUser.getPhone() != null) {
|
|
|
+ fsUser.setPhone(ParseUtils.parsePhone(fsUser.getPhone()));
|
|
|
+ }
|
|
|
+ map.put("user", fsUser);
|
|
|
+ return R.ok(map);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 添加appId到用户的appId列表中(如果不存在)
|
|
|
* @param currentAppIds 当前用户已有的appId列表(逗号分隔)
|
|
|
@@ -762,4 +823,29 @@ public class AppLoginController extends AppBaseController{
|
|
|
// 不存在,追加到末尾
|
|
|
return currentAppIds + "," + newAppId;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取 appId 的私有方法
|
|
|
+ */
|
|
|
+ private String getAppId() {
|
|
|
+ try {
|
|
|
+ String configValue = sysConfigService.selectConfigByKey(APP_ID_CONFIG_KEY);
|
|
|
+ if (StringUtils.isNotEmpty(configValue)) {
|
|
|
+ JSONObject json = JSONUtil.parseObj(configValue);
|
|
|
+ String appId = json.getStr("appId");
|
|
|
+ if (StringUtils.isNotEmpty(appId)) {
|
|
|
+ return appId;
|
|
|
+ } else {
|
|
|
+ log.warn("配置 {} 中 appId 字段为空,使用默认值", APP_ID_CONFIG_KEY);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("未找到配置 {},使用默认值", APP_ID_CONFIG_KEY);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析 appId 配置异常,configValue={}",
|
|
|
+ sysConfigService.selectConfigByKey(APP_ID_CONFIG_KEY), e);
|
|
|
+ }
|
|
|
+ //默认值
|
|
|
+ return DEFAULT_APP_ID;
|
|
|
+ }
|
|
|
}
|