liuxiaolong
2019-05-06 a7bed6b4cfecd61ec153818945f982c5bb796b98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.cloud.attendance.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.cloud.common.exception.ApplicationException;
 
import com.cloud.common.utils.RequestUtil;
import com.cloud.model.sys.LoginAppUser;
import com.cloud.attendance.service.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
 
 
@Slf4j
@Component
@Service
public class TokenServiceImpl implements TokenService {
 
    @Autowired
    private  StringRedisTemplate stringRedisTemplate;
 
 
    @Override
    public LoginAppUser currentUser() {
 
        // 请求参数中包含access_token参数
        String token = RequestUtil.getTokenByParam();
        if(token == null){
            throw new ApplicationException("not found token");
        }
        String s_user = stringRedisTemplate.opsForValue().get(token);
 
        LoginAppUser user = JSONObject.parseObject(s_user, LoginAppUser.class);
 
        return user;
    }
 
    @Override
    public LoginAppUser currentUserByToken(String token) {
        String s_user = stringRedisTemplate.opsForValue().get(token);
        LoginAppUser user = JSONObject.parseObject(s_user, LoginAppUser.class);
 
        return user;
    }
 
 
 
}