<p><strong>Project Description </strong><br /> JPush.NET is JPush SDK for .NET. It can help you send, monitor and manage all your JPush messages by programming, following JPush official REST API.<br /> <br /> Click <a
href="http://docs.jpush.cn/display/dev/Push+API+v2">here</a> to view JPush official document.<br /> <br /> This project contains following parts:</p>
<ul>
<li>Pure API client, following official REST API. You can <strong><a href="https://jpush.codeplex.com/releases/view/123507" target="_blank">download</a></strong> or <a href="/wikipage?title=class%3a%20JPushClient&referringTitle=Documentation"
target="_blank"> <strong>review documentation</strong></a>.</li>
<li>ASP.NET MVC based Web Portal for basic operations and simple configuration. (Can be demo)</li>
</ul>
<p> </p>
<p style="color:red">
<strong>IMPORTANT NOTE:</strong><br />
<ul>
<li>
JPush Server SDK 1.0.0 is for JPush v2, which would be retired by JPush officially.
</li>
<li>
To support v3, please download & use
<a href="https://jpush.codeplex.com/releases/" target="_blank">latest version</a>.
</li>
<li>
In
<a href="https://jpush.codeplex.com/releases/" target="_blank">latest version</a>, to make developers take minor change, class
<a href="https://jpush.codeplex.com/wikipage?title=class%3a%20JPushClient&referringTitle=Documentation" target="_blank">JPushClient</a> has been changed to use JPushClientV3 logics inside.
</li>
<li>
Major changes in v3:
<ul>
<li>Always use SSL for sending/querying push message.</li>
<li>Use Basic Authentication Header instead of hash code for authentication.</li>
<li>Split model to Message and Notification to for UI/logic.</li>
<li>Enhancement and improvement for PushType. They can be multiple used in one push for complicated filter requirements.</li>
<li>Add Windows Phone in Platform.</li>
<li>Add different models for each platform.</li>
</ul>
</li>
</ul>
</p>
<p><strong>Sample for JPushClientV3:</strong></p>
<p>Here is a sample based on .NET console application.</p>
<div class="code">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td>
<pre xml:space="preserve">
<span class="highlight-keyword" style="color: #0000FF;">using</span> System;
<span class="highlight-keyword" style="color: #0000FF;">using</span> System.Collections.Generic;
<span class="highlight-keyword" style="color: #0000FF;">using</span> System.IO;
<span class="highlight-keyword" style="color: #0000FF;">using</span> System.Net;
<span class="highlight-keyword" style="color: #0000FF;">using</span> System.Text;
<span class="highlight-keyword" style="color: #0000FF;">using</span> System.Threading;
<span class="highlight-keyword" style="color: #0000FF;">using</span> ifunction.JPush.V3;
<span class="highlight-keyword" style="color: #0000FF;">using</span> Newtonsoft.Json;
<span class="highlight-keyword" style="color: #0000FF;">namespace</span> ifunction.JPush.Test
{
<span class="highlight-keyword" style="color: #0000FF;">class</span> Program
{
<span class="highlight-keyword" style="color: #0000FF;">static</span> <span class="highlight-keyword" style="color: #0000FF;">void</span> Main(<span class="highlight-keyword" style="color: #0000FF;">string</span>[] args)
{
<span class="highlight-keyword" style="color: #0000FF;">var</span> appKey = <span class="highlight-literal" style="color: #CC0000;">"1234567890abcdef"</span>; <span class="highlight-comment" style="color: #006633;">// Your App
Key from JPush</span>
<span class="highlight-keyword" style="color: #0000FF;">var</span> masterSecret = <span class="highlight-literal" style="color: #CC0000;">"1234567890abcdef"</span>; <span class="highlight-comment" style="color: #006633;">// Your
Master Secret from JPush</span>
Dictionary<<span class="highlight-keyword" style="color: #0000FF;">string</span>, <span class="highlight-keyword" style="color: #0000FF;">string</span>> customizedValues = <span class="highlight-keyword" style="color:
#0000FF;">new</span> Dictionary<<span class="highlight-keyword" style="color: #0000FF;">string</span>, <span class="highlight-keyword" style="color: #0000FF;">string</span>>();
customizedValues.Add(<span class="highlight-literal" style="color: #CC0000;">"CK1"</span>, <span class="highlight-literal" style="color: #CC0000;">"CV1"</span>);
customizedValues.Add(<span class="highlight-literal" style="color: #CC0000;">"CK2"</span>, <span class="highlight-literal" style="color: #CC0000;">"CV2"</span>);
JPushClientV3 client = <span class="highlight-keyword" style="color: #0000FF;">new</span> JPushClientV3(appKey, masterSecret);
Audience audience = <span class="highlight-keyword" style="color: #0000FF;">new</span> Audience();
<span class="highlight-comment" style="color: #006633;">// In JPush V3, tag can be multiple added with different values.</span>
<span class="highlight-comment" style="color: #006633;">// In following code, it is to send push to those who are in ((Tag1 AND Tag2) AND (Tag3 OR Tag4))</span>
<span class="highlight-comment" style="color: #006633;">// If you want to send to all, please use: audience.Add(PushTypeV3.Broadcast, null);</span>
audience.Add(PushTypeV3.ByTagWithinAnd, <span class="highlight-keyword" style="color: #0000FF;">new</span> List<<span class="highlight-keyword" style="color: #0000FF;">string</span>>(<span class="highlight-keyword" style="color:
#0000FF;">new</span> <span class="highlight-keyword" style="color: #0000FF;">string</span>[] { <span class="highlight-literal" style="color: #CC0000;">"Tag1"</span>, <span class="highlight-literal" style="color: #CC0000;">"Tag2"</span>
}));
audience.Add(PushTypeV3.ByTagWithinOr, <span class="highlight-keyword" style="color: #0000FF;">new</span> List<<span class="highlight-keyword" style="color: #0000FF;">string</span>>(<span class="highlight-keyword" style="color:
#0000FF;">new</span> <span class="highlight-keyword" style="color: #0000FF;">string</span>[] { <span class="highlight-literal" style="color: #CC0000;">"Tag3"</span>, <span class="highlight-literal" style="color: #CC0000;">"Tag4"</span>
}));
<span class="highlight-comment" style="color: #006633;">// In JPush V3, Notification would not be display on screen, it would be transferred to app instead.</span>
<span class="highlight-comment" style="color: #006633;">// And different platform can provide different notification data.</span>
Notification notification = <span class="highlight-keyword" style="color: #0000FF;">new</span> Notification
{
AndroidNotification = <span class="highlight-keyword" style="color: #0000FF;">new</span> AndroidNotificationParameters
{
Title = <span class="highlight-literal" style="color: #CC0000;">"JPush provides V3."</span>,
Alert = <span class="highlight-literal" style="color: #CC0000;">"JPush V2 would be retired soon."</span>,
CustomizedValues = customizedValues
},
iOSNotification = <span class="highlight-keyword" style="color: #0000FF;">new</span> iOSNotificationParameters
{
Badge = <span class="highlight-number">1</span>,
Alert = <span class="highlight-literal" style="color: #CC0000;">"JPush V2 would be retired soon."</span>,
Sound = <span class="highlight-literal" style="color: #CC0000;">"YourSound"</span>,
CustomizedValues = customizedValues
}
};
<span class="highlight-keyword" style="color: #0000FF;">var</span> response = client.SendPushMessage(<span class="highlight-keyword" style="color: #0000FF;">new</span> PushMessageRequestV3
{
Audience = audience,
Platform = PushPlatform.AndroidAndiOS,
IsTestEnvironment = <span class="highlight-keyword" style="color: #0000FF;">true</span>,
AppMessage = <span class="highlight-keyword" style="color: #0000FF;">new</span> AppMessage
{
Content = <span class="highlight-literal" style="color: #CC0000;">"Hello, this is a test push of V3 from .NET. Have a nice day!"</span>,
CustomizedValue = customizedValues
},
Notification = notification
});
Console.WriteLine(response.ResponseCode.ToString() + <span class="highlight-literal" style="color: #CC0000;">":"</span> + response.ResponseMessage);
Console.WriteLine(<span class="highlight-literal" style="color: #CC0000;">"Push sent."</span>);
Console.WriteLine(response.ResponseCode.ToString() + <span class="highlight-literal" style="color: #CC0000;">":"</span> + response.ResponseMessage);
List<<span class="highlight-keyword" style="color: #0000FF;">string</span>> idToCheck = <span class="highlight-keyword" style="color: #0000FF;">new</span> List<<span class="highlight-keyword" style="color:
#0000FF;">string</span>>();
idToCheck.Add(response.MessageId);
<span class="highlight-keyword" style="color: #0000FF;">var</span> statusList = client.QueryPushMessageStatus(idToCheck);
Console.WriteLine(<span class="highlight-literal" style="color: #CC0000;">"Status track is completed."</span>);
<span class="highlight-keyword" style="color: #0000FF;">if</span> (statusList != <span class="highlight-keyword" style="color: #0000FF;">null</span>)
{
<span class="highlight-keyword" style="color: #0000FF;">foreach</span> (<span class="highlight-keyword" style="color: #0000FF;">var</span> one <span class="highlight-keyword" style="color: #0000FF;">in</span> statusList)
{
Console.WriteLine(<span class="highlight-keyword" style="color: #0000FF;">string</span>.Format(<span class="highlight-literal" style="color: #CC0000;">"Id: {0}, Android: {1}, iOS: {2}"</span>, one.MessageId, one.AndroidDeliveredCount,
one.ApplePushNotificationDeliveredCount));
}
}
Console.WriteLine(<span class="highlight-literal" style="color: #CC0000;">"Press any key to exit."</span>);
Console.Read();
}
}
}</pre>
</td>
</tr>
</table>
</div>
<p>RESTful API reference: <a href="http://docs.jpush.cn/display/dev/Push-API-v3">http://docs.jpush.cn/display/dev/Push-API-v3</a></p>
<p style="color:red">
<strong>IMPORTANT NOTE:</strong><br />
If you already use JPushClient V2 (Class: JPushClient), you can continue to use that. Library would convert the old PushMessageRequest to PushMessageRequestV3.
</p>
<p><strong>Sample for <a href="https://jpush.codeplex.com/wikipage?title=class%3a%20JPushClient&referringTitle=Documentation" target="_blank">JPushClient</a>:</strong></p>
<p>Here is a sample based on .NET console application.</p>
<div>
<table width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<pre><span style="color: #0000ff;">class</span> Program
{
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span>[] args)
{
<span style="color: #0000ff;">var</span> appKey = <span style="color: #cc0000;">"1234567890abcdef"</span>; <span style="color: #006633;">// Your App Key from JPush</span>
<span style="color: #0000ff;">var</span> masterSecret = <span style="color: #cc0000;">"1234567890abcdef"</span>; <span style="color: #006633;">// Your Master Secret from JPush</span>
Dictionary<<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">string</span>> customizedValues = <span style="color: #0000ff;">new</span> Dictionary<<span style="color: #0000ff;">string</span>,<span style="color: #0000ff;">string</span>>();
customizedValues.Add(<span style="color: #cc0000;">"CK1"</span>, <span style="color: #cc0000;">"CV1"</span>);
customizedValues.Add(<span style="color: #cc0000;">"CK2"</span>, <span style="color: #cc0000;">"CV2"</span>);
JPushClient client = <span style="color: #0000ff;">new</span> JPushClient(appKey, masterSecret, <span style="color: #0000ff;">false</span>);
<span style="color: #0000ff;">var</span> response = client.SendPushMessage(<span style="color: #0000ff;">new</span> PushMessageRequest
{
MessageType = MessageType.Notification,
Platform = PushPlatform.Android,
Description = <span style="color: #cc0000;">"DotNET"</span>,
PushType = PushType.Broadcast,
IsTestEnvironment = <span style="color: #0000ff;">true</span>,
Message = <span style="color: #0000ff;">new</span> PushMessage
{
Content = <span style="color: #cc0000;">"Hello, this is a test push from .NET. Have a nice day!"</span>,
PushTitle = <span style="color: #cc0000;">"A title."</span>,
Sound = <span style="color: #cc0000;">"YourSound"</span>,
CustomizedValue = customizedValues
}
});
Console.WriteLine(response.ResponseCode.ToString() + <span style="color: #cc0000;">":"</span> + response.ResponseMessage);
Console.WriteLine(<span style="color: #cc0000;">"Push sent."</span>);
Console.WriteLine(response.ResponseCode.ToString() + <span style="color: #cc0000;">":"</span> + response.ResponseMessage);
List<<span style="color: #0000ff;">string</span>> idToCheck = <span style="color: #0000ff;">new</span> List<<span style="color: #0000ff;">string</span>>();
idToCheck.Add(response.MessageId);
<span style="color: #0000ff;">var</span> statusList = client.QueryPushMessageStatus(idToCheck);
Console.WriteLine(<span style="color: #cc0000;">"Status track is completed."</span>);
<span style="color: #0000ff;">if</span> (statusList != <span style="color: #0000ff;">null</span>)
{
<span style="color: #0000ff;">foreach</span> (<span style="color: #0000ff;">var</span> one <span style="color: #0000ff;">in</span> statusList)
{
Console.WriteLine(<span style="color: #0000ff;">string</span>.Format(<span style="color: #cc0000;">"Id: {0}, Android: {1}, iOS: {2}"</span>, one.MessageId, one.AndroidDeliveredCount, one.ApplePushNotificationDeliveredCount));
}
}
Console.WriteLine(<span style="color: #cc0000;">"Press any key to exit."</span>);
Console.Read();
}
}</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>RESTful API reference: <a href="http://docs.jpush.cn/display/dev/Index">http://docs.jpush.cn/display/dev/Index</a></p>
<p>
<br />
<br /> If you have any question or concern, you can contact <a href="mailto:rynn.wang@live.com"> me</a>.
</p>