极光推送

极光推送

客户端集成步骤:

1、首先去JPush的开发者官网https://www.jpush.cn/  注册帐号

2、用刚刚的帐号登录开发者网站

3、点击用户头像下的控制台https://www.jpush.cn/common/apps/

4、创建应用。

5、打开开发者网站的文档选项 http://docs.jpush.cn/display/dev/Index根据里面的集成步骤集成Jpush。

服务端集成:

客户端集成完,我们的移动端的app就可以收到通知和消息了,但是发消息需要到Jpush的开发者网站去发送,这样的话就很不合理。正常情况肯定是我们自己的服务器根据情况发送通知和消息到客户端的。不可能我们服务端需要发通知和消息的时候需要有个人去打开Jpush的网站去发送通知。

这些情况Jpush已经为我们想到了,我们服务器端只要在发通知的地方调用Jpush提供的发布接口就可以了,就是一个HTTP请求而已。

我们可以自己写代码发送http请求,这边有一个第三方的开源项目是对Jpush推送接口的封装:https://github.com/jpush/jpush-api-java-client

api:

  • 推送的载体:类PushPayload

  • Platform 平台信息(必填)

  • Audience 推送目标(必填)

  • Notification 通知内容(可选)

  • Message 消息内容(可选)

  • Options 可选参数(可选)

  示例:

  方法:JPushClient.sendPush(PushPayload pushPayload)

JPushClient jpushClient = new JPushClient(masterSecret, appKey);
        String account = jgPushMessage.getCustomerNo();
        String title = jgPushMessage.getMsgTitle();
        String content = jgPushMessage.getMsgContent();
        
         PushPayload payload = PushPayload.newBuilder()
        .setPlatform(Platform.android_ios())
        .setAudience(Audience.alias(account))
        .setNotification(Notification.newBuilder()
                .setAlert(content)
                .addPlatformNotification(AndroidNotification.newBuilder()
                        .setTitle(title).build())
                .addPlatformNotification(IosNotification.newBuilder()
                        .incrBadge(1)
                        .setBadge(5)
                        .setSound("happy")
                        .addExtra("from", "JPush").build())
                .build())
                .setOptions(Options.newBuilder()
                 .setApnsProduction(true)
                 .build())
        .build();

PushResult result = jpushClient.sendPush(payload);

  添加代理:

HttpProxy proxy = new HttpProxy(HttpUtil.PROXY_IP,
                HttpUtil.PROXY_PORT,HttpUtil.PROXY_DOMAIN+"//"+HttpUtil.PROXY_USER,HttpUtil.PROXY_PASS);
        ClientConfig clientConfig = ClientConfig.getInstance();

  参考:

    极光推送接口详细描述:http://docs.jpush.cn/display/dev/Push-API-v3

      https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/

    https://blog.csdn.net/dalancon/article/details/41865303

    https://www.cnblogs.com/fengziaichou/p/5385793.html

猜你喜欢

转载自www.cnblogs.com/soul-wonder/p/8991984.html