|
@@ -1,11 +1,22 @@
|
|
|
package com.mokamrp.privates.service.impl;
|
|
package com.mokamrp.privates.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.mokamrp.privates.constant.Constants;
|
|
|
|
|
+import com.mokamrp.privates.constant.RedisKey;
|
|
|
import com.mokamrp.privates.mapper.pojo.User;
|
|
import com.mokamrp.privates.mapper.pojo.User;
|
|
|
import com.mokamrp.privates.mapper.UserMapper;
|
|
import com.mokamrp.privates.mapper.UserMapper;
|
|
|
import com.mokamrp.privates.service.UserService;
|
|
import com.mokamrp.privates.service.UserService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.mokamrp.privates.utils.StringUtils;
|
|
|
|
|
+import com.mokamrp.privates.utils.sign.Md5Utils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* <p>
|
|
* <p>
|
|
|
* 企微小平台系统临时账户 服务实现类
|
|
* 企微小平台系统临时账户 服务实现类
|
|
@@ -16,5 +27,30 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ public StringRedisTemplate redis;
|
|
|
|
|
|
|
|
|
|
+ public Map<String, Object> doLogin(String phone, String password) {
|
|
|
|
|
+ Map<String, Object> res =this.getMap(new QueryWrapper<User>().eq("phone", phone));
|
|
|
|
|
+ //.验证账户名和密码
|
|
|
|
|
+ if (res.isEmpty()) {
|
|
|
|
|
+ res.put("loginStatus", "phoneNull");
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+ Object nowPass = res.get("password");
|
|
|
|
|
+ if (!nowPass.toString().equals(password)) {
|
|
|
|
|
+ res.put("loginStatus", "passwordErr");
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+ //.登录信息缓存到redis,过期时间5小时
|
|
|
|
|
+ String userMd5 = Md5Utils.hash(phone);
|
|
|
|
|
+ String token = userMd5 + "_" + StringUtils.getRandomString(10);
|
|
|
|
|
+ res.remove("password");
|
|
|
|
|
+ String userInfoStr = JSON.toJSONString(res);
|
|
|
|
|
+ redis.opsForValue().set(RedisKey.AuthToken + token, userInfoStr);
|
|
|
|
|
+ redis.expire(RedisKey.AuthToken + token, Constants.TOKEN_EXPIRATION, TimeUnit.SECONDS);
|
|
|
|
|
+ res.put("token", token);
|
|
|
|
|
+ res.put("loginStatus", "loginSuccess");
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|