app推送-极光推送

会不会有小伙伴一脸懵逼,问我什么是App推送?android

先甩一个熟悉的界面。这些就是推送。ios

file

这些推送有什么做用呢,我百度百科了一下好处程序员

作过app开发的都应该接触到app推送。如今安卓推送 app只要是后台进程被杀死用户是是接受不到的。ios推送是没有问题的,由于ios只有一个厂家使用的系统 而安卓虽然也是只是一个系统可是可是被不少厂商修改了底层。这个时候若是你的老板给你一个需求让你作app推送,保证app推送用户百分百接收到,那么你就能够辞职了。你和安卓一块辞职。是否是想一想均可怕。原来咱们公司是这么作的,当app被锁屏的时候留一个一像素的点,保证app随时存活,可是如今不能够了 只要清理了,app就会被杀死。

file

这个时候小伙伴就有人问我了,这个就没办法解决了么???????????

file

如今能够集成各大厂商都本身研发的推送方式,好比小米推送、华为推送。他们本身推送确定在本身的手机能收到,还有就是只要你有钱什么都能解决。。。。。web

file

哈哈哈哈 对的 你只要给各大厂商钱就能够开启白名单通道,若是你是安卓你就能够看到,即便你把某些app进程给杀死了可是呢,依然还有烦人的推送,据据说腾讯是超牛逼的,这话怎么讲,腾讯微信是确定在白名单的不用想。可是呢,人家有本身开发的推送方式,只要腾讯有一个app是活着的,他就能把全部的腾讯产品拉起来,(这个时候小伙伴会问我什么是拉起来,我解释一下拉起来的含义就是能让某些app本身启动)是否是难以想象哈哈哈哈。今天咱们要说的是极光推送,只要所有app都是极光推送,大家的app就是活着的,But极光是靠这个收费的,具体怎么收费我给大家甩一个官网。

点我进极光官网--小程序用户直接百度极光推送spring

给你们说一个好消息 工信部已经联合了国内多家厂商要作统一推送服务,若是那一天真的到来那么对于广大国内开发者将会受益巨大。官网网址:http://chinaupa.com/

file

我给你们的解决方案能够参考一下:
  目前解决推送问题通用的解决办法是采用混合推送机制,对于有提供系统推送的厂商走厂商推送,其他的走第三方                       推送。好比极光
系统级别的推送就是根据手机型号进行推送,判断用户手机型号进行分别进行sdk的切换。
对于没有提供系统级推送的厂商那么只能本身经过保活机制维持一个常驻后台进程来实现。不过厂商为了系统纯净对后台进程作了严格限制,致使目前的进程保活机制面临几乎无解的问题。
最后咱们一块儿期待工信部的推送尽快与你们见面。。

今天说一下app极光推送后端逻辑小程序

老规矩先扔极光推送文档的地址。 点我快速进入极光推送文档地址 极光不只能推送还能看到app多少日活,有的投资人不看大家app后台的数据,就看极光友盟之类的第三方插件的数据 file后端

咱们从demo看起,这是手动推送的界面。很简洁。 file 可是呢,咱们身为高级程序员怎么可能用这种方法。 fileapi

好嘞这个没有什么流程就给请求极光就能够了。甩一个工具类。服务器

pom文件 若是是maven项目直接引入 若是是web项目须要从官网下载jar包

  <!-- 极光推送 -->
	  <dependency>
		  <groupId>cn.jpush.api</groupId>
		  <artifactId>jpush-client</artifactId>
		  <version>3.3.7</version>
	  </dependency>
	 

package cn.cnbuilder.util;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
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.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosAlert;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;

/** 
 * 说明:极光推送工具类
 * @version
 * KingYiFan
 */
@Controller
@RequestMapping(value="/jpush")
public class JPushClientUtil{
	//极光后台管理系统申请
	private static final String appKey = "xxxxx";
	private static final String masterSecret = "xxxxx";
	public static final int MAX = Integer.MAX_VALUE;
	public static final int MIN = MAX / 2;
	 private static JPushClient jPushClient = new JPushClient(masterSecret,appKey);
	
	/**
	 * 保存离线的时长。秒为单位。最多支持10天(864000秒)。 
	 * 0 表示该消息不保存离线。即:用户在线立刻发出,当前不在线用户将不会收到此消息。
	 * 此参数不设置则表示默认,默认为保存1天的离线消息(86400秒)。
	 */
	private static long timeToLive = 60 * 60 * 24;
	public static void main(String[] args) {
		String msgTitle = "测试推送,你是KingYiFan,哈哈哈!!!";
		String msgContent = "看到信息了么,看到就推送成功了!";
		String userid="用户别名";
		JPushClientUtil.sendToAll("最新文章",msgTitle, "WZ", userid);
	}
	/**
	 * 保持 sendNo 的惟一性是有必要的
	 */
	public static int getRandomSendNo() {
		return (int) (MIN + Math.random() * (MAX - MIN));
	}
    /**
     * 推送给设备标识参数的用户
     * @param registrationId 设备标识
     * @param notification_title 通知内容标题
     * @param msg_title 消息内容标题
     * @param msg_content 消息内容
     * @param extrasparam 扩展字段
     * @return 0推送失败,1推送成功
     */
    public static int sendToRegistrationId( String registrationId,String notification_title, String msg_title, String msg_content, String extrasparam,String extrasparam2) {
        int result = 0;
        try {
            PushPayload pushPayload= JPushClientUtil.buildPushObject_all_registrationId_alertWithTitle(registrationId,notification_title,msg_title,msg_content,extrasparam,extrasparam2);
            System.out.println(pushPayload);
            PushResult pushResult=jPushClient.sendPush(pushPayload);
            System.out.println(pushResult);
            if(pushResult.getResponseCode()==200){
                result=1;
            }
        } catch (APIConnectionException e) {
            e.printStackTrace();
 
        } catch (APIRequestException e) {
            e.printStackTrace();
        }
 
         return result;
    }
 
    /**
     * 发送给全部安卓用户
     * @param notification_title 通知内容标题
     * @param msg_title 消息内容标题
     * @param msg_content 消息内容
     * @param extrasparam 扩展字段
     * @return 0推送失败,1推送成功
     */
    public static int sendToAllAndroid( String notification_title, String msg_title, String msg_content, String extrasparam) {
        int result = 0;
        try {
            PushPayload pushPayload= JPushClientUtil.buildPushObject_android_all_alertWithTitle(notification_title,msg_title,msg_content,extrasparam);
            System.out.println(pushPayload);
            PushResult pushResult=jPushClient.sendPush(pushPayload);
            System.out.println(pushResult);
            if(pushResult.getResponseCode()==200){
                result=1;
            }
        } catch (Exception e) {
 
            e.printStackTrace();
        }
 
         return result;
    }
 
    /**
     * 发送给全部IOS用户
     * @param notification_title 通知内容标题
     * @param msg_title 消息内容标题
     * @param msg_content 消息内容
     * @param extrasparam 扩展字段
     * @return 0推送失败,1推送成功
     */
    public static int sendToAllIos(String notification_title, String msg_title, String msg_content, String extrasparam) {
        int result = 0;
        try {
            PushPayload pushPayload= JPushClientUtil.buildPushObject_ios_all_alertWithTitle(notification_title,msg_title,msg_content,extrasparam);
            System.out.println(pushPayload);
            PushResult pushResult=jPushClient.sendPush(pushPayload);
            System.out.println(pushResult);
            if(pushResult.getResponseCode()==200){
                result=1;
            }
        } catch (Exception e) {
 
            e.printStackTrace();
        }
 
         return result;
    }
 
    /**
     * 发送给全部用户
     * @param notification_title 通知内容标题
     * @param msg_title 消息内容标题
     * @param msg_content 消息内容
     * @param extrasparam 扩展字段
     * @return 0推送失败,1推送成功
     */
    public static int sendToAll( String title, String content,String extrasparam, String extrasparam2) {
        int result = 0;
        try {
            PushPayload pushPayload= JPushClientUtil.buildPushObject_android_and_ios(title,content,extrasparam,extrasparam2);
            System.out.println(pushPayload);
            PushResult pushResult=jPushClient.sendPush(pushPayload);
            System.out.println(pushResult);
            if(pushResult.getResponseCode()==200){
                result=1;
            }
        } catch (Exception e) {
 
            e.printStackTrace();
        }
 
        return result;
    }
 
 
 
    public static PushPayload buildPushObject_android_and_ios(String title, String content, String extrasparam, String extrasparam2) {
    	    IosAlert iosAlert =  IosAlert.newBuilder().setTitleAndBody(title, null,content).build();
    		return PushPayload.newBuilder()
                .setPlatform(Platform.android_ios())
                .setAudience(Audience.all())
                .setNotification(Notification.newBuilder()
                        .setAlert(title)
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .setAlert(content)
                                .setTitle(title)
                                //此字段为透传字段,不会显示在通知栏。用户能够经过此字段来作一些定制需求,如特定的key传要指定跳转的页面(value)
                                .addExtra("type",extrasparam)
                                .addExtra("id",extrasparam2)
                                .build()
                        )
                        .addPlatformNotification(IosNotification.newBuilder()
                                //传一个IosAlert对象,指定apns title、title、subtitle等
                                .setAlert(iosAlert)
                                //直接传alert
                                //此项是指定此推送的badge自动加1
                                .incrBadge(1)
                                //此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
                                // 若是系统没有此音频则以系统默认声音提醒;此字段若是传空字符串,iOS9及以上的系统是无声音提醒,如下的系统是默认声音
                                .setSound("sound.caf")
                                //此字段为透传字段,不会显示在通知栏。用户能够经过此字段来作一些定制需求,如特定的key传要指定跳转的页面(value)
                                .addExtra("type",extrasparam)
                                .addExtra("id",extrasparam2)
                                //此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
                                // .setContentAvailable(true)
 
                                .build()
                        )
                        .build()
                )
                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
                // sdk默认不作任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
                .setMessage(Message.newBuilder()
                        .setMsgContent(content)
                        .setTitle(title)
                        .addExtra("type",extrasparam)
                        .addExtra("id",extrasparam2)
                        .build())
 
                .setOptions(Options.newBuilder()
                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无心义
                        .setApnsProduction(true)
                        //此字段是给开发者本身给推送编号,方便推送者分辨推送记录
                        .setSendno(getRandomSendNo())
                        //此字段的值是用来指定本推送的离线保存时长,若是不传此字段则默认保存一天,最多指定保留十天,单位为秒
                        .setTimeToLive(timeToLive)
                        .build()
                )
                .build();
    }
 
    private static PushPayload buildPushObject_all_registrationId_alertWithTitle(String registrationId,String notification_title, String msg_title, String msg_content, String extrasparam,String extrasparam2) {
 
        System.out.println("----------buildPushObject_all_all_alert");
        //建立一个IosAlert对象,可指定APNs的alert、title等字段
        //IosAlert iosAlert =  IosAlert.newBuilder().setTitleAndBody("title", "alert body").build();
        return PushPayload.newBuilder()
                //指定要推送的平台,all表明当前应用配置了的全部平台,也能够传android等具体平台
                .setPlatform(Platform.all())
                //指定推送的接收对象,all表明全部人,也能够指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
                .setAudience(Audience.alias(registrationId))
                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
                .setNotification(Notification.newBuilder()
                        //指定当前推送的android通知
                        .addPlatformNotification(AndroidNotification.newBuilder()
 
                                .setAlert(notification_title)
                                .setTitle(notification_title)
                                
                                //此字段为透传字段,不会显示在通知栏。用户能够经过此字段来作一些定制需求,如特定的key传要指定跳转的页面(value)
                                .addExtra("type",extrasparam)
                                .addExtra("id",extrasparam2)
                                .build())
                        //指定当前推送的iOS通知
                        .addPlatformNotification(IosNotification.newBuilder()
                                //传一个IosAlert对象,指定apns title、title、subtitle等
                                .setAlert(msg_title)
                                //直接传alert
                                //此项是指定此推送的badge自动加1
                                .incrBadge(1)
                                //此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
                                // 若是系统没有此音频则以系统默认声音提醒;此字段若是传空字符串,iOS9及以上的系统是无声音提醒,如下的系统是默认声音
                                .setSound("default")
                                //此字段为透传字段,不会显示在通知栏。用户能够经过此字段来作一些定制需求,如特定的key传要指定跳转的页面(value)
                                .addExtra("type",extrasparam)
                                .addExtra("id",extrasparam2)
                                //此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
                                //取消此注释,消息推送时ios将没法在锁屏状况接收
                                // .setContentAvailable(true)
 
                                .build())
 
 
                        .build())
                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
                // sdk默认不作任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
                .setMessage(Message.newBuilder()
 
                        .setMsgContent(msg_content)
 
                        .setTitle(msg_title)
 
                        .addExtra("type",extrasparam)
                         .addExtra("id",extrasparam2)
 
                        .build())
 
                .setOptions(Options.newBuilder()
                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无心义
                        .setApnsProduction(true)
                        //此字段是给开发者本身给推送编号,方便推送者分辨推送记录
                        .setSendno(getRandomSendNo())
                        //此字段的值是用来指定本推送的离线保存时长,若是不传此字段则默认保存一天,最多指定保留十天;
                        .setTimeToLive(timeToLive)
 
                        .build())
 
                .build();
	    }
	 
	    private static PushPayload buildPushObject_android_all_alertWithTitle(String notification_title, String msg_title, String msg_content, String extrasparam) {
	        System.out.println("----------buildPushObject_android_registrationId_alertWithTitle");
	        return PushPayload.newBuilder()
                //指定要推送的平台,all表明当前应用配置了的全部平台,也能够传android等具体平台
                .setPlatform(Platform.android())
                //指定推送的接收对象,all表明全部人,也能够指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
                .setAudience(Audience.all())
                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
                .setNotification(Notification.newBuilder()
                        //指定当前推送的android通知
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .setAlert(notification_title)
                                .setTitle(notification_title)
                                //此字段为透传字段,不会显示在通知栏。用户能够经过此字段来作一些定制需求,如特定的key传要指定跳转的页面(value)
                                .addExtra("androidNotification extras key",extrasparam)
                                .build())
                        .build()
                )
                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
                // sdk默认不作任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg_content)
                        .setTitle(msg_title)
                        .addExtra("message extras key",extrasparam)
                        .build())
 
                .setOptions(Options.newBuilder()
                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无心义
                        .setApnsProduction(true)
                        //此字段是给开发者本身给推送编号,方便推送者分辨推送记录
                        .setSendno(getRandomSendNo())
                        //此字段的值是用来指定本推送的离线保存时长,若是不传此字段则默认保存一天,最多指定保留十天,单位为秒
                        .setTimeToLive(timeToLive)
                        .build())
                .build();
	    }
	 
	    private static PushPayload buildPushObject_ios_all_alertWithTitle( String notification_title, String msg_title, String msg_content, String extrasparam) {
	        System.out.println("----------buildPushObject_ios_registrationId_alertWithTitle");
	        return PushPayload.newBuilder()
                //指定要推送的平台,all表明当前应用配置了的全部平台,也能够传android等具体平台
                .setPlatform(Platform.ios())
                //指定推送的接收对象,all表明全部人,也能够指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
                .setAudience(Audience.all())
                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
                .setNotification(Notification.newBuilder()
                        //指定当前推送的android通知
                        .addPlatformNotification(IosNotification.newBuilder()
                                //传一个IosAlert对象,指定apns title、title、subtitle等
                                .setAlert(notification_title)
                                //直接传alert
                                //此项是指定此推送的badge自动加1
                                .incrBadge(1)
                                //此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
                                // 若是系统没有此音频则以系统默认声音提醒;此字段若是传空字符串,iOS9及以上的系统是无声音提醒,如下的系统是默认声音
                                .setSound("sound.caf")
                                //此字段为透传字段,不会显示在通知栏。用户能够经过此字段来作一些定制需求,如特定的key传要指定跳转的页面(value)
                                .addExtra("iosNotification extras key",extrasparam)
                                //此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
                               // .setContentAvailable(true)
 
                                .build())
                        .build()
                )
                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
                // sdk默认不作任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg_content)
                        .setTitle(msg_title)
                        .addExtra("message extras key",extrasparam)
                        .build())
 
                .setOptions(Options.newBuilder()
                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无心义
                        .setApnsProduction(true)
                        //此字段是给开发者本身给推送编号,方便推送者分辨推送记录
                        .setSendno(getRandomSendNo())
                        //此字段的值是用来指定本推送的离线保存时长,若是不传此字段则默认保存一天,最多指定保留十天,单位为秒
                        .setTimeToLive(timeToLive)
                        .build())
                .build();
	    }
}

这就是极光推送教程,哪里不懂能够私信我哦!给你们留一个问题,推送大家是否有收到过带声音的推送。我最近在研究,欢迎一块儿学习。微信


鼓励做者写出更好的技术文档,就请我喝一瓶哇哈哈哈哈哈哈哈。。 微信:

支付宝:


感谢一路支持个人人。。。。。

Love me and hold me
QQ:69673804(16年老号)
EMAIL:69673804@qq.com
友链交换
若是有兴趣和本博客交换友链的话,请按照下面的格式在评论区进行评论,我会尽快添加上你的连接。

网站名称:KingYiFan’S Blog
网站地址:http://blog.cnbuilder.cn
网站描述:年少是你未醒的梦话,风华是燃烬的彼岸花。
网站Logo/头像:[头像地址](https://blog.cnbuilder.cn/upload/2018/7/avatar20180720144536200.jpg)
相关文章
相关标签/搜索