86183
2022-09-09 0d999e33085c0a25c5525242748f6aa62a401159
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cn.mb.cloud.auth.security.social.handler;
 
import cn.mb.cloud.auth.security.entity.User;
import cn.mb.cloud.auth.security.service.IUserService;
import cn.mb.cloud.common.api.vo.UserVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
 
/**
 * @author jason
 * @date 2018/11/18
 */
@Slf4j
@Component("WX")
@AllArgsConstructor
public class WeChatLoginHandler extends AbstractLoginHandler {
 
    private final IUserService userService;
 
    /**
     * 微信登录传入code
     * <p>
     * 通过code 调用qq 获取唯一标识
     *
     * @param code
     * @return
     */
    @Override
    public String identify(String code) {
        /*SysSocialDetails condition = new SysSocialDetails();
        condition.setType(LoginTypeEnum.WECHAT.getType());
        SysSocialDetails socialDetails = sysSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
 
        String url = String.format(SecurityConstants.WX_AUTHORIZATION_CODE_URL, socialDetails.getAppId(),
                socialDetails.getAppSecret(), code);
        String result = HttpUtil.get(url);
        log.debug("微信响应报文:{}", result);
        Object obj = JSONUtil.parseObj(result).get("openid");*/
        return code;
    }
 
    /**
     * openId 获取用户信息
     *
     * @param openId
     * @return
     */
    @Override
    @SneakyThrows
    public UserVO info(String openId, String threeAvatar, String threeName) {
      /*  String threeName = WebUtils.getRequest().getParameter("nickname");
        String threeAvatar = WebUtils.getRequest().getParameter("iconurl");*/
 
        User user = null;
        user = userService.getOne(Wrappers.<User>query().lambda().
                eq(User::getOpenId, openId).
                eq(User::getDelFlag, 0));
        if (user == null) {
            //注册
 
        }
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        if (StringUtils.isEmpty(user.getUsername())) {
            userVO.setUsername(user.getOpenId());
        }
        return userVO;
    }
}