Class JPushClient
This class is the core for calling JPush API via official RESTful interfaces. There are two major features:

  • Send Push message for iOS and/or Android
  • Track delivery status via multiple message ID, which returned by JPush Service.

 

Sample:

Here is a sample based on .NET console application.

class Program
 {
      static void Main(string[] args)
      {
          var appKey = "1234567890abcdef"; // Your App Key from JPush
          var masterSecret = "1234567890abcdef"; // Your Master Secret from JPush
          Dictionary<string, string> customizedValues = new Dictionary<string, string>();
          customizedValues.Add("CK1", "CV1");
          customizedValues.Add("CK2", "CV2");
          JPushClient client = new JPushClient(appKey, masterSecret, false);
          var response = client.SendPushMessage(new PushMessageRequest
          {
              MessageType = MessageType.Notification,
              Platform = PushPlatform.Android,
              Description = "DotNET",
              PushType = PushType.Broadcast,
              IsTestEnvironment = true,
              Message = new PushMessage
              {
                  Content = "Hello, this is a test push from .NET. Have a nice day!",
                  PushTitle = "A title.",
                  Sound = "YourSound",
                  CustomizedValue = customizedValues
              }
          });
          Console.WriteLine(response.ResponseCode.ToString() + ":" + response.ResponseMessage);
          Console.WriteLine("Push sent.");
          Console.WriteLine(response.ResponseCode.ToString() + ":" + response.ResponseMessage);
          List<string> idToCheck = new List<string>();
          idToCheck.Add(response.MessageId);
          var statusList = client.QueryPushMessageStatus(idToCheck);
          Console.WriteLine("Status track is completed.");
          if (statusList != null)
          {
          foreach (var one in statusList)
              {
                  Console.WriteLine(string.Format("Id: {0}, Android: {1}, iOS: {2}", one.MessageId, one.AndroidDeliveredCount, one.ApplePushNotificationDeliveredCount));
              }
          }
          Console.WriteLine("Press any key to exit.");
          Console.Read();
      }
  }

RESTful API reference: http://docs.jpush.cn/display/dev/Index

NOTE:

  • As official document defined, the message ID collection is limited by 1000 in one track request. So if more than 1000 is set in collection for tracking, only the first 1000 can get status information in result.
  • Regarding to the possible change of official RESTful API, current client is cliamed to base on v2 version of JPush.

Last edited Mar 26, 2014 at 8:57 AM by rynnwang, version 1