java 批量推送 iosITeye - AG环亚娱乐集团

java 批量推送 iosITeye

2019年04月02日08时55分46秒 | 作者: 沛凝 | 标签: 推送,测验,内容 | 浏览: 243

import javapns.devices.Device;

import javapns.devices.implementations.basic.BasicDevice;

import javapns.notification.AppleNotificationServerBasicImpl;

import javapns.notification.PushNotificationManager;

import javapns.notification.PushNotificationPayload;

import javapns.notification.PushedNotification;

import org.apache.commons.lang.StringUtils;

 

public class ApnsSend

{

    public static void main(String[] args) throws Exception

    {

        String deviceToken = "d7e6132895b388cf016433167c9e2d97fe4b76ca5a1692209a3b6e3cb3fdcd9c";

        String alert = "我的push测验";//push的内容

        int badge = 100;//图标小红圈的数值

        String sound = "default";//铃音

 

        List String tokens = new ArrayList String

        tokens.add(deviceToken);

        String certificatePath = "D:/PushDev.p12";

        String certificatePassword = "123456";//此处留意导出的证书暗码不能为空由于空暗码会报错

        boolean sendCount = true;

 

        try

        {

            PushNotificationPayload payLoad = new PushNotificationPayload();

            payLoad.addAlert(alert); // 音讯内容

            payLoad.addBadge(badge); // iphone使用图标上小红圈上的数值

            if (!StringUtils.isBlank(sound))

            {

                payLoad.addSound(sound);//铃音

            }

            PushNotificationManager pushManager = new PushNotificationManager();

            //true:表明的是产品发布推送效劳 false:表明的是产品测验推送效劳

            pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificatePath, certificatePassword, false));

            List PushedNotification notifications = new ArrayList PushedNotification

            // 发送push音讯

            if (sendCount)

            {

                Device device = new BasicDevice();

                device.setToken(tokens.get(0));

                PushedNotification notification = pushManager.sendNotification(device, payLoad, true);

                notifications.add(notification);

            }

            else

            {

                List Device device = new ArrayList Device

                for (String token : tokens)

                {

                    device.add(new BasicDevice(token));

                }

                notifications = pushManager.sendNotifications(payLoad, device);

            }

            List PushedNotification failedNotifications = PushedNotification.findFailedNotifications(notifications);

            List PushedNotification successfulNotifications = PushedNotification.findSuccessfulNotifications(notifications);

            int failed = failedNotifications.size();

            int successful = successfulNotifications.size();

            pushManager.stopConnection();

        }

        catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表AG环亚娱乐集团立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章