A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/jpush/jpush-api-csharp-client/tree/v1 below:

GitHub - jpush/jpush-api-csharp-client at v1

JPush API client library for CSharp

目前推荐使用 Master 分支上的新版本库,支持 .NET Standard。该分支下的库(cn.jpush.api)今后将减少维护,一般只修复 bug。

这是 JPush REST API 的 C# 版本封装开发包,是由极光推送官方提供。

对应的 REST API 文档:http://docs.jiguang.cn/jpush/server/push/server_overview/

支持 Microsoft. NET Framework 4.0 (包括)以上版本。

jpush-api-csharp-client 项目根目录可以下载下面的两个文件。

在线方式配置:

向某单个设备或者某设备列表推送一条通知或者消息:

以下片断来自项目代码里的文件:cn.jpush.api.example 中的 JPushApiExample.cs。

PushPayload payload = PushObject_All_All_Alert();
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());
    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.ErrorMessage);
}
catch (APIConnectionException e)
{
    Console.WriteLine(e.Message);
}

进行推送的关键在于构建一个 PushPayload 对象,以下展示了一些常见的用法:

public static PushPayload PushObject_All_All_Alert()
{
    PushPayload pushPayload = new PushPayload();
    pushPayload.platform = Platform.all();
    pushPayload.audience = Audience.all();
    pushPayload.notification = new Notification().setAlert(ALERT);
    return pushPayload;
}
public static PushPayload PushObject_all_alias_alert()
{
    PushPayload pushPayload_alias = new PushPayload();
    pushPayload_alias.platform = Platform.android();
    pushPayload_alias.audience = Audience.s_alias("alias1");
    pushPayload_alias.notification = new Notification().setAlert(ALERT);
    return pushPayload_alias;
}
public static PushPayload PushObject_Android_Tag_AlertWithTitle()
{
    PushPayload pushPayload = new PushPayload();
    pushPayload.platform = Platform.android();
    pushPayload.audience = Audience.s_tag("tag1");
    pushPayload.notification =  Notification.android(ALERT,TITLE);
    return pushPayload;
}
public static PushPayload PushObject_ios_tagAnd_alertWithExtrasAndMessage()
{
    PushPayload pushPayload = new PushPayload();
    pushPayload.platform = Platform.android_ios();
    pushPayload.audience = Audience.s_tag_and("tag1", "tag_all");
    var notification = new Notification();
    notification.IosNotification = new IosNotification().setAlert(ALERT)
                                                        .setBadge(5)
                                                        .setSound("happy")
                                                        .AddExtra("from","JPush";
    pushPayload.notification = notification;
    pushPayload.message = Message.content(MSG_CONTENT);
    return pushPayload;
}
public static PushPayload PushObject_ios_audienceMore_messageWithExtras()
{         
    var pushPayload = new PushPayload();
    pushPayload.platform = Platform.android_ios();
    pushPayload.audience = Audience.s_tag("tag1","tag2");
    pushPayload.message = Message.content(MSG_CONTENT).AddExtras("from", "JPush");
    return pushPayload;
}
public static PushPayload PushSendSmsMessage()
{
    var pushPayload = new PushPayload();
    pushPayload.platform = Platform.all();
    pushPayload.audience = Audience.all();
    pushPayload.notification = new Notification().setAlert(ALERT);
    SmsMessage sms_message = new SmsMessage();
    sms_message.setContent(SMSMESSAGE);
    sms_message.setDelayTime(DELAY_TIME);
    pushPayload.sms_message = sms_message;
    return pushPayload;
}

JPush Report API V3 提供各类统计数据查询功能。

以下片断来自项目代码里的文件:cn.jpush.api.examples 中的 ReportsExample.cs。

try
{
    var result = jpushClient.getReceivedApi("1942377665");
    Console.WriteLine("Got result - " + result.ToString());
}
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.ErrorMessage);
}
catch (APIConnectionException e)
{
    Console.WriteLine(e.Message);
}

Device API 用于在服务器端查询、设置、更新、删除设备的 tag, alias 信息,使用时需要注意不要让服务端设置的标签又被客户端给覆盖了。

以下片断来自项目代码里的文件:cn.jpush.api.examples 中的 DeviceApiExample.cs。

try
{
    var result = client.updateDevice(REGISTRATION_ID, ALIAS, MOBILE,
        TAG_HASHSET, TAG_HASHSET_REMOVE);
    System.Threading.Thread.Sleep(10000);
    Console.WriteLine(result);
}
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.ErrorMessage);
}
catch (APIConnectionException e)
{
    Console.WriteLine(e.Message);
}

API 层面支持定时功能。

以下片断来自项目代码里的文件:cn.jpush.api.examples 中的 ScheduleApiExample.cs。

TriggerPayload triggerConstructor = new TriggerPayload(START, END,
    TIME_PERIODICAL, TIME_UNIT, FREQUENCY, POINT);
SchedulePayload schedulepayloadperiodical = new SchedulePayload(NAME,
    ENABLED, triggerConstructor, pushPayload);
try
{
    var result = scheduleclient.sendSchedule(schedulepayloadperiodical);
    System.Threading.Thread.Sleep(10000);
    Console.WriteLine(result);
    schedule_id = result.schedule_id;
}
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.ErrorMessage);
}
catch (APIConnectionException e)
{
    Console.WriteLine(e.Message);
}

Please contribute! Look at the issues.

MIT © JiGuang


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4