极光推送案例-PushExample-Jpush
ssh - maven - java项目-极光注冊id完毕推送
这是我学习时的步骤:
1:去极光推送平台注冊账号,自己能够去注冊(一般公司会帮助完毕注冊)
地址:https://www.jpush.cn
2:进入控制台
点击创建应用(不细说,都有说明)
创建应用后会产生:(AppKey : dd1066407b044738b6479275 Master Secret : 2b38ce69b1de2a7fa95706ea)
3:client安装新的应用。会有一个极光注冊id,找他们要就能够了。他们知道是什么东西的(不再多说)
Registration ID :02070ec9ab3
4:pom.xml
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.1.3</version>
</dependency>
5:PushExample
package com.zpms.portal.management.user.action;
import java.util.Collection;
import java.util.LinkedList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.jpush.api.JPushClient;
import cn.jpush.api.common.APIConnectionException;
import cn.jpush.api.common.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.audience.AudienceTarget;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;
public class PushExample {
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);
private static final String appKey ="dd1066407b044738b6479275";
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
public static final String TITLE = "Test from API example";
public static final String ALERT = "Test from API Example - alert";
public static final String MSG_CONTENT = "Test from API Example - msgContent";
public static final String REGISTRATION_ID = "02070ec9ab3";
public static final String TAG = "tag_api";
public static void main(String[] args) {
testSendPush();
}
public static void testSendPush() {
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
// For push, all you need do is to build PushPayload object.
PushPayload payload = buildPushObject_all_registrationid_alert();
/*
* Collection<String> strings = new LinkedList<String>();
* strings.add(REGISTRATION_ID);//配置多个client的极光注冊id
* PushPayload payload = buildPushObject_all_registrationids_alert(strings);
*/
try {
PushResult result = jpushClient.sendPush(payload);
System.out.println("Got result - " + result);
} catch (APIConnectionException e) {
System.out.println("Connection error. Should retry later. " + e);
} catch (APIRequestException e) {
System.out.println("Error response from JPush server. Should review and fix it. " + e);
System.out.println("HTTP Status: " + e.getStatus());
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Error Message: " + e.getErrorMessage());
System.out.println("Msg ID: " + e.getMsgId());
}
}
//发给一个client
public static PushPayload buildPushObject_all_registrationid_alert() {
return PushPayload.newBuilder()
.setPlatform(Platform.all()) //设置平台-全部平台
.setAudience(Audience.registrationId(REGISTRATION_ID)) //设置受众-极光注冊id
.setNotification(Notification.alert(ALERT)) //设置通知 - 消息
.build();
}
//多个client
public static PushPayload buildPushObject_all_registrationids_alert(Collection<String> strings) {
return PushPayload.newBuilder()
.setPlatform(Platform.all()) //设置平台-全部平台
.setAudience(Audience.registrationId(strings)) //设置受众-极光注冊id-多个client
.setNotification(Notification.alert(ALERT)) //设置通知-推送信息
.build();
}
}
------------------------------------------------------------------------------------------------------------------------------------------
參考过的网页:http://www.cnblogs.com/jiqing9006/p/3945095.html
訪问官方站点:http://docs.jpush.io
极光推送案例-PushExample-Jpush的更多相关文章
- 在ionic/cordova中使用极光推送插件(jpush)
Stpe1:创建一个项目(此处使用的是tab类型的项目,创建方式可参照我前一篇如何离线创建Ionic1项目) Stpe2:修改项目信息 打开[config.xml]修改下图内容:
- iOS开发——极光推送
1.到极光官网 https://www.jpush.cn/ 下载极光推送SDK. 具体如何集成最好参考官网的文档,以及一些失败的原因.文档非常详细,我也是参考集成的. 2.到极光推送官网注册自己的应用 ...
- Cordova 集成极光推送
1.申请极光推送账号,创建应用,配置包等信息,可以获得AppKey,用于添加Cordova插件,这部分暂不细讲,根据官网的提示操作就能完成. 2.命令窗口给cordova项目添加极光推送插件 cord ...
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...
- 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)
这次公司要我们做一个功能,就是当用户成功注册以后,他登录以后要收到消息,当然这个消息是安装了我们的手机APP应用的手机咯. 极光推送的网站的网址是:https://www.jpush.cn/ 极光推送 ...
- 极光推送JPush的快速集成
首先到极光推送的官网上创建一个应用,填写对应的应用名和包名. 创建好之后下载Demo 提取Sdk里面的图片和xml等资源文件放自己项目的相应位置,然后要注意的是.so文件的放置位置: 在main目录下 ...
- 极光推送Jpush(v3)服务端PHP版本的api脚本类
原文地址:http://www.dodobook.net/php/780 关于极光推送的上一篇文章已经说明了,此处就不多说了.使用v3版本的原因是v2使用到2014年年底就停止了.点击查看上一篇的地址 ...
- 极光推送Jpush(v3)服务端PHP版本集成(V3版本只调用推送API)
因为版本升级,极光推送的API也有了V3,功能也更丰富了,但是对于我们有的用户来说,我们还是只需要调用推送的API就够了. 下载了一份PHP服务端的SDK(下载地址:http://docs.jpush ...
- 1、Android Studio集成极光推送(Jpush) 报错 java.lang.UnsatisfiedLinkError: cn.jpush.android.service.PushProtoco
Android studio 集成极光推送(Jpush) (华为手机)报错, E/JPush: [JPushGlobal] Get sdk version fail![获取sdk版本失败!] W/Sy ...
随机推荐
- 实战篇之实现 OutLook 中以 EDM 形式发送通知邮件
1.写 Html5 的 EDM 模板 EDM 源代码示例: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ...
- mysql触发器的操作
一.创建触发器 1.创建有一条执行语句的触发器 CREATE TRIGGER trigger_name BEFORE|AFTER trigger_EVENT(INSERT|DELETE|UPDATE) ...
- C++中 list与vector的区别
引用http://www.cnblogs.com/shijingjing07/p/5587719.html C++ vector和list的区别 1.vector数据结构vector和数组类似,拥有一 ...
- Android项目实战_手机安全卫士手机防盗界面
#安全卫士手机防盗# ###1.Activity的任务栈 1.类似一个木桶,每层只能放一个木块,我们放入木块和取出木块的时候只能从最上面开始操作 ###2.Android中的坐标系 在二元操作符中,除了指数操作符 “^” 和连接操作符 “..” 是 ”右结合” 的,是所有其他操作符都是 “左结合” 的.因此如 ...
- js 简单模板引擎
代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" cont ...
- Promise嵌套问题/async await执行顺序
/* 原则: 执行完当前promise, 会把紧挨着的then放入microtask队尾, 链后面的第二个then暂不处理分析, */ 一. new Promise((resolve, reject) ...
- [luogu3155 CQOI2009] 叶子的染色(树形dp)
传送门 Solution 十分简单的树形dpQwQ,转移关系:父亲染了儿子不用染 只需要确定根就是简单树形dp,而其实根可以随便取一个非叶子节点 可以分情况讨论发现答案并不会改变 Code //By ...