Esempio n. 1
0
        //将指定的消息以及额外添加的数据推送给安卓和IOS平台终端且满足具有指定标签的目标用户
        public static bool PushObject_ios_tagAnd_alertWithExtrasAndMessage(string alert, string message, Dictionary <string, string> extraParameters, params string[] tags)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();   //推送的平台为android和ios
            pushPayload.audience = Audience.s_tag_and(tags); //推送的具有tag1和tag2这两个标签的目标用户

            //构造Notification对象
            var notification = new Notification();

            notification.setAlert(alert);//设定要发送的消息内容
            notification.IosNotification = new IosNotification().incrBadge(1);
            pushPayload.notification     = notification;

            //添加额外的数据
            if (extraParameters != null && extraParameters.Count > 0)
            {
                foreach (var dicItem in extraParameters)
                {
                    notification.IosNotification.AddExtra(dicItem.Key, dicItem.Value);
                }
            }

            pushPayload.message = Message.content(message);

            return(SendPush(pushPayload));
        }
Esempio n. 2
0
        //推送给满足所有标签的用户
        public static PushPayload PushObject_tags_and(string companyId, string[] selects, string content)
        {
            var pushPayload = new PushPayload();

            pushPayload.platform     = Platform.android();
            pushPayload.audience     = Audience.s_tag_and(selects).tag_and(companyId);
            pushPayload.message      = Message.content(content).AddExtras("Tag", "2").AddExtras("CompanyTag", "1");
            pushPayload.notification = Notification.android(ALERT, TITLE);
            return(pushPayload);
        }
Esempio n. 3
0
        public void sendByTagAndMore()
        {
            PushPayload payload = new PushPayload();

            payload.platform     = Platform.all();
            payload.audience     = Audience.s_tag_and(TAG1, TAG_ALL);
            payload.notification = new Notification().setAlert(ALERT);
            var result = _client.SendPush(payload);

            Assert.IsTrue(result.isResultOK());
        }
Esempio n. 4
0
        public static PushPayload PushObject_Android_Tag_AlertWithTitle()
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android();
            // pushPayload.audience = Audience.all();
            pushPayload.audience     = Audience.s_tag_and("0000000008");
            pushPayload.notification = Notification.android(ALERT, TITLE);

            return(pushPayload);
        }
Esempio n. 5
0
        public static PushPayload PushObject_ios_tagAnd_alertWithExtrasAndMessage()
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = Audience.s_tag_and("tag1", "tag_all");
            var notification = new Notification();

            notification.IosNotification = new IosNotification().setAlert(ALERT).setBadge(5).setSound("happy").AddExtra("from", "JPush");

            pushPayload.notification = notification;
            pushPayload.message      = Message.content(MSG_CONTENT);
            return(pushPayload);
        }
Esempio n. 6
0
 /// <summary>
 /// 极光消息推送
 /// </summary>
 /// <param name="tagId">来源标识(1=B端/0=C端)</param>
 /// <param name="title">提示title</param>
 /// <param name="alert"></param>
 /// <param name="content"></param>
 /// <param name="RegistrationId">商户id  注册ID 数组。多个注册ID之间是 OR 关系,即取并集。 设备标识。一次推送最多 1000 个。 </param>
 /// <param name="city">城市 </param>
 public static void PushMessage(int tagId, string title, string alert, string content, string RegistrationId, string city)
 {
     try
     {
         string appKey       = "";
         string masterSecret = "";
         if (tagId == 0)                                //C端
         {
             appKey       = "dce902893245e99461b9a5c8"; // Your App Key from JPush
             masterSecret = "fdc95d37d67c9472ad4e0e96"; // Your Master Secret from JPush
         }
         else if (tagId == 1)                           //B端
         {
             appKey       = "d794d51f2ffaf5de42001c4b"; // Your App Key from JPush
             masterSecret = "03f956afaaeb086481aa3b7c"; // Your Master Secret from JPush
         }
         JPushClient client   = new JPushClient(appKey, masterSecret);
         Audience    audience = null;
         if (tagId == 0)  //C端
         {
             audience = Audience.s_tag_and(city.Trim());
         }
         else if (tagId == 1 && !string.IsNullOrEmpty(RegistrationId)) //B端
         {
             audience = Audience.s_tag(RegistrationId);
         }
         PushPayload pushPayload = new PushPayload();
         pushPayload.platform = Platform.android_ios();
         pushPayload.audience = audience;
         Notification notification = new Notification().setAlert(alert);
         notification.AndroidNotification = new AndroidNotification().setTitle(title);
         notification.IosNotification     = new IosNotification().setAlert(alert).setBadge(1).setSound("YourSound");
         pushPayload.notification         = notification.Check();
         var response = client.SendPush(pushPayload);
         if (!response.isResultOK())
         {
             LogHelper.LogWriter("推送失败", response.msg_id);
         }
         else
         {
             LogHelper.LogWriter("推送成功", response.msg_id);
         }
     }
     catch (Exception ex)
     {
         string parm = string.Concat("推送异常,参数:tagId", tagId, ",RegistrationId:", RegistrationId);
         LogHelper.LogWriter(ex, parm);
     }
 }
Esempio n. 7
0
        public void sendByTagAndMore_fail()
        {
            //PushPayload payload = PushPayload.newBuilder()
            //        .setPlatform(Platform.all())
            //        .setAudience(Audience.tag_and(TAG1, TAG2))
            //        .setNotification(Notification.alert(ALERT))
            //        .build();
            PushPayload payload = new PushPayload();

            payload.platform     = Platform.all();
            payload.audience     = Audience.s_tag_and(TAG1, TAG2);
            payload.notification = new Notification().setAlert(ALERT);
            var result = _client.SendPush(payload);

            Assert.IsTrue(result.isResultOK());
        }
Esempio n. 8
0
        private PushPayload CreatePayload(string title, string content, string[] tags = null, string[] alias = null)
        {
            var result = new PushPayload()
            {
                platform     = Platform.android(),
                notification = Notification.android(content, title)
            };

            if (tags != null && tags.Length > 0)
            {
                result.audience = Audience.s_tag_and(tags);
            }

            if (alias != null && alias.Length > 0)
            {
                result.audience = Audience.s_alias(alias);
            }
            return(result);
        }
Esempio n. 9
0
    //tag-标签,alias-别名,title-标题,content-内容,type-类型,subtitle-副标题
    public static void push(string tag, string alias, string title, string subtitle, string content, string type)
    {
        //string[] tags = tag.Split(',');
        JPushClient client;

        if (type == "shop")
        {
            client = new JPushClient(sysconf.jpush_app_key_shop, sysconf.jpush_master_secret_shop);
        }
        else
        {
            client = new JPushClient(sysconf.jpush_app_key, sysconf.jpush_master_secret);
        }
        Audience target;

        switch (type)
        {
        case "alert":
            target = Audience.all();
            break;

        case "verified":
            target = Audience.s_alias(alias);
            break;

        case "order":
            string[] tags = tag.Split(',');
            target = Audience.s_tag_and(tags);
            break;

        case "finish":
            target = Audience.s_alias(alias);
            break;

        case "shop":
            target = Audience.s_alias(alias);
            break;

        default:
            target = Audience.all();
            break;
        }
        PushPayload payload = ios(target, title, content, type, subtitle);

        try
        {
            var result = client.SendPush(payload);
        }
        catch
        {
            //
        }
        payload = android(target, title, content, type, subtitle);
        try
        {
            var result = client.SendPush(payload);
        }
        catch
        {
            //
        }
    }