admin
2019-02-22 e358583d644fa39fc1e93b14b3cafff3644980e4
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package com.yeshi.fanli.system.utils;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import javax.servlet.http.HttpServletRequest;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.taobao.TbImgUtil;
 
import com.yeshi.fanli.base.entity.admin.AdminUser;
 
public class SystemCommonUtils {
 
    private static final String ANDROID = "ANDROID";
    private static final String IOS = "IOS";
    private static final String WEB = "WEB";
 
    private static final Map<String, String> map = new HashMap<String, String>();
 
    static {
        map.put("1", ANDROID);
        map.put("2", IOS);
        map.put("3", WEB);
    }
 
    public static Map<String, String> getMap() {
        return map;
    }
 
    public static boolean isEmailUrlRight(String email, String sign, long time) {
        if (StringUtil.Md5(email + time + "WEIJU2016xxx").equalsIgnoreCase(sign)
                && Math.abs(System.currentTimeMillis() - time) < 1000 * 60 * 60 * 2) {
            return true;
        }
        return false;
    }
 
    public static String getUrlPageTitle(String url) {
        try {
            Document doc = Jsoup.connect(url).timeout(1000 * 60).get();
            return doc.title();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
 
    public static AdminUser getAdminUser(HttpServletRequest request) {
        AdminUser adminUser = (AdminUser) request.getSession().getAttribute("ADMIN_USERINFO");
        return adminUser;
    }
 
    public static boolean signIsRight(String devicename, String imei, String sign) {
        return sign.equalsIgnoreCase(StringUtil.Md5(devicename + imei + "WEIju2016888xx3"));
    }
 
    public static Map<String, Object> sort(Map<String, Integer> map) {
        // 通过ArrayList构�?函数把map.entrySet()转换成list
        List<Map.Entry<String, Object>> list = new ArrayList<Map.Entry<String, Object>>((Collection) map.entrySet());
        // 通过比较器实现比较排�?
        Collections.sort(list, new Comparator<Map.Entry<String, Object>>() {
            public int compare(Map.Entry<String, Object> mapping1, Map.Entry<String, Object> mapping2) {
                return mapping1.getKey().compareTo(mapping2.getKey());
            }
        });
 
        Map<String, Object> newMap = new TreeMap<String, Object>();
        for (Entry<String, Object> entry : list) {
            newMap.put(entry.getKey(), entry.getValue());
        }
        return newMap;
    }
 
 
    public static String imgSize(String jsonStr) {
        JSONObject json = JSONObject.fromObject(jsonStr);
        String picUrl = (String) json.opt("pictUrl");
        if (picUrl.contains("alicdn") || picUrl.contains("tbcdn")) {
            picUrl = TbImgUtil.getTBSize320Img(picUrl);
        }
        json.element("pictUrl", picUrl);
        return json.toString();
    }
 
    public static String imgListSize(String jsonStr) {
        JSONArray json = JSONArray.fromObject(jsonStr);
        for (Object object : json) {
            String picUrl = (String) ((JSONObject) object).opt("pictUrl");
            if (picUrl.contains("alicdn") || picUrl.contains("tbcdn")) {
                picUrl = TbImgUtil.getTBSize320Img(picUrl);
            }
            ((JSONObject) object).element("pictUrl", picUrl);
        }
        return json.toString();
    }
 
    public static Map<String, String> parseURL(String url) {
 
        String URL_REGEX = "(((http|https)://)|(www\\.))[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,4})?(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
        Pattern p = Pattern.compile(URL_REGEX);
        Matcher matcher = p.matcher(url);
        boolean b = matcher.matches();
        Map<String, String> map = new HashMap<String, String>();
        if (!b) {
            return map;
        }
        if (!url.contains("?")) {
            return map;
        }
 
        String params = url.substring(url.indexOf("?") + 1);
        if (params == null || "".equals(params)) {
            return map;
        }
 
        String[] paramArr = params.split("&");
 
        for (String arr : paramArr) {
            String[] kv = arr.split("=");
            if (kv.length == 1) {
                kv[1] = "";
            }
            map.put(kv[0], kv[1]);
        }
 
        return map;
    }
 
    public static double random(double mix) {
        return (Math.random() * 20) + mix;
    }
 
    public static String getStarString(String content, int begin, int end) {
 
        if (begin >= content.length() || begin < 0) {
            return content;
        }
        if (end >= content.length() || end < 0) {
            return content;
        }
        if (begin >= end) {
            return content;
        }
        String starStr = "";
        for (int i = begin; i < end; i++) {
            starStr = starStr + "*";
        }
        return content.substring(0, begin) + starStr + content.substring(end, content.length());
 
    }
 
    public static boolean isNum(String content) {
        if (content == null) {
            return false;
        }
        String regex = "\\d+";
        Pattern compile = Pattern.compile(regex);
        Matcher matcher = compile.matcher(content);
        return matcher.matches();
    }
 
    public static boolean isOrderNum(String order) {
        if (order == null) {
            return false;
        }
        String regex = "\\d{16,}";
        Pattern compile = Pattern.compile(regex);
        Matcher matcher = compile.matcher(order);
        return matcher.matches();
    }
 
    public static boolean isUserOrder(String existOrder, String lostOrder) {
        if (existOrder.length() < 16 || lostOrder.length() < 16) {
            return false;
        }
        String existNum = existOrder.substring(existOrder.length() - 6);
        String lostOrderNum = lostOrder.substring(lostOrder.length() - 6);
 
        if (existNum.equals(lostOrderNum)) {
            return true;
        }
 
        return false;
    }
 
}