提交 166e2b76 编写于 作者: dong.an's avatar dong.an

H5登录注册

上级 ee565e7b
流水线 #9864 已失败 于阶段
in 0 second
......@@ -8,12 +8,16 @@ import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.constants.CommonConstants;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import com.pica.cloud.foundation.utils.utils.CommonUtil;
import com.pica.cloud.foundation.utils.utils.EncryptCreateUtil;
import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import com.pica.cloud.foundation.utils.utils.json.Object2Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -21,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
/**
......@@ -75,7 +80,7 @@ public class AccountController extends AccountBaseController {
//已经绑定过云鹊医账号,登录成功,返回token
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
String newToken = this.generateToken(account.getId(), deviceType);
String newToken = this.generateToken(account, deviceType);
return PicaResponse.toResponse(newToken);
}
......@@ -110,7 +115,7 @@ public class AccountController extends AccountBaseController {
//登录成功,清除旧token,生成新token
String deviceType = super.getDeviceInfo("device_type"); //1:pc 2:android 3:ios
String newToken = this.generateToken(account.getId(), deviceType);
String newToken = this.generateToken(account, deviceType);
return PicaResponse.toResponse(newToken);
}
......@@ -138,7 +143,7 @@ public class AccountController extends AccountBaseController {
accountService.createAccount(account); //创建账号
//生成token并返回
String newToken = this.generateToken(account.getId(), deviceType);
String newToken = this.generateToken(account, deviceType);
return PicaResponse.toResponse(newToken);
}
......@@ -189,11 +194,11 @@ public class AccountController extends AccountBaseController {
}
//生成H5 token
private String generateH5Token(Long doctorId) {
private String generateH5Token(Account account) {
String newToken = StringUtils.EMPTY;
try {
//先清除旧token
String tokenValue = "token-doctor-" + doctorId.toString();
String tokenValue = "token-doctor-" + account.getId().toString();
String oldToken = redisClient.get(tokenValue + "-h5");
if (StringUtils.isNotBlank(oldToken)) {
redisClient.del(oldToken);
......@@ -204,6 +209,18 @@ public class AccountController extends AccountBaseController {
String tokenKey = "token-" + newToken;
redisClient.set(tokenKey, tokenValue, expiredSeconds);
redisClient.set(tokenValue + "-h5", tokenKey, expiredSeconds);
//用户数据放入缓存
String userData = redisClient.hget(tokenValue, "id");
if (StringUtils.isEmpty(userData)) {
PicaUser picaUser = new PicaUser();
picaUser.setToken(newToken);
picaUser.setId(account.getId().intValue());
picaUser.setMobile(account.getMobilePhone());
picaUser.setCreated_time(account.getCreatTime());
Map<String, String> data = Object2Map.objectToMapString("yyyy-MM-dd HH:mm:ss", picaUser, new String[0]);
data.put("sysCode", "h5");
data.forEach((key, value) -> {value = value == null ? "" : value; redisClient.hset(tokenValue, key, value);});
}
} catch (Exception ex) {
logger.error("生成H5 token异常:{}" + ex.getMessage(), ex);
}
......@@ -211,7 +228,7 @@ public class AccountController extends AccountBaseController {
}
//清除旧token,生成新token
private String generateToken(Long doctorId, String deviceType) {
private String generateToken(Account account, String deviceType) {
String newToken;
switch (deviceType) { //设备信息
case "1": //pc
......@@ -224,7 +241,7 @@ public class AccountController extends AccountBaseController {
newToken = StringUtils.EMPTY;
break;
default: //H5
newToken = this.generateH5Token(doctorId);
newToken = this.generateH5Token(account);
}
return newToken;
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册