极光推送(极光推送简介)

时间:2026-02-05 19:57:52 来源:下儿资讯网

本篇文章给大家谈谈极光推送,极光极光简介以及极光推送官网对应的推送推送知识点,希望对各位有所帮助,极光极光简介不要忘了收藏本站喔。推送推送

极光推送总结

应用场景:在我们的极光极光简介项目中我们用的是创建视频会议和预警消息通知推送这两种情况,首先创建视频会议和中途邀请人参加会议我采用的推送推送是自定义推送消息,因为此应用场景传递的极光极光简介参数比较多,在推送过去之后android和ios可以很方便的推送推送将参数传递过去,但是极光极光简介我们考虑到邀请的所有人都在登录状态的时候才可以创建会议房间,我们采用的推送推送是腾讯视频会议的sdk,因为我们采用的极光极光简介是别名推送,当用户在登录的推送推送时候安卓端将用户uuid设置为别名,退出时取消别名,极光极光简介我在服务端根据传递过来的推送推送uuid利用别名查询registration_ids的数组大小是否为空判断当前用户是否设置别名,当邀请的极光极光简介所有人都设置了别名之后我才调用创建会议房间的接口。而预警消息推送我采用的是通知推送,当气象预警触发的时候我会采用通知推送的方式推送给app,这种方式比较简单。

极光推送是给app推送消息的,我们首先需要在服务端集成maven依赖

!-- 极光推送 --

    groupIdcn.jpush.api

    artifactIdjpush-client

    version3.2.3

/dependency

接着我们需要了解极光推送有哪些推送方式,对于安卓和ios都适用的情况,我在项目中使用的是别名推送alias,(还有标签推送tag),推送方式又分为通知推送和自定义推送,通知推送能够显示在手机提示框中,而自定义推送却不能,我看安卓他们做的能跟微信视频一样的弹出一个会话框,看着挺不错的,这跟微信不同的是可以邀请多个,之前用阿里云的好像只能一对一,所以才换成腾讯视频会议的,好了,废话不多说,上我写的一个工具类,

package com.jpxx.homepage.homePage.service.utils;

import cn.jpush.api.JPushClient;

import cn.jpush.api.push.PushResult;

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.Notification;

import cn.jpush.api.push.model.Message;

import cn.jpush.api.push.model.PushPayload.Builder;

public class SendMessageUtils {

private static StringAppKey="8a7880c6fb81ad494b224078";

    /

**

    * JPush MasterSecret 极光推送平台生成的密钥

    */

    private static StringMasterSecret="c0fc675c4c48f9bf35269cf4";

    //两个参数分别填写你申请的masterSecret和appKey

    private static JPushClientjPushClient=new JPushClient(MasterSecret,AppKey);

    /

**

    * 通知推送

    * 备注:推送方式不为空时,推送的值也不能为空;推送方式为空时,推送值不做要求

    * @param type 推送方式:1、“tag”标签推送,2、“alias”别名推送

    * @param value 推送的标签或别名值

    * @param alert 推送的内容

    */

    public static StringpushNotice(String type,String title,String value,String alert,int roomId,String MessageType,String name,String promoterAdavter,String meetingTitle,String sig){

Builder builder= PushPayload.newBuilder();

        builder.setPlatform(Platform.all());//设置接受的平台,all为所有平台,包括安卓、ios、和微软的

        //设置如果用户不在线、离线消息保存的时间

        Options options=Options.sendno();

        options.setTimeToLive(86400l);    //设置为86400为保存一天,如果不设置默认也是保存一天

        builder.setOptions(options);

        builder.setMessage(Message.newBuilder()

.setMsgContent(value)

.setTitle(title)

.addExtra("roomId",roomId)

.addExtra("MessageType",MessageType)

.addExtra("name",name)

.addExtra("promoterAdavter",promoterAdavter)

.addExtra("meetingTitle",meetingTitle)

.addExtra("userSig",sig)

.build());

        //设置推送方式

        if(type.equals("alias")){

builder.setAudience(Audience.alias(value));//根据别名推送

        }else if(type.equals("tag")){

builder.setAudience(Audience.tag(value));//根据标签推送

        }else{

builder.setAudience(Audience.all());//Audience设置为all,说明采用广播方式推送,所有用户都可以接收到

        }

//设置为采用通知的方式发送消息

        builder.setNotification(Notification.alert(alert));

        PushPayload pushPayload=builder.build();

        System.out.println("ggggggg"+pushPayload);

        try{

//进行推送,实际推送就在这一步

            //System.out.println("zzzzzzzzz "+jPushClient.sendPush(pushPayload));

            PushResult pushResult=jPushClient.sendPush(pushPayload);

            return "success";

        }catch(Exception e){

System.out.println("异常 "+e);

            e.printStackTrace();

            return "fail";

        }

}

/

**

    * 自定义消息推送

    * 备注:推送方式不为空时,推送的值也不能为空;推送方式为空时,推送值不做要求

    * @param type 推送方式:1、“tag”标签推送,2、“alias”别名推送

    * @param value 推送的标签或别名值

    * @param alert 推送的内容

    */

    public static StringpushMsg(String type,String title,String value,String alert,int roomId,String MessageType,String name,String promoterAdavter,String meetingTitle,String sig){

Builder builder= PushPayload.newBuilder();

        builder.setPlatform(Platform.all());//设置接受的平台

        if(type.equals("alias")){

builder.setAudience(Audience.alias(value));//别名推送

        }else if(type.equals("tag")){

builder.setAudience(Audience.tag(value));//标签推送

        }else{

builder.setAudience(Audience.all());//Audience设置为all,说明采用广播方式推送,所有用户都可以接收到

        }

Message.Builder newBuilder=Message.newBuilder();

        newBuilder.setMsgContent(alert);//消息内容

        newBuilder.setTitle(title);

        newBuilder.addExtra("roomId",roomId);

        newBuilder.addExtra("MessageType",MessageType);

        newBuilder.addExtra("name",name);

        newBuilder.addExtra("promoterAdavter",promoterAdavter);

        newBuilder.addExtra("meetingTitle",meetingTitle);

        newBuilder.addExtra("userSig",sig);

        Message message=newBuilder.build();

        builder.setMessage(message);

        PushPayload pushPayload=builder.build();

        try{

PushResult pushResult=jPushClient.sendPush(pushPayload);

            System.out.println(pushResult.isResultOK());

            return "success";

        }catch(Exception e){

e.printStackTrace();

            return "fail";

        }

}

public static void main(String[] args) {

//给标签为kefu的用户进行消息推送

        //SendMessageUtils.pushMsg("alias","标题","5b9022746e284ea0992e3baa983035dc","你有新的任务,请及时处理",111,"meetingType","name","avater","meetingTitle","");

//sendNotificationWirhAlias_Ios("zzzzzzzzzzzz","uuid");

        //String result = SendMessageUtils.pushNotice("alias","标题","5b9022746e284ea0992e3baa983035dc","你有新的任务,请及时处理",111,"meetingType","name","avater","meetingTitle","");

        //System.out.println("返回结果"+result);

        /*String result = SendMessageUtils.pushNotice("alias","预警标题","5b9022746e284ea0992e3baa983035dc","dddd",0,"warnType","","","","");  //userDto.getUuId()

System.out.println("result "+result);*/

        //根据uuid查询别名信息是否存在

        String result = HttpRequestUtil.JGUtil("", "8a7880c6fb81ad494b224078","c0fc675c4c48f9bf35269cf4");//get请求

        //String result = HttpRequestUtil.interfaceUtil("", "","ydswtapp","eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJjbGllbnRJZFwiOlwieWRzd3RhcHBcIixcImxvZ2luVGltZVwiOjE1NTYwMDY1NDU4MzksXCJ1c0lkXCI6MjM5OSxcInVzZXJSb2xlXCI6XCJBRE1JTlwiLFwidXVJZFwiOlwiNDAyODgxZTUzYzdmMGRkZTAxM2M3ZjI5ZWQ4ZTAwMTZcIn0iLCJpc3MiOiJhdXRoMCIsImV4cCI6MTg3MTM2NjU0NSwiaWF0IjoxNTU2MDA2NTQ1fQ.Cy3-eDD4OEYhJlldvtJsymALRVGwP466TmBrSQJQGUo");//get请求

        System.out.println("result  "+result);

    }

}

因为我要根据前端传来的uuid判断当前用户是否登录,所以我对http方法进行了稍微改装,根据极光的api文档(文档写的不是很好找),以下是我改装的

/

**

*

* 极光专用

*/

public static StringJGUtil(String path,String appKey,String masterSecret) {

String str ="";

    try {

URL url =new URL(path);

        //打开和url之间的连接

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        PrintWriter out =null;

        /**设置URLConnection的参数和普通的请求属性****start***/

        String base64String=appKey+":"+masterSecret;

        System.out.println("拼接的 "+base64String);

        String str2=base64String;

        String encode =new BASE64Encoder().encode(str2.getBytes());

        System.out.println("编码过后:"+encode);

        String auth ="Basic "+encode;

        System.out.println("最终的 "+auth);

        conn.setRequestProperty("Authorization", auth);

        conn.setRequestProperty("Content-Type", "application/json");

        //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        conn.setRequestProperty("accept", "*/*");

        conn.setRequestProperty("connection", "Keep-Alive");

        conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");

        /**设置URLConnection的参数和普通的请求属性****end***/

        //设置是否向httpUrlConnection输出,设置是否从httpUrlConnection读入,此外发送post请求必须设置这两个

        //最常用的Http请求无非是get和post,get请求可以获取静态页面,也可以把参数放在URL字串后面,传递给servlet,

        //post与get的 不同之处在于post的参数不是放在URL字串里面,而是放在http请求的正文内。

        conn.setDoOutput(true);

        conn.setDoInput(true);

        conn.setRequestMethod("GET");//GET和POST必须全大写

        /**GET方法请求*****start*/

/

**

        * 如果只是发送GET方式请求,使用connet方法建立和远程资源之间的实际连接即可;

        * 如果发送POST方式的请求,需要获取URLConnection实例对应的输出流来发送请求参数。

        * */

        conn.connect();

        /**GET方法请求*****end*/

        /***POST方法请求****start*/

        /*out = new PrintWriter(conn.getOutputStream());//获取URLConnection对象对应的输出流        out.print(data);//发送请求参数即数据        out.flush();//缓冲数据*/

        /***POST方法请求****end*/

        //获取URLConnection对象对应的输入流

        InputStream is = conn.getInputStream();

        //构造一个字符流缓存

        BufferedReader br =new BufferedReader(new InputStreamReader(is));

        while ((str = br.readLine()) !=null) {

str =new String(str.getBytes(), "UTF-8");//解决中文乱码问题

            System.out.println("wwwww"+str);

            return str;

        }

//关闭流

        is.close();

        //断开连接,最好写上,disconnect是在底层tcp socket链接空闲时才切断。如果正在被其他线程使用就不切断。

        //固定多线程的话,如果不disconnect,链接会增多,直到收发不出信息。写上disconnect后正常一些。

        conn.disconnect();

        System.out.println("完整结束");

    }catch (Exception e) {

e.printStackTrace();

    }

return "success";

}

好了,以后再写类似的就会写了,这里附上极光文档的链接

怎么使用极光推送

使用极光推送的步骤:

1.到极光推送官方网站注册开发者帐号;

2.登录进入管理控制台,创建应用程序,得到 Appkey(SDK 与服务器端通过 Appkey 互相识别);

3.在推送设置中给 Android 设置包名、给 iOS 上传证书、启用 WinPhone,根据你的需求进行选择;

4.下载 SDK 集成到 App 里

推送服务可以说是所有 App 的标配,不论是哪种类型的 App,推送都从很大程度上决定了 App 的 打开率、使用率、存活率 。因此,熟知并掌握推送原理及方法,对每一个开发者来说都是必备技能,对每一个依赖 App 的公司来说都至关重要。

想进一步了解可以访问极光推送官网联系商务

极光推送产品特点

极光推送 — 快、稳、准

JPush提供整合Android、iOS的统一推送服务,毫秒级 送达,推送内容多样性,有效提高留存率,提升用户活 跃度。

支持消息撤回、消息免打扰、文件推送、消息防重发、 批量单推、透传转通知、通知开关检测等功能

1.内容丰富

通知+自定义消息+富媒体, 三重个性化推送方式, 满足任意场景需要

2.集成简单

3 分钟快速集成推送 SDK, 推送毫秒级到达, 完全省去开发和维护成本。

3.效果显著

使用推送当日,APP开启次数提 升5 倍,留存率提升2 倍, 移动订单成交率提升20%。

4.效果显著

使用推送当日,APP开启次数提 升5 倍,留存率提升2 倍, 移动订单成交率提升20%。

5.统计全面

提供 Report API、控制台两 种方式查询统计各类数据。 推送图表包括推送、点击、 打开时长等,用户统计图表 包括新增、在线、活跃

极光推送的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于极光推送官网、极光推送的信息别忘了在本站进行查找喔。