登录部分

This commit is contained in:
wangw 2024-06-22 11:26:07 +08:00
parent 941c33ea7a
commit d86463155d
3 changed files with 29 additions and 9 deletions

View File

@ -320,18 +320,21 @@ public class LoginContoller {
@PostMapping("/app/login")
public Result applogin(@RequestBody AuthUserDto authUserDto) {
boolean tf = false;
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(authUserDto.getOpencode(), customAppId, customSecrete);
// 3.接收微信接口服务 获取返回的参数
String openid = SessionKeyOpenId.getString("openid");
if (ObjectUtil.isNull(authUserDto.getCode())) {
if (StringUtils.isBlank(authUserDto.getPassword())) {
return Result.fail("请输入密码,或使用验证码登录");
}
//验证密码
String mdPasswordString = MD5Utils.MD5Encode(authUserDto.getPassword(), "utf-8");
return loginService.appLogin(authUserDto.getUsername(), mdPasswordString);
return loginService.appLogin(authUserDto.getUsername(),openid, mdPasswordString);
} else {
// tf = true;
tf = loginService.validate(authUserDto.getCode(), authUserDto.getUsername());
if (tf) {
return loginService.appLogin(authUserDto.getUsername(), null);
return loginService.appLogin(authUserDto.getUsername(),openid, null);
} else {
return Result.fail("验证码输入有误");
}

View File

@ -13,6 +13,7 @@ public class AuthUserDto {
private String password;
private String code;
private String opencode;
private String uuid = "";
@ -47,4 +48,12 @@ public class AuthUserDto {
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getOpencode() {
return opencode;
}
public void setOpencode(String opencode) {
this.opencode = opencode;
}
}

View File

@ -178,7 +178,7 @@ public class LoginService {
* @param nickName
* @return
*/
public TbUserInfo register(String phone, String password, String nickName) {
public TbUserInfo register(String phone, String openId,String password, String nickName) {
TbUserInfo userInfo = new TbUserInfo();
userInfo.setAmount(BigDecimal.ZERO);
@ -202,6 +202,9 @@ public class LoginService {
userInfo.setLastLogInAt(System.currentTimeMillis());
userInfo.setCreatedAt(System.currentTimeMillis());
userInfo.setUpdatedAt(System.currentTimeMillis());
userInfo.setMiniAppOpenId(openId);
userInfo.setIsPwd("0");
userInfo.setPwd(MD5Utils.md5("123456"));
if (StringUtils.isNotBlank(password)) {
userInfo.setPassword(MD5Utils.MD5Encode(password, "UTF-8"));
}
@ -234,14 +237,19 @@ public class LoginService {
}
@Transactional(rollbackFor = Exception.class)
public Result appLogin(String username, String password) {
public Result appLogin(String username,String openId, String password) {
TbUserInfo userInfo = tbUserInfoMapper.selectByPhone(username);
if (ObjectUtil.isNull(userInfo)) {
if (StringUtils.isNotBlank(password)) {
return Result.fail("暂未设置密码,请使用验证码登录");
}
userInfo = register(username, password, username);
userInfo = register(username,openId, password, username);
} else {
if (StringUtils.isNotBlank(userInfo.getMiniAppOpenId())) {
if (!userInfo.getMiniAppOpenId().equals(openId)) {
userInfo.setMiniAppOpenId(openId);
}
}
String searchWord = userInfo.getSearchWord();
if (!searchWord.contains("移动端用户")) {
userInfo.setSearchWord(userInfo.getSearchWord() + "||移动端用户");
@ -268,10 +276,10 @@ public class LoginService {
try {
map.put("token", token);
map.put("userInfo", userInfo);
if(StringUtils.isNotBlank(userInfo.getMiniAppOpenId())){
redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getMiniAppOpenId()), JSON.toJSONString(map),60*60*24*30L);
}else {
redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L);
if (StringUtils.isNotBlank(userInfo.getMiniAppOpenId())) {
redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getMiniAppOpenId()), JSON.toJSONString(map), 60 * 60 * 24 * 30L);
} else {
redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map), 60 * 60 * 24 * 30L);
}
// redisUtil.saveMessage(RedisCst.ONLINE_APP_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L);
return Result.success(CodeEnum.SUCCESS, map);