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 getIP(HttpServletRequest request) {
|
String ip = request.getHeader("x-forwarded-for");
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
ip = request.getHeader("Proxy-Client-IP");
|
}
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
}
|
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
ip = request.getHeader("X-Real-IP");
|
}
|
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
ip = request.getRemoteAddr();
|
}
|
|
return ip;
|
|
}
|
|
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());
|
}
|
|
}
|