WebUtils

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
//	 * @return
	public 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值