package com.tencent.xinge.demo;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;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;import com.tencent.xinge.TagTokenPair;public class Demo {public static void main(String[] args) {// 易用接口System.out.println(XingeApp.pushTokenAndroid(000, "secretKey", "test", "测试", "token"));//System.out.println(XingeApp.pushAccountAndroid(000, "secretKey", "test", "测试", "account"));//System.out.println(XingeApp.pushAllAndroid(000, "secretKey", "test", "测试"));//System.out.println(XingeApp.pushTagAndroid(000, "secretKey", "test", "测试", "tag"));//System.out.println(XingeApp.pushTokenIos(000L, "secretKey", "测试", "token", XingeApp.IOSENV_DEV));//System.out.println(XingeApp.pushAccountIos(000L, "secretKey", "测试", "account", XingeApp.IOSENV_DEV));//System.out.println(XingeApp.pushAllIos(000L, "secretKey", "测试", XingeApp.IOSENV_DEV));//System.out.println(XingeApp.pushTagIos(000L, "secretKey", "测试", "tag", XingeApp.IOSENV_DEV));//Demo示例JSONObject ret;Demo t = new Demo();//ret = t.demoPushSingleDeviceMessage();//System.out.println(ret);////ret = t.demoPushSingleDeviceNotification();//System.out.println(ret);////ret = t.demoPushSingleDeviceIOS();//System.out.println(ret);////ret = t.demoPushSingleAccount();//System.out.println(ret);////ret = t.demoPushAccountList();//System.out.println(ret);////ret = t.demoPushSingleAccountIOS();//System.out.println(ret);////ret = t.demoPushAccountListIOS();//System.out.println(ret);////ret = t.demoPushAllDevice();//System.out.println(ret);////ret = t.demoPushTags();//System.out.println(ret);////ret = t.demoPushAccountListMultiple();//System.out.println(ret);////ret = t.demoPushDeviceListMultiple();//System.out.println(ret);////ret = t.demoQueryPushStatus();//System.out.println(ret);////ret = t.demoQueryDeviceCount();//System.out.println(ret);////ret = t.demoQueryTags();//System.out.println(ret);////ret = t.demoQueryTagTokenNum();//System.out.println(ret);////ret = t.demoQueryTokenTags();//System.out.println(ret);////ret = t.demoCancelTimingPush();//System.out.println(ret);//// ret = t.DemoBatchSetTag();// System.out.println(ret);// // ret = t.DemoBatchDelTag();// System.out.println(ret);// // ret = t.DemoQueryInfoOfToken();// System.out.println(ret);// // ret = t.DemoQueryTokensOfAccount();// System.out.println(ret);//// ret = t.DemoDeleteTokenOfAccount();// System.out.println(ret);//// ret = t.DemoDeleteAllTokensOfAccount();// System.out.println(ret);}//单个设备下发透传消息protected JSONObject demoPushSingleDeviceMessage(){XingeApp xinge = new XingeApp(000, "secret_key");Message message = new Message();message.setTitle("title");message.setContent("content");message.setType(Message.TYPE_MESSAGE);message.setExpireTime(86400);JSONObject ret = xinge.pushSingleDevice("token", message);return ret;}//单个设备下发通知消息protected JSONObject demoPushSingleDeviceNotification(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.pushSingleDevice("token", message1);return (ret);}//单个设备下发通知消息protected JSONObject demoPushSingleDeviceIOS(){MessageIOS message = new MessageIOS();message.setExpireTime(86400);message.setAlert("ios test");message.setBadge(1);message.setSound("beep.wav");TimeInterval acceptTime1 = new TimeInterval(0,0,23,59);message.addAcceptTime(acceptTime1);Map<String, Object> custom = new HashMap<String, Object>();custom.put("key1", "value1");custom.put("key2", 2);message.setCustom(custom);XingeApp xinge = new XingeApp(000L, "secret_key");JSONObject ret = xinge.pushSingleDevice("token", message, XingeApp.IOSENV_DEV);return (ret);}//单个设备下发通知Intent//setIntent()的内容需要使用intent.toUri(Intent.URI_INTENT_SCHEME)方法来得到序列化后的Intent(自定义参数也包含在Intent内)//终端收到后可通过intent.parseUri()来反序列化得到Intentprotected JSONObject demoPushSingleDeviceNotificationIntent(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.pushSingleDevice("token", message2);return (ret);}//下发单个账号protected JSONObject demoPushSingleAccount() {XingeApp xinge = new XingeApp(000, "secret_key");Message message = new Message();message.setExpireTime(86400);message.setTitle("title");message.setContent("content");message.setType(Message.TYPE_MESSAGE);JSONObject ret = xinge.pushSingleAccount(0, "joelliu", message);return (ret);}//下发多个账号protected JSONObject demoPushAccountList() {XingeApp xinge = new XingeApp(000, "secret_key");Message message = new Message();message.setExpireTime(86400);message.setTitle("title");message.setContent("content");message.setType(Message.TYPE_MESSAGE);List<String> accountList = new ArrayList<String>();accountList.add("joelliu");accountList.add("joelliu");JSONObject ret = xinge.pushAccountList(0, accountList, message);return (ret);}//下发IOS单个账号protected JSONObject demoPushSingleAccountIOS() {MessageIOS message = new MessageIOS();message.setExpireTime(86400);message.setAlert("ios test");message.setBadge(1);message.setSound("beep.wav");TimeInterval acceptTime1 = new TimeInterval(0,0,23,59);message.addAcceptTime(acceptTime1);Map<String, Object> custom = new HashMap<String, Object>();custom.put("key1", "value1");custom.put("key2", 2);message.setCustom(custom);XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.pushSingleAccount(0, "joelliu", message, XingeApp.IOSENV_DEV);return (ret);}//下发IOS多个账号protected JSONObject demoPushAccountListIOS() {MessageIOS message = new MessageIOS();message.setExpireTime(86400);message.setAlert("ios test");message.setBadge(1);message.setSound("beep.wav");XingeApp xinge = new XingeApp(000, "secret_key");List<String> accountList = new ArrayList<String>();accountList.add("joelliu");accountList.add("joelliu");JSONObject ret = xinge.pushAccountList(0, accountList, message, XingeApp.IOSENV_DEV);return (ret);}//下发所有设备protected JSONObject demoPushAllDevice(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.pushAllDevice(0, message1);return (ret);}//下发标签选中设备protected JSONObject demoPushTags(){XingeApp xinge = new XingeApp(000, "secret_key");List<String> tagList = new ArrayList<String>();tagList.add("joelliu");tagList.add("phone");JSONObject ret = xinge.pushTags(0, tagList, "OR", message1);return (ret);} //大批量下发给帐号 // iOS 请构造MessageIOS消息protected JSONObject demoPushAccountListMultiple() {XingeApp xinge = new XingeApp(000, "secret_key");Message message = new Message();message.setExpireTime(86400);message.setTitle("title");message.setContent("content");message.setType(Message.TYPE_NOTIFICATION);JSONObject ret = xinge.createMultipush(message);if (ret.getInt("ret_code") != 0) return (ret); else { JSONObject result = new JSONObject(); List<String> accountList1 = new ArrayList<String>(); accountList1.add("joelliu1"); accountList1.add("joelliu2"); // ... result.append("all", xinge.pushAccountListMultiple(ret.getJSONObject("result").getInt("push_id"), accountList1)); List<String> accountList2 = new ArrayList<String>(); accountList2.add("joelliu3"); accountList2.add("joelliu4"); // ... result.append("all", xinge.pushAccountListMultiple(ret.getJSONObject("result").getInt("push_id"), accountList2)); return (result); }}//大批量下发给设备 // iOS 请构造MessageIOS消息protected JSONObject demoPushDeviceListMultiple() {XingeApp xinge = new XingeApp(000, "secret_key");Message message = new Message();message.setExpireTime(86400);message.setTitle("title");message.setContent("content");message.setType(Message.TYPE_NOTIFICATION);JSONObject ret = xinge.createMultipush(message);if (ret.getInt("ret_code") != 0) return (ret); else { JSONObject result = new JSONObject(); List<String> deviceList1 = new ArrayList<String>(); deviceList1.add("joelliu1"); deviceList1.add("joelliu2"); // ... result.append("all", xinge.pushDeviceListMultiple(ret.getJSONObject("result").getInt("push_id"), deviceList1)); List<String> deviceList2 = new ArrayList<String>(); deviceList2.add("joelliu3"); deviceList2.add("joelliu4"); // ... result.append("all", xinge.pushDeviceListMultiple(ret.getJSONObject("result").getInt("push_id"), deviceList2)); return (result); }}//查询消息推送状态protected JSONObject demoQueryPushStatus(){XingeApp xinge = new XingeApp(000, "secret_key");List<String> pushIdList = new ArrayList<String>();pushIdList.add("390");pushIdList.add("389");JSONObject ret = xinge.queryPushStatus(pushIdList);return (ret);}//查询设备数量protected JSONObject demoQueryDeviceCount(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.queryDeviceCount();return (ret);}//查询标签protected JSONObject demoQueryTags(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.queryTags();return (ret);}//查询某个tag下token的数量protected JSONObject demoQueryTagTokenNum(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.queryTagTokenNum("tag");return (ret);}//查询某个token的标签protected JSONObject demoQueryTokenTags(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.queryTokenTags("token");return (ret);}//取消定时任务protected JSONObject demoCancelTimingPush(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.cancelTimingPush("32");return (ret);}// 设置标签protected JSONObject DemoBatchSetTag() { XingeApp xinge = new XingeApp(000, "secret_key"); List<TagTokenPair> pairs = new ArrayList<TagTokenPair>(); // 切记把这里的示例tag和示例token修改为你的真实tag和真实token pairs.add(new TagTokenPair("tag1","token00000000000000000000000000000000001")); pairs.add(new TagTokenPair("tag2","token00000000000000000000000000000000001")); JSONObject ret = xinge.BatchSetTag(pairs); return (ret); } // 删除标签 protected JSONObject DemoBatchDelTag() { XingeApp xinge = new XingeApp(000, "secret_key"); List<TagTokenPair> pairs = new ArrayList<TagTokenPair>(); // 切记把这里的示例tag和示例token修改为你的真实tag和真实token pairs.add(new TagTokenPair("tag1","token00000000000000000000000000000000001")); pairs.add(new TagTokenPair("tag2","token00000000000000000000000000000000001")); JSONObject ret = xinge.BatchDelTag(pairs); return (ret); }//查询某个token的信息protected JSONObject DemoQueryInfoOfToken(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.queryInfoOfToken("token");return (ret);}//查询某个account绑定的tokenprotected JSONObject DemoQueryTokensOfAccount(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.queryTokensOfAccount("nickName");return (ret);}//删除某个account绑定的tokenprotected JSONObject DemoDeleteTokenOfAccount(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.deleteTokenOfAccount("nickName", "token");return (ret);}//删除某个account绑定的所有tokenprotected JSONObject DemoDeleteAllTokensOfAccount(){XingeApp xinge = new XingeApp(000, "secret_key");JSONObject ret = xinge.deleteAllTokensOfAccount("nickName");return (ret);}public Demo(){message1 = new Message();message1.setType(Message.TYPE_NOTIFICATION);Style style = new Style(1);style = new Style(3,1,0,1,0);ClickAction action = new ClickAction();action.setActionType(ClickAction.TYPE_URL);action.setUrl("http://xg.qq.com");Map<String, Object> custom = new HashMap<String, Object>();custom.put("key1", "value1");custom.put("key2", 2);message1.setTitle("title");message1.setContent("大小");message1.setStyle(style);message1.setAction(action);message1.setCustom(custom);TimeInterval acceptTime1 = new TimeInterval(0,0,23,59);message1.addAcceptTime(acceptTime1);message2 = new Message();message2.setType(Message.TYPE_NOTIFICATION);message2.setTitle("title");message2.setContent("通知点击执行Intent测试");style = new Style(1);action = new ClickAction();action.setActionType(ClickAction.TYPE_INTENT);action.setIntent("intent:10086#Intent;scheme=tel;action=android.intent.action.DIAL;S.key=value;end");message2.setStyle(style);message2.setAction(action);}private Message message1;private Message message2;}
下载腾讯信鸽推送(java版)用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论