コード例 #1
0
        /// <summary>
        /// 推送消息
        /// </summary>
        /// <param name="notificationTitle">通知title</param>
        /// <param name="content">通知内容</param>
        /// <param name="message">消息内容</param>
        /// <param name="deviceTypes">推送平台</param>
        /// <param name="pushId">用户标识</param>
        /// <param name="keyValueParams">参数</param>
        /// <returns>推送消息ID</returns>
        public static long SendPush(
            string notificationTitle,
            string content,
            string message,
            DeviceType deviceTypes,
            string pushId,
            Dictionary <string, string> keyValueParams)
        {
            PushPayload pushPayload = new PushPayload();

            var platformNotification = GetPlatformNotification(deviceTypes, notificationTitle, content, keyValueParams);

            pushPayload.platform     = platformNotification.Item1;
            pushPayload.notification = platformNotification.Item2;

            Audience audience = string.IsNullOrWhiteSpace(pushId)
                ?
                                Audience.all()
                : Audience.s_registrationId(pushId);

            pushPayload.audience = audience;

            if (!string.IsNullOrWhiteSpace(message))
            {
                pushPayload.message = Message.content(message);
            }

            //true 表示推送生产环境, false表示要推送开发环境;
            pushPayload.ResetOptionsApnsProduction(isRelease);

            var result = _client.SendPush(pushPayload);

            return(result.msg_id);
        }
コード例 #2
0
ファイル: PushMessage.cs プロジェクト: 15831944/EPC
        /// <summary>
        /// 推送到ios和andriod平台
        /// </summary>
        /// <param name="content">通知内容</param>
        /// <param name="title">通知标题</param>
        /// <param name="dict">额外信息</param>
        /// <param name="isProduction">是生产环境</param>
        /// <param name="audience">推送的用户</param>
        /// <returns></returns>
        public static PushPayload PushObject_AndroidAndIos_Audience(string content, string title, Audience audience, bool isProduction = true, Dictionary <string, string> dict = null)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = audience;

            var notification = new Notification().setAlert(content);

            notification.AndroidNotification = new AndroidNotification();
            notification.AndroidNotification.setTitle(title);

            notification.IosNotification = new IosNotification();
            notification.IosNotification.incrBadge(1);
            notification.IosNotification.setSound("default");

            //判断是否有额外信息
            if (dict != null)
            {
                foreach (var item in dict)
                {
                    notification.AndroidNotification.AddExtra(item.Key, item.Value);
                    notification.IosNotification.AddExtra(item.Key, item.Value);
                }
            }

            pushPayload.notification = notification.Check();
            pushPayload.ResetOptionsApnsProduction(isProduction);
            return(pushPayload);
        }
コード例 #3
0
    public static PushPayload PushObject_all_alias_alert(string mobile, string msg)
    {
        PushPayload pushPayload_alias = new PushPayload();

        pushPayload_alias.platform     = Platform.all();
        pushPayload_alias.audience     = Audience.s_alias(mobile);
        pushPayload_alias.notification = new Notification().setAlert(msg);
        pushPayload_alias.ResetOptionsApnsProduction(false);
        return(pushPayload_alias);
    }
コード例 #4
0
ファイル: Conductor.ashx.cs プロジェクト: fu-yujie/guangyang
        //接受推送信息
        private void SecondContentCode(HttpContext context)
        {
            var msgContent = context.Request.Params["content"];
            var userId     = context.Request.Params["userId"];
            var senderId   = string.IsNullOrEmpty(context.Request.Params["senderId"]) ? 0 : Convert.ToInt32(context.Request.Params["senderId"]);

            string[] userIds = userId.Split(',');
            var      query   = userIds.Aggregate(string.Empty, (current, s) => current + ("'" + s + "',"));

            query = query.Substring(0, query.LastIndexOf(','));

            string[] registrationId;
            var      conductorManager = new ConductorManager();
            var      dtRegistration   = conductorManager.GetRegistrationIds(query);

            if (dtRegistration != null && dtRegistration.Rows.Count > 0)
            {
                registrationId = dtRegistration.Rows.Cast <DataRow>().Select(o => o["PhoneId"].ToString()).ToArray();
                //开发者标识
                var appKeyAndrow       = ServiceLocator.DevKey;
                var masterSecretAndrow = ServiceLocator.DevSecret;
                var alert = ServiceLocator.AppAlert;//推送提示
                //var title = ServiceLocator.AppTitle;//推送标题
                JPushClient clientAndrow = new JPushClient(appKeyAndrow, masterSecretAndrow);

                PushPayload payload = PushObject(registrationId, alert);
                payload.ResetOptionsApnsProduction(true);
                try
                {
                    DateTime lssuedTime = DateTime.Now;
                    //var lssuedPeople = 0;
                    var result = clientAndrow.SendPush(payload);
                    System.Threading.Thread.Sleep(10000);
                    //查询推送结果
                    var apiResult = clientAndrow.getReceivedApi_v3(result.msg_id.ToString());
                    if (apiResult.isResultOK())//发送成功
                    {
                        conductorManager.Insert(senderId, lssuedTime, msgContent, userIds);
                        context.Response.Write("{\"msg\":\"Ok\"}");
                    }
                }
                catch (APIRequestException e)
                {
                    context.Response.Write("{\"msg\":\"Error\"}");
                }
                catch (APIConnectionException e)
                {
                    context.Response.Write("{\"msg\":\"Error\"}");
                }
            }
            else
            {
                context.Response.Write("{\"msg\":\"Error\"}");
            }
        }
コード例 #5
0
ファイル: JPushApiExample.cs プロジェクト: tonyyzz/UQingHrMng
        public static PushPayload PushObject_ios_audienceMore_messageWithExtras(string alias, string from)
        {
            var pushPayload = new PushPayload();

            pushPayload.ResetOptionsApnsProduction(true);
            pushPayload.platform = Platform.android_ios();
            //pushPayload.audience = Audience.s_tag("tag1","tag2");
            pushPayload.audience     = Audience.s_alias(alias);
            pushPayload.notification = new Notification().setAlert(ALERT);
            pushPayload.message      = Message.content(MSG_CONTENT).AddExtras("from", from);
            return(pushPayload);
        }
コード例 #6
0
ファイル: JPushApiExample.cs プロジェクト: tonyyzz/UQingHrMng
        public static PushPayload PushObject_ios_tagAnd_alertWithExtrasAndMessage(string alias, string from)
        {
            PushPayload pushPayload = new PushPayload();

            pushPayload.ResetOptionsApnsProduction(true);
            pushPayload.platform = Platform.android_ios();
            pushPayload.audience = Audience.s_alias(alias);
            var notification = new Notification();

            notification.IosNotification     = new IosNotification().setAlert(ALERT).setSound("happy").AddExtra("from", from);
            notification.AndroidNotification = new AndroidNotification().setAlert(ALERT).AddExtra("from", from);
            pushPayload.notification         = notification;
            pushPayload.message = Message.content(MSG_CONTENT).AddExtras("from", from);
            return(pushPayload);
        }
コード例 #7
0
ファイル: Push.cs プロジェクト: wndayday/bex5
        public static MessageResult sendPushMessage(string registrationId, string key, string secret)
        {
            //ClientConfig config = ClientConfig.getInstance();
            //jpushClient = new JPushClient(secret, key, 3, null, config);
            jpushClient = new JPushClient(key, secret);
            PushPayload payload = new PushPayload();

            payload.platform     = Platform.all();
            payload.audience     = Audience.s_registrationId(registrationId);
            payload.notification = new Notification().setAlert("亲爱的x5外卖用户,您的订单已经配货完毕,正在运送中..");

            payload.ResetOptionsTimeToLive(86400);
            payload.ResetOptionsApnsProduction(apnsProduction);
            string        schedleTime = DateTime.Today.ToString("yyyy-MM-dd HH:mm:ss");
            MessageResult result      = jpushClient.SendPush(payload);

            return(result);
        }