C#简单的JPush(极光推送) API实现推送功能

APP推送功能大家应该都了解了,目前主要的有百度、极光等几家公司提供推送服务,下面说一下极光推送API的简单实现推送通知功能。

注册完极光的账号后,就可以创建应用,建好后会得到AppKey和MasterSecret两个主要参数,这个东西相当于我们的手机号码,用来连接推送的ID。

    private string SendPush(int type)
    {
        string result = "";  //返回结果
        string app_key = "你的AppKey";
        string master_secret = "你的MasterSecret";
        int time_to_live = 86400;   //生存周期,单位为秒
        string os = "android|ios";    //可以只要android或者ios
        string title = "标题";  //选填
        string content = "内容";    //必填,少于70字

        JPush.JPushClient client = new JPush.JPushClient(app_key, master_secret, time_to_live);

        switch (type)
        { 
            case 0: //发送给设备的所有用户
                result = client.sendNotificationByAppkey(9, "des", title, content, os, "", "");
                break;
            case 1: //发送给设备用户ID为888的用户(如果发给多个ID,可以用“,”号隔开,如“888,999,000”,限制在1000个以内,具体官方文档有说明)
                result = client.sendNotificationByAlias("888", 9, "des", title, content, os, "", "");
                break;
            case 2: //发送给类别为Level8的用户
                result = client.sendNotificationByTag("Level8", 9, "des", title, content, os, "", "");
                break;
        }

        return result;
    }


这里用到了JPush.dll,下载地址:https://pan.baidu.com/s/1NDL4awJ2WUkHUeKS_VPD5A 提取码: y1g6

极光官方网站:https://www.jiguang.cn/

以上就是JPush API(C#)的运用,至于手机端的开发,官方已经有相关文档案例。

猜你喜欢

转载自blog.csdn.net/mojocube/article/details/47212087