package com.uas.platform.b2b.support;

import org.json.JSONObject;

import com.tencent.xinge.ClickAction;
import com.tencent.xinge.Message;
import com.tencent.xinge.MessageIOS;
import com.tencent.xinge.Style;
import com.tencent.xinge.TimeInterval;
import com.tencent.xinge.XingeApp;

/**
 * 信鸽推送
 * @author suntg
 * @date 2015年3月7日10:01:04
 *
 */
public class XingePusher {
	
	/**
	 * 向单个帐套的单个账号Android设备推送一条信息<p>在Android客户端使用(master+emcode)账号向信鸽注册</p>
	 * @param account 接受者账号（UU号）
	 * @param tittle 推送消息的标题
	 * @param content 推送消息的内容
	 * @param activity 消息点击之后跳转的页面，null或""为默认跳转至主页
	 * @return
	 */
	public static JSONObject pushSingleAccountAndroid(String account, String tittle, String content, String activity) {
		XingeApp xinge = new XingeApp(2100092639, "8dac43ec796c73748fe464ce8d65351e");
		Message message = new Message();
		message.setExpireTime(86400);
		message.setTitle(tittle);//推送信息标题
		message.setContent(content);//推送信息内容（第二行）
		message.setType(Message.TYPE_NOTIFICATION);
		Style style = new Style(0, 1, 1, 1, 0, 1, 0, 0);
		message.setStyle(style);
		ClickAction clickAction = new ClickAction();
		clickAction.setActionType(ClickAction.TYPE_ACTIVITY);
		if(activity != null && !activity.equals("")){
			clickAction.setActivity(activity);
		}
		message.setAction(clickAction);
		JSONObject obj = xinge.pushSingleAccount(0, account, message);//发送给当前的帐套
		return obj;
	};
	
	/**
	 * 向单个帐套的单个账号IOS设备推送一条信息<p>在Android客户端使用(master+emcode)账号向信鸽注册</p>
	 * @param account 接受者账号（UU号）
	 * @param alert 推送消息提示
	 * @return
	 */
	public static JSONObject pushSingleAccountIOS(String account, String alert) {
		XingeApp xinge = new XingeApp(2200088576L, "cdd9696ae38aaeaf766f3c457440d970");
		MessageIOS message = new MessageIOS();
		message.setAlert(alert);
		message.setBadge(1);
		message.setSound("beep.wav");
		TimeInterval acceptTime1 = new TimeInterval(0,0,23,59);
		message.addAcceptTime(acceptTime1);
		JSONObject obj = xinge.pushSingleAccount(0, account, message, XingeApp.IOSENV_DEV);
		return obj;
	};

}
