Main Entrance - 该类为JPush服务的主要入口
Example #1
0
        /// <summary>
        /// 发送标签消息
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="Content">内容</param>
        /// <param name="alias">标签组</param>
        /// <returns></returns>
        public MessageResult SendTagMsg(string title, string Content, string[] Tags)
        {
            MessageResult result = new MessageResult();

            try
            {
                JPushClient  client      = new JPushClient(app_key, master_secret);
                string       MSG_CONTENT = Content;
                PushPayload  payload     = new PushPayload();
                Notification not         = new Notification();
                not.setAlert(title);

                payload.notification = not;
                payload.platform     = Platform.all();
                payload.audience     = Audience.s_tag(Tags);
                payload.message      = Message.content(title)
                                       .AddExtras("Content", Content)
                                       .AddExtras("Title", title)
                                       .AddExtras("key2", false);
                result = client.SendPush(payload);
            }
            catch (APIRequestException e)
            {
                SystemLogsBiz.logv("推送失败APIRequestException", e.ErrorMessage, "类 JpushHelp");
            }
            catch (APIConnectionException e)
            {
                SystemLogsBiz.logv("推送失败APIConnectionException", e.Message, "类 JpushHelp");
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 发送别名消息
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">message</param>
        /// <param name="alias">客户的别名组</param>
        /// <returns></returns>
        public MessageResult SendAliaMsg(string title, Message message, string[] alias)
        {
            MessageResult result = new MessageResult();

            try
            {
                JPushClient  client  = new JPushClient(app_key, master_secret);
                PushPayload  payload = new PushPayload();
                Notification not     = new Notification();
                not.setAlert(title);


                payload.notification = not;
                payload.platform     = Platform.all();
                payload.audience     = Audience.s_alias(alias);
                payload.message      = message;
                result = client.SendPush(payload);
            }
            catch (APIRequestException e)
            {
                SystemLogsBiz.logv("推送失败APIRequestException", e.ErrorMessage, "类 JpushHelp");
            }
            catch (APIConnectionException e)
            {
                SystemLogsBiz.logv("推送失败APIConnectionException", e.Message, "类 JpushHelp");
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">消息</param>
        /// <param name="audience">用户类型</param>
        /// <returns></returns>
        public MessageResult SendMsg(Notification not, Message message, Audience audience)
        {
            MessageResult result = new MessageResult();

            try
            {
                JPushClient client = new JPushClient(app_key, master_secret);

                PushPayload payload = new PushPayload();
                payload.notification = not;
                payload.platform     = Platform.all();
                payload.audience     = audience;
                payload.message      = message;
                result = client.SendPush(payload);
            }
            catch (APIRequestException e)
            {
                SystemLogsBiz.logv("推送失败APIRequestException", e.ErrorMessage, "类 JpushHelp");
            }
            catch (APIConnectionException e)
            {
                SystemLogsBiz.logv("推送失败APIConnectionException", e.Message, "类 JpushHelp");
            }
            return(result);
        }
Example #4
0
        protected void btn_Send_Click(object sender, EventArgs e)
        {
            JPushClient pushClient = new JPushClient(apikKey, secretKey);
            try
            {
                Message msg = new Message(txtContent.Value, txtTitle.Value, "");

                //广播
                if (this.rbBrandCast.Checked)
                {
                    pushClient.SendPush(PushPayload.SendAndroidAlertPushToAll(msg));
                }
                //批量发送
                else if (this.rbBatch.Checked)
                {
                    string[] paramsId = new string[] { "0304819befc", "021032" };
                    pushClient.SendPush(PushPayload.SendAndroidAlertBatchPush(msg, paramsId));
                }
                //单独设备发送
                else if (rbSingleDevice.Checked)
                {
                    string registerId = "0304819befc";
                    pushClient.SendPush(PushPayload.SendAndroidAlertSinglePush(msg, registerId));

                }
            }
            catch (Exception msg)
            {
                txtResponse.Value = msg.Message;
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("*****开始发送******");
            JPushClient client = new JPushClient(app_key, master_secret);
            PushPayload payload = PushObject_all_alias_alert("8001");
            try
            {
                var result = client.SendPush(payload);
                //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法
                System.Threading.Thread.Sleep(10000);
                /*如需查询上次推送结果执行下面的代码*/
                var apiResult = client.getReceivedApi(result.msg_id.ToString());
                var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString());
                /*如需查询某个messageid的推送结果执行下面的代码*/
                var queryResultWithV2 = client.getReceivedApi("1739302794"); 
                var querResultWithV3 = client.getReceivedApi_v3("1739302794");

            }
            catch (APIRequestException e)
            {
                Console.WriteLine("Error response from JPush server. Should review and fix it. ");
                Console.WriteLine("HTTP Status: " + e.Status);
                Console.WriteLine("Error Code: " + e.ErrorCode);
                Console.WriteLine("Error Message: " + e.ErrorCode);
            }
            catch (APIConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("*****结束发送******");
        }
Example #6
0
        static void Main(string[] args)
        {
            //String result;
            String master_secret = "8d182844403f3d9f100d21ec";
            String app_key = "51260cf224b010f4c0b0ac67";
            //int sendno = 9;
            JPushClient client = new JPushClient(app_key, master_secret);
            MessageResult result = null;

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

            //notifyParams.
            Dictionary<String, Object> extras = null;

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

            notifyParams.addPlatform(DeviceEnum.Android);
            notifyParams.ReceiverType = ReceiverTypeEnum.ALIAS;
            notifyParams.ReceiverValue = "AB6F93F8E6C64AB58BD570A9AF31BF15";
            notifyParams.SendNo = 257;
            //notifyParams.OverrideMsgId = "2";

            UTF8Encoding utf8 = new UTF8Encoding();
            string unicodeString = "中国";
            byte[] encodeBytes = utf8.GetBytes(unicodeString);
            string test = Encoding.UTF8.GetString(encodeBytes);
            result = client.sendNotification("中国xaut", notifyParams, extras);
            Console.WriteLine("sendNotificationAll:**返回状态:" + result.getErrorCode().ToString() +
                          "  **返回信息:" + result.getErrorMessage() +
                          "  **Send No.:" + result.getSendNo() +
                          "  msg_id:" + result.getMessageId() +
                          "  频率次数:" + result.getRateLimitQuota() +
                          "  可用频率:" + result.getRateLimitRemaining() +
                          "  重置时间:" + result.getRateLimitReset());

            Console.WriteLine("*****发送带alias消息******");
            customParams.addPlatform(DeviceEnum.Android);
            customParams.ReceiverType = ReceiverTypeEnum.ALIAS;
            customParams.ReceiverValue = "alias_api";
            customParams.SendNo = 256;
            result = client.sendCustomMessage("send custom mess", "alias notify content", customParams, extras);
            Console.WriteLine("sendCustomMessage:**返回状态:" + result.getErrorCode().ToString() +
                          "  **返回信息:" + result.getErrorMessage() +
                          "  **Send No.:" + result.getSendNo() +
                          "  msg_id:" + result.getMessageId() +
                          "  频率次数:" + result.getRateLimitQuota() +
                          "  可用频率:" + result.getRateLimitRemaining() +
                          "  重置时间:" + result.getRateLimitReset());
        }
Example #7
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">消息</param>
        /// <param name="audience">用户类型</param>
        /// <returns></returns>
        public MessageResult SendMsg(PushPayload payload)
        {
            MessageResult result = new MessageResult();

            try
            {
                JPushClient client = new JPushClient(app_key, master_secret);
                result = client.SendPush(payload);
            }
            catch (APIRequestException e)
            {
                SystemLogsBiz.logv("推送失败APIRequestException", e.ErrorMessage, "类 JpushHelp");
            }
            catch (APIConnectionException e)
            {
                SystemLogsBiz.logv("推送失败APIConnectionException", e.Message, "类 JpushHelp");
            }
            return(result);
        }
Example #8
0
    //基于手机号(设备别名)的推送
    public static string PushByMobile(string mobile, string msg)
    {
        string      app_key       = "5755e4ed48c87923fef29871";
        string      master_secret = "5d02d7ebd59ccd3da3cc24fe";
        string      error         = "";
        PushPayload payload_alias = PushObject_all_alias_alert(mobile, msg);

        try
        {
            cn.jpush.api.JPushClient client = new cn.jpush.api.JPushClient(app_key, master_secret);
            var result = client.SendPush(payload_alias);
            //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法
            //System.Threading.Thread.Sleep(100);
            ////如需查询上次推送结果执行下面的代码
            //var apiResult = client.getReceivedApi(result.msg_id.ToString());
            //var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString());
            ////如需查询某个messageid的推送结果执行下面的代码
            //var queryResultWithV2 = client.getReceivedApi("1739302794");
            //var querResultWithV3 = client.getReceivedApi_v3("1739302794");
        }
        catch (APIRequestException e)
        {
            error += "|Error response from JPush server. Should review and fix it. ";
            error += "|HTTP Status: " + e.Status;
            error += "|Error Code: " + e.ErrorCode;
            error += "|Error Message: " + e.ErrorMessage;
        }
        catch (APIConnectionException e)
        {
            error += "e.Message";
        }
        if (error == "")
        {
            error = "success";
        }
        return(mobile + "$" + error);
    }
Example #9
0
 public JPush(string app_key, string master_secret)
 {
     client = new JPushClient(app_key, master_secret);
 }
        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\"}}";

            //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.APP_KEY;

            notifyParams.SendNo = 256;
            //notifyParams.OverrideMsgId = "1";

            result = client.sendNotification("酷派tag111111", notifyParams, extras);
            Console.WriteLine("sendNotification by tag:**返回状态:" + result.getErrorCode().ToString() +
                          "  **返回信息:" + result.getErrorMessage() +
                          "  **Send No.:" + result.getSendNo() +
                          "  msg_id:" + result.getMessageId() +
                          "  频率次数:" + result.getRateLimitQuota() +
                          "  可用频率:" + result.getRateLimitRemaining() +
                          "  重置时间:" + result.getRateLimitReset());

            Console.WriteLine("*****发送带tag消息******");

            //customParams.addPlatform(DeviceEnum.Android);
            customParams.ReceiverType = ReceiverTypeEnum.TAG;
            customParams.ReceiverValue = "tag_api";

            customParams.SendNo = 256;
            result = client.sendCustomMessage("send custom mess by tag", "tag notify content", customParams, extras);
            Console.WriteLine("sendCustomMessage:**返回状态:" + result.getErrorCode().ToString() +
                          "  **返回信息:" + result.getErrorMessage() +
                          "  **Send No.:" + result.getSendNo() +
                          "  msg_id:" + result.getMessageId() +
                          "  频率次数:" + result.getRateLimitQuota() +
                          "  可用频率:" + result.getRateLimitRemaining() +
                          "  重置时间:" + result.getRateLimitReset());

            Console.WriteLine();

            String msg_ids = "1613113584,1229760629,1174658841,1174658641";
            ReceivedResult receivedResult = client.getReceivedApi(msg_ids);

            Console.WriteLine("Report Result:");
            foreach(ReceivedResult.Received re in receivedResult.ReceivedList)
            {
                Console.WriteLine("getReceivedApi************msgid=" + re.msg_id+ "  ***andriod received="+re.android_received+" ***ios received="+re.ios_apns_sent);
            }
            Console.WriteLine();
        }
Example #11
0
 public PushService(IConfigService configService, ILogger logger)
 {
     _configService = configService;
     _logger = logger;
     _client = new JPushClient(_configService.GetByKey("PushAppKey"), _configService.GetByKey("PushMasterSecret"));
 }