WebUtils

来源:互联网 发布:python实现rfm模型 编辑:程序博客网 时间:2024/05/17 22:07
package com.xhrd.util;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.List;import java.util.UUID;import javax.servlet.http.HttpServletRequest;import org.springframework.web.context.request.RequestContextHolder;import org.springframework.web.context.request.ServletRequestAttributes;import cn.walle.framework.core.support.SystemConfig;import com.chase.push.PushClient;import com.chase.push.constants.Constants;import com.chase.push.constants.RspCodeConstants;import com.chase.push.interbean.rsp.SendNotificationRspBean;import com.xhrd.common.SessionContextUserEntity;import com.xhrd.mail.MailSenderInfo;import com.xhrd.mail.SimpleMailSender;/** *  * Web工具类 * @author sigangjun * */public class WebUtils {public static String getWebDate() {Calendar cal = Calendar.getInstance();int hour = cal.get(Calendar.HOUR_OF_DAY);if (hour >= 6 && hour < 8) {return ("早上好");} else if (hour >= 8 && hour < 11) {return ("上午好");} else if (hour >= 11 && hour < 13) {return ("中午好");} else if (hour >= 13 && hour < 18) {return ("下午好");} else {return ("晚上好");}}public static HttpServletRequest getRequest() {return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();}public static String getRealPath() {return getRequest().getRealPath("");}public static String getWebPath() {return "/"+SystemConfig.PROJECT_NAME+"";//return "/";}/** * 获取当前用户的ID * @return */public static Long getCurrentUserId() {return Long.parseLong(SessionContextUserEntity.currentUser().getUserId());}/** * 获取当前用户的ID * @return */public static SessionContextUserEntity getCurrentUser() {return SessionContextUserEntity.currentUser();}// * @param sendno 发送标识,如果标识相同并且客户端未查看,则客户端覆盖上一条发送标识相同的消息 必填// * @param usernames 用户名 多个设备号用英文的“,”分割  必填  eg. 4354546565657,435454645645431 // * @param msgType 消息类型 1 简单消息, 此类型消息客户端直接显示;  2 用户自定义消息 必填// * @param msgContent 消息内容 必填// * @param isTxi 是否即时传输 必填// * @param sendTime 发送时间 如果 isTxi=true 发送时间非必填,否则必填// * @param os 操作系统 必填  eg. new String[] { Constants.OS_ANDROID, Constants.OS_IOS }// * @param timeToLive 离线存活时间 单位 s 非必填,默认值:864000L(10天)// * @param isNeedCallback 是否需要回调 true 是 false 否 默认false// * @returnpublic static void sendMsg(String user_ids,String msg){PushClient client = new PushClient("fanspad.push.weiba.cn", 8085, "4aea47a23f552dfd013f552f71f10000");try {//===发送用户消息=======================================================================SendNotificationRspBean rspBean5 = null;rspBean5 = client.sendNotificationWithSpecificUser(UUID.randomUUID().toString(), user_ids, Constants.NOTIFICATION_MSG_TYPE_SIMPLE, msg, true, null, new String[] { Constants.OS_ANDROID, Constants.OS_IOS }, null, false);System.out.println("状态码:" + rspBean5.getRspHeader().getRspCode());if (RspCodeConstants.RSP_CODE_SUCCESS.equals(rspBean5.getRspHeader().getRspCode()))System.out.println("成功"); } catch (Exception e) {e.printStackTrace();}}public static void sendEmail(String subject,String content,String addr){MailSenderInfo mailInfo = new MailSenderInfo();mailInfo.setMailServerPort("25");mailInfo.setValidate(true);//mailInfo.setMailServerHost("mail.datang.com");//mailInfo.setUserName("serviced01@datang.com");//mailInfo.setPassword("20110117");//mailInfo.setFromAddress("serviced01@datang.com");mailInfo.setMailServerHost("smtp.163.com");mailInfo.setUserName("xhrd_service@163.com");mailInfo.setPassword("xhrd_service123");mailInfo.setFromAddress("xhrd_service@163.com");mailInfo.setToAddress(addr);mailInfo.setSubject(subject);mailInfo.setContent(content);// 这个类主要来发送邮件SimpleMailSender sms = new SimpleMailSender();//sms.sendTextMail(mailInfo);// 发送文体格式sms.sendHtmlMail(mailInfo);// 发送html格式}public static void main(String[] args) {//List<Long> ids = new ArrayList<Long>();//ids.add(1L);//ids.add(2L);//sendMsg(ids, "你好");sendEmail("测试222", "哈哈222,测试内容2", "rzxiaosi@vip.qq.com");}public static String genVoiceFileName(){Long curid = getCurrentUserId();SimpleDateFormat frm = new SimpleDateFormat("yyyyMMddHHmmssSSS");String fname = curid+"_"+frm.format(new Date());return fname;}}

0 0
原创粉丝点击