admin
2024-10-30 010ef2a907e66efd4702443c06cdd18f8a7ffa5b
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
package com.yeshi.buwan.util;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import javax.persistence.Entity;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.system.DetailSystem;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.springframework.context.ApplicationContext;
 
import com.yeshi.buwan.domain.entity.NewVideoDetail;
import com.yeshi.buwan.domain.entity.NewVideoInfo;
import com.yeshi.buwan.domain.entity.VideoResourceVideo;
import com.yeshi.buwan.service.imp.DetailSystemConfigService;
import com.yeshi.buwan.service.imp.UserService;
 
@Entity
public class Utils {
    public static int getPageIndex(String page, int totalPage) {
        int pageIndex = 1;
        if (!StringUtil.isNullOrEmpty(page)) {
            try {
                pageIndex = Integer.parseInt(page);
            } catch (Exception e) {
                pageIndex = 1;
            }
            System.out.print("传入页码:" + pageIndex);
        }
        if (pageIndex >= totalPage)
            pageIndex = totalPage;
        if (pageIndex < 1)
            pageIndex = 1;
        return pageIndex;
    }
 
    /**
     * 存储验证码
     *
     * @param request
     * @param mobile
     * @param verifyCode
     */
    public static void saveVerifyCode(String mobile, HttpSession session, String verifyCode) {
        LogUtil.i("验证码保存--:" + mobile + ":" + verifyCode);
        session.setAttribute(mobile, verifyCode);
    }
 
    /**
     * 获取存储的验证码
     *
     * @param request
     * @param mobile
     * @return
     */
    public static String getVerifyCode(String mobile, HttpSession session) {
        try {
            for (String st : session.getValueNames())
                LogUtil.i("已有的建名称:" + st + "值为:" + session.getAttribute(st));
            return session.getAttribute(mobile) + "";
        } catch (Exception e) {
            return null;
        }
    }
 
    public static String JsonFilter(String st) {
        return st.replace(": null", ": \"\"");
    }
 
    // 短信发送
    public static boolean sendMessage(String mobile, String content) {
        HttpClient client = new HttpClient();
        NameValuePair[] nameValuePairs = new NameValuePair[6];
        nameValuePairs[0] = new NameValuePair("name", "ahwm");
        nameValuePairs[1] = new NameValuePair("pwd", "D47760AE19F823AEB4F53E476BF6");
        nameValuePairs[2] = new NameValuePair("content", content);
        nameValuePairs[3] = new NameValuePair("mobile", mobile);
        nameValuePairs[4] = new NameValuePair("type", "pt");
        nameValuePairs[5] = new NameValuePair("sign", "真惠赚");
 
        PostMethod method = new PostMethod("http://web.cr6868.com/asmx/smsservice.aspx");
        method.setRequestBody(nameValuePairs);
        HttpMethodParams param = method.getParams();
        param.setContentCharset("UTF-8");
        try {
            client.executeMethod(method);
            String responseBodyAsString = method.getResponseBodyAsString();
 
            // 打印发送结果
            System.out.print("***************************短信发送结果:" + responseBodyAsString
                    + "*************************************");
            return true;
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
 
    }
 
    public static long getDay(long time) {
        long d = 86400000;
        return time / d;
    }
 
    public static String getChargeType(int type) {
        String st = "";
        switch (type) {
            case 1:
                st = "Q币";
                break;
            case 2:
                st = "支付宝";
                break;
            case 3:
                st = "财付通";
                break;
            case 4:
                st = "话费充值";
                break;
            case 5:
                st = "实物兑换";
                break;
            case 6:
                st = "银行提现";
                break;
        }
        return st;
    }
 
    public static boolean signIsRight(String sign, String method, String uid, String system) {
        if (sign.equalsIgnoreCase(StringUtil.Md5(method + uid + system)))
            return true;
        else
            return false;
    }
 
    public static boolean signIsRight(HttpServletRequest request) {
        String method = request.getParameter("Method");
        String sign = request.getParameter("Sign");
        String system = request.getParameter("System");
        String uid = request.getParameter("Uid");
        String device = request.getParameter("Device");
        if (!StringUtil.isNullOrEmpty(uid)) {
            if (sign.equalsIgnoreCase(StringUtil.Md5(method + uid + system)))
                return true;
            else
                return false;
        } else {
            if (sign.equalsIgnoreCase(StringUtil.Md5(method + device + system)))
                return true;
            else
                return false;
        }
    }
 
    public static VideoInfoDetail convertVideo(VideoInfo info) {
        if (info == null)
            return null;
        VideoInfoDetail de = new VideoInfoDetail();
        de.setAdmin(info.getAdmin());
        de.setBaseurl(info.getBaseurl());
        de.setBeizhu(info.getBeizhu());
        de.setCreatetime(info.getCreatetime() + "");
        de.setDuration(info.getDuration());
        de.setFinish(info.getFinish());
        de.setId(info.getId());
        de.setIntroduction(info.getIntroduction());
        de.setMainActor(info.getMainActor());
        de.setName(info.getName());
        de.setNowNumber(info.getNowNumber());
        de.setOrderby(info.getOrderby());
        de.setPicture(info.getPicture());
        de.setQulity(info.getQulity());
        de.setScore(info.getScore());
        de.setShow(info.getShow());
        de.setThirdType(Long.parseLong(info.getThirdType()));
        de.setVideoDetailList(info.getVideoDetailList());
        de.setVideoType(info.getVideoType());
        de.setWatchCount(info.getWatchCount());
        de.setYear(info.getYear());
        de.setShare(info.getShare());
        de.setCanSave(info.getCanSave() == null ? false : info.getCanSave());
        de.setResourceList(info.getResourceList());
        de.setPlayPicture(info.getPlayPicture());
        de.setShowType(info.getShowType());
        de.setVpicture(info.getVpicture());
        de.setHpicture(info.getHpicture());
        de.setCommentCount(info.getCommentCount());
        de.setUpdatetime(info.getUpdatetime());
        de.setArea(info.getArea());
        de.setPageSize(info.getPageSize());
        return de;
    }
 
    private static ApplicationContext applicationContext = null;
 
    public static NewVideoInfo convertOldVideoToNew(VideoInfo vi) {
        NewVideoInfo ni = new NewVideoInfo();
        ni.setArea(vi.getArea());
        ni.setBaseurl(vi.getBaseurl());
        ni.setBeizhu(vi.getBeizhu());
        ni.setCanSave(vi.getCanSave());
        ni.setCommentCount(vi.getCommentCount());
        ni.setCreatetime(vi.getCreatetime() + "");
        ni.setDay(vi.getDay());
        ni.setDuration(vi.getDuration());
        ni.setFinish(vi.getFinish());
        ni.setId(vi.getId());
        ni.setIntroduction(vi.getIntroduction());
        ni.setMainActor(vi.getMainActor());
        ni.setMonth(vi.getMonth());
        ni.setName(vi.getName());
        ni.setNowNumber(vi.getNowNumber());
        ni.setOrderby(vi.getOrderby());
        ni.setPicture(vi.getPicture());
        ni.setQulity(vi.getQulity());
        ni.setScore(vi.getScore());
        ni.setShare(vi.getShare());
        ni.setShow(vi.getShow());
        ni.setTag(vi.getTag());
        ni.setThirdType(vi.getThirdType());
        ni.setTotalNumber(vi.getTotalNumber());
        ni.setUpdatetime(vi.getUpdatetime());
        ni.setVideoType(vi.getVideoType());
        ni.setWatchCount(vi.getWatchCount());
        ni.setYear(vi.getYear());
 
        List<VideoResourceVideo> list = new ArrayList<VideoResourceVideo>();
 
        Map<VideoResource, List<NewVideoDetail>> map = new HashMap<VideoResource, List<NewVideoDetail>>();
 
        for (int i = 0; i < vi.getVideoDetailList().size(); i++) {
            VideoDetailInfo detail = vi.getVideoDetailList().get(i);
            for (VideoUrl vu : detail.getUrls()) {
                if (map.get(vu.getResource()) == null) {
                    List<NewVideoDetail> newVD = new ArrayList<NewVideoDetail>();
                    map.put(vu.getResource(), newVD);
                }
                List<NewVideoDetail> nvdList = map.get(vu.getResource());
                NewVideoDetail de = new NewVideoDetail();
                de.setId(detail.getId() + "");
                de.setInvalid(vu.getInvalid());
                de.setTag(detail.getTag());
                de.setUrl(vu.getUrl());
                de.setVideoResource(vu.getResource());
                nvdList.add(de);
            }
        }
 
        Iterator<VideoResource> its = map.keySet().iterator();
        while (its.hasNext()) {
            VideoResource key = its.next();
            VideoResourceVideo vr = new VideoResourceVideo();
            vr.setVideoResource(key);
            vr.setDetailList(map.get(key));
            list.add(vr);
        }
        ni.setResourceDetailList(list);
        return ni;
    }
 
    public static boolean isContains(String detailsystemId) {
        String[] detailsystemIds = new String[]{"1", "2", "3", "4", "5", "6", "14", "12", "20", "11"};
 
        for (String d : detailsystemIds) {
            if (detailsystemId.equalsIgnoreCase(d))
                return true;
        }
 
        return false;
    }
 
    public static boolean isTest(HttpServletRequest request, UserInfo user, String detailSystemId) {
        return false;
        // String ip = getIP(request);
        // if (!(ip + "").equalsIgnoreCase(user.getIp())) {
        // Map<String, String> map = IPUtil.getIPInfo(ip);
        // user.setIp(ip);
        //
        // if (!StringUtil.isNullOrEmpty(map.get("city"))) {
        // user.setCity(map.get("city"));
        // }
        //
        // if (!StringUtil.isNullOrEmpty(map.get("country"))) {
        // user.setCountry(map.get("country"));
        // }
        // new UserService().updateUserInfo(user);
        // }
        //
        // Map<String, String> map = new OtherService().getConfigAsMap();
        // String[] detailsystemIds = new String[] { "1", "2", "3", "4", "5",
        // "6",
        // "14", "12", "20", "11" };
        // for (String d : detailsystemIds) {
        // if (detailSystemId.equalsIgnoreCase(d)) {
        // return true;
        // }
        // }
 
        // return false;
 
    }
 
    public final static int TYPE_NORMAL = 1;
 
    public final static int TYPE_DANGER_AREA = 2;
 
    public final static int TYPE_DANGER = 3;
 
    public static String getCoverImage(VideoInfo info) {
        if (!StringUtil.isNullOrEmpty(info.getLatestHpicture()))
            return info.getLatestHpicture();
        if (!StringUtil.isNullOrEmpty(info.getHpicture()))
            return info.getHpicture();
        return info.getPicture();
    }
 
    public static String getCoverImage(HomeVideo info) {
        if (!StringUtil.isNullOrEmpty(info.getPicture()))
            return info.getPicture();
        else
            return getCoverImage(info.getVideo());
    }
 
}