C#极光推送消息。【分析demo】




参考:http://docs.jpush.cn/display/dev/Push-API-v3


给android,ios设备发送推送消息。

给所有用户或者单个用户推送消息。


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

using cn.jpush.api;
using cn.jpush.api.push;
using cn.jpush.api.report;
using cn.jpush.api.common;
using cn.jpush.api.util;

namespace JpushApiClientExample
{
    class JPushApiExample
    {

        public class ExtralClass
        {
            public String sound = "ssss";

            public String menu="button";
        }




        static void Main(string[] args)
        {
            Console.WriteLine("************");
            Console.WriteLine("*****开始发送******");

            //String result;
            String app_key = "-";//需要申请
            String master_secret = "-";
            //int sendno = 9;

            HashSet<DeviceEnum> set = new HashSet<DeviceEnum>();
            set.Add(DeviceEnum.Android);
            set.Add(DeviceEnum.IOS);
            JPushClient client = new JPushClient(app_key, master_secret, 0, set, true);

            MessageResult result = null;

            NotificationParams notifyParams = new NotificationParams();
            //CustomMessageParams customParams = new CustomMessageParams();

            //notifyParams.

            //传入json字符串


            String extras = null;
            extras = "{\"ios\":{\"badge\":88, \"sound\":\"happy\"}}";//ios设备推送时


            //extras中有中文请用HttpUtility.UrlEncode编码
            //System.Web.HttpUtility.UrlEncode(notificationContent, Encoding.UTF8);

            //Console.WriteLine("*****发送带tag通知******");

            /**
             *发送类型 
             *APP_KEY          通知
             *TAG              TAG
             *ALIAS            ALIAS
             *REGISTRATION_ID  REGISTRATION_ID
             */
            notifyParams.ReceiverType = ReceiverTypeEnum.REGISTRATION_ID;
            notifyParams.ReceiverValue = "4455cda4f16";//单个用户设备标识

            notifyParams.SendNo = 256;

            /*****单个用户推送****/
            //result = client.sendNotification("测试单个用户的推送消息", notifyParams, extras);//给某个用户推送消息

            /*****广播形式****/
            result = client.sendNotificationAll("测试广播信息");//广播--全体推送

            Console.WriteLine("sendNotification by tag:**返回状态:" + result.getErrorCode().ToString() +
                          "  **返回信息:" + result.getErrorMessage() +
                          "  **Send No.:" + result.getSendNo() +
                          "  msg_id:" + result.getMessageId() +
                          "  频率次数:" + result.getRateLimitQuota() +
                          "  可用频率:" + result.getRateLimitRemaining() +
                          "  重置时间:" + result.getRateLimitReset());
        }
    
        public class IOSExtras
        {
            public int badge = 888;
            public String sound = "happy";
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值