admin
2021-08-27 8fee151ffae0c3818694b7318583814bf92663e2
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
package com.yeshi.buwan.util.factory.vo;
 
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.domain.user.LoginUserExtra;
import com.yeshi.buwan.domain.vip.UserVIPInfo;
import com.yeshi.buwan.videos.pptv.PPTVUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.vo.client.user.UserInfoVO;
 
public class UserInfoVOFactory {
 
 
    public static UserInfoVO create(LoginUser user, LoginUserExtra extra, UserVIPInfo vipInfo) {
        UserInfoVO vo = new UserInfoVO();
        vo.setId(user.getId());
        vo.setPptvCode(PPTVUtil.getPPTVCode(extra.getPptvUid()));
        vo.setQqNickName(extra.getQqNickName());
        vo.setBirthday(extra.getBirthday());
        vo.setEmail(getHiddenEmail(extra.getEmail()));
        vo.setNickName(user.getName());
        vo.setPhone(getHiddenPhone(user.getPhone()));
        vo.setPortrait(user.getPortrait());
        vo.setQqOpenId(getHiddenOpenId(extra.getQqOpenId()));
        vo.setSex(extra.getSex());
        vo.setSign(extra.getSign());
        if (vipInfo != null && vipInfo.getExpireDate() != null)
            vo.setVipExpireTime(vipInfo.getExpireDate().getTime());
        vo.setWxName(extra.getWxNickName());
        vo.setWxUnionId(getHiddenOpenId(extra.getWxUnionId()));
        return vo;
    }
 
 
    private static String getHiddenPhone(String phone) {
        if (StringUtil.isNullOrEmpty(phone)) {
            return null;
        }
        if (phone.length() < 11) {
            return phone;
        }
        return phone.substring(0, 3) + "****" + phone.substring(phone.length() - 4, phone.length());
    }
 
    private static String getHiddenOpenId(String openId) {
        if (StringUtil.isNullOrEmpty(openId)) {
            return null;
        }
        if (openId.length() < 11) {
            return openId;
        }
        return openId.substring(0, 4) + "****" + openId.substring(openId.length() - 4, openId.length() - 4);
    }
 
    public static String getHiddenEmail(String email) {
        if (StringUtil.isNullOrEmpty(email)) {
            return null;
        }
        int index = email.indexOf("@");
        if (index < 0)
            return null;
 
        String prefix = email.substring(0, index);
        if (prefix.length() < 2)
            return prefix.substring(0, 1) + "**" + email.substring(index, email.length());
        return prefix.substring(0, 2) + "****" + email.substring(index, email.length());
    }
 
 
}