java集成vivo推送sdk

测试代码块

/** * vivo推送测试类 * */ public class Vivo { public static final String ALIAS = "ALIAS"; public static final int APP_ID = 123; public static final String APP_KEY = "APP_KEY"; public static final String APP_SECRET = "APP_SECRET"; public static final String AUTH_TOKEN = "authToken"; // 需要推送的用户注册id public static final String REG_ID = ""; public static String getUUID() { return java.util.UUID.randomUUID().toString().toUpperCase().replaceAll("-", ""); } public static void main(String[] args) throws Exception { String test_title = "test_title"; String test_content = "test-content"; Sender sender = new Sender(APP_SECRET);// 注册登录开发平台网站获取到的appSecret Result result = sender.getToken(APP_ID, APP_KEY);// 注册登录开发平台网站获取到的appId和appKey System.out.println("authToken: " + result.getAuthToken()); Sender senderMessage = new Sender(APP_SECRET, result.getAuthToken()); Message singleMessage = new Message.Builder().regId(REG_ID) // 该测试手机设备订阅推送后生成的regId .notifyType(3).title(test_title).content(test_content).timeToLive(1000).skipType(2) .skipContent("http://www.vivo.com").networkType(-1).requestId(getUUID()).build(); Result resultMessage = senderMessage.sendSingle(singleMessage); System.out.println(resultMessage); } // 单推 public static void singeSend() throws Exception { Sender sender = new Sender(APP_SECRET, AUTH_TOKEN); sender.initPool(20, 10);// 设置连接池参数,可选项 Message singleMessage = new Message.Builder().build();// 构建单推消息体 Result result = sender.sendSingle(singleMessage);// 发送单推请求 result.getResult();// 获取服务器返回的状态码,0成功,非0失败 result.getDesc();// 获取服务器返回的调用情况文字描述 result.getTaskId();// 如单推请求发送成功,将获得该条单推消息的任务编号,即taskId } // 保存群推消息 public static void saveListPayload() throws Exception { Sender sender = new Sender(APP_SECRET, AUTH_TOKEN); sender.initPool(20, 10);// 设置连接池参数,可选项 Message saveList = new Message.Builder().build();// 构建要保存的批量推送消息体 Result result = sender.saveListPayLoad(saveList);// 发送保存群推消息请求 result.getResult();// 获取服务器返回的状态码,0成功,非0失败 result.getDesc();// 获取服务器返回的调用情况文字描述 result.getTaskId();// 如请求发送成功,将获得该条消息的任务编号,即taskId } // 批量推送用户 public static void listSend() throws Exception { Sender sender = new Sender(APP_SECRET, AUTH_TOKEN); sender.initPool(20, 10);// 设置连接池参数,可选项 Set<String> regid = new HashSet<>();// 构建批量推送用户群 regid.add("taskId1"); regid.add("taskId2"); TargetMessage targetMessage = new TargetMessage.Builder().build();// 构建批量推送的消息体 Result result = sender.sendToList(targetMessage);// 批量推送给用户 result.getResult();// 获取服务器返回的状态码,0成功,非0失败 result.getDesc();// 获取服务器返回的调用情况文字描述 } // 全量推送 public static void allSend() throws Exception { Sender sender = new Sender(APP_SECRET, AUTH_TOKEN); sender.initPool(20, 10);// 设置连接池参数,可选项 Message allSend = new Message.Builder().build();// 构建要全量推送的消息体 Result result = sender.sendToAll(allSend);// 发送全量推送消息请求 result.getResult();// 获取服务器返回的状态码,0成功,非0失败 result.getDesc();// 获取服务器返回的调用情况文字描述 result.getTaskId();// 如请求发送成功,将获得该条消息的任务编号,即taskId } // 通知栏消息体 public static Message buildMessage() throws Exception { Map<String, String> map = new HashMap<String, String>(); Message message = new Message.Builder() .regId("12345678901234567890123") // 仅构建单推消息体需要 .alias(ALIAS) // 仅构建单推消息体需要 .notifyType(1).title("YOUR_TITLE").content("YOUR_CONTENT").timeToLive(1000).skipType(2) .skipContent("http://www.vivo.com").networkType(-1).clientCustomMap(map).extra("http://www.vivo.com", "vivo") .requestId("1234567890123456").build(); return message; } // 批量推送用户消息体 public static TargetMessage buildTargetMessage() throws Exception { Set<String> regids = new HashSet<>(); regids.add("12345678901234567890123"); regids.add("12345678901234567890321"); Set<String> aliases = new HashSet<>(); aliases.add("ALIAS1"); aliases.add("ALIAS2"); TargetMessage targetMessage = new TargetMessage.Builder().regIds(regids).aliases(aliases).requestId("1234567890123456") .taskId("123456789012345678").build(); return targetMessage; } // 获取消息推送的统计值 public static void testGetStatistics() throws Exception { Sender sender = new Sender(APP_SECRET, AUTH_TOKEN); sender.initPool(20, 10);// 设置连接池参数,可选项 Set<String> taskIds = new HashSet<>(); taskIds.add("123456789012345678"); taskIds.add("123456789087654321"); Result result = sender.getStatistics(taskIds); result.getResult();// 获取服务器返回的状态码,0成功,非0失败 result.getDesc();// 获取服务器返回的调用情况文字描述 result.getStatistics();// 如请求发送成功,将获得各个taskId对应的统计数据 } // 鉴权 public static void testGetToken() throws Exception { Sender sender = new Sender(APP_SECRET);// 实例化Sender sender.initPool(20, 10);// 设置连接池参数,可选项 Result result = sender.getToken(APP_ID, APP_KEY);// 发送鉴权请求 result.getResult();// 获取服务器返回的状态码,0成功,非0失败 result.getDesc();// 获取服务器返回的调用情况文字描述 result.getAuthToken();// 如鉴权请求发送成功,获得authToken } } 

原文链接:https://blog.csdn.net/u013585096/article/details/89479913?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277698816780357211394%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277698816780357211394&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-25-89479913-null-null.nonecase&utm_term=vivo

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片