Moved to GitHub

已迁移到 GitHub

Project Description (项目介绍)
JPush.NET is .NET Server SDK for JPush. It can help you send, monitor and manage all your JPush messages by programming, following JPush official REST API.
(JPush.NET 是基于.NET平台的JPush服务器端的SDK。用来帮助开发者以编程的方式使用JPush官方REST API来发送、监视和管理所有的JPush推送消息。)

 

Source Code: C#

.NET framework: 4.0


Click here to view JPush official document.
(点击 这里 查看JPush官方文档.)

 

IMPORTANT NOTE (重要通告):

New way to install JPush.NET: run the following NuGet command in the Package Manager Console

(新增安装JPush.NET 的方式: 使用NuGet来安装)

PM> Install-Package JPush.NET



This project contains following parts:(项目包含2部分)

 

IMPORTANT NOTE (重要通告):

Sample for class JPushClientV3: (使用 类JPushClientV3的示例)

Here is a sample based on .NET console application.(这是一个基于.NET控制台应用程序的示例)

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using ifunction.JPush.V3;
using Newtonsoft.Json;
namespace ifunction.JPush.Test
{
    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");
JPushClientV3 client = new JPushClientV3(appKey, masterSecret); Audience audience = new Audience(); // In JPush V3, tag can be multiple added with different values. // In following code, it is to send push to those who are in ((Tag1 AND Tag2) AND (Tag3 OR Tag4)) // If you want to send to all, please use: audience.Add(PushTypeV3.Broadcast, null); audience.Add(PushTypeV3.ByTagWithinAnd, new List<string>(new string[] { "Tag1", "Tag2" })); audience.Add(PushTypeV3.ByTagWithinOr, new List<string>(new string[] { "Tag3", "Tag4" }));
// In JPush V3, Notification would not be display on screen, it would be transferred to app instead. // And different platform can provide different notification data. Notification notification = new Notification { AndroidNotification = new AndroidNotificationParameters { Title = "JPush provides V3.", Alert = "JPush V2 would be retired soon.", CustomizedValues = customizedValues }, iOSNotification = new iOSNotificationParameters { Badge = 1, Alert = "JPush V2 would be retired soon.", Sound = "YourSound", CustomizedValues = customizedValues } };
var response = client.SendPushMessage(new PushMessageRequestV3 { Audience = audience, Platform = PushPlatform.AndroidAndiOS, IsTestEnvironment = true, AppMessage = new AppMessage { Content = "Hello, this is a test push of V3 from .NET. Have a nice day!", CustomizedValue = customizedValues }, Notification = notification });
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/Push-API-v3

IMPORTANT NOTE(重要通告):
If you already use JPushClient V2 (Class: JPushClient), you can continue to use that. SDK Library would convert the old PushMessageRequest to PushMessageRequestV3 and send request based on JPush V3.
(如果你已经使用JPushClient V2,即SDK中的类 JPushClient,你可以继续使用它。SDK类库将在内部自动将PushMessageRequest转换到PushMessageRequestV3,并以V3形式访问JPush服务.)

Sample for JPushClient:

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



If you have any question or concern, you can contact me.
(如果你在使用过程中有任何问题或疑问,请联系 .)

If you are so kind to DONATE this project, please use Alipay app to scan the following QR for payment. Very appreciate!.
(如果愿意资助此项目,请使用支付宝移动客户端扫描以下二维码提供资金帮助,非常感激!)