信鸽推送 .NET (C#) 服务端 SDK rest api 调用库(v1.2)

时间:2022-06-11 20:45:20
信鸽推送 .NET  服务端 SDK rest api 调用库-介绍

该版本是基于信鸽推送v2版本的时候封装的,先拿出来与大家分享,封装还还凑合,不依赖其他http调用件,唯一依赖json序列化dll。

网上有一些封装的调用库,但是都不是自己喜欢的调用方式和封装风格,官方更没有封装.NET的版本,只有python、java、php版本,您让.NET情何以堪啊,

故咱们也来封装一个.

温馨提示:该版本是2014-8月份左右封装的,现在信鸽加了很多功能,但是存在的功能是不影响的,只需要下载源码,实体类加些参数加几个调用方法既可。

调用代码示例

【推送所有设备】

 QQXGProvider qqxg = new QQXGProvider();
XGPushAllDeviceParam xgp = new XGPushAllDeviceParam();
xgp.Timestamp = null; //1299865775;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//实际key请使用实际的,下面仅演示作用
//============测试key1==============
xgp.Access_id = ;
//xgp.Access_Key = "ARQ4CB14Q92X";
xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试key2==============
//xgp.Access_id = 2100025346;
//xgp.Access_Key = "AUP1I5W741WJ";
//xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
xgp.Message_type = ;
xgp.Expire_time = ;
xgp.Message = new NotifyMessage()
{
Custom_content = new SerializableDictionary<string,string>(){
{"type",""},{"type1",""}
},
//Accept_time = new System.Collections.Generic.List<AcceptTime>(){
// new AcceptTime(){ Start=new XGTime(){ Hour="18", Min="02"}, End=new XGTime(){ Hour="18", Min="30"}}
//},
Clearable = ,
Title = "XGTestAllDevice-50%",
Content = "有中文10%,人们有1%以及,$abcdef", //中文测试
Vibrate = ,
Ring = ,
Action = new NotifyMessageAction()
{
Action_type = ,
Browser = new NotifyMessageAction_Browser()
{
Url = "http://baidu.com",
Confirm =
},
Intent = "http://baidu.com",
Activity = "XGPushDemo"
}
}; XGResult<XGPushResult> a = qqxg.PushAllDevices(xgp);

【单个 Device_token 的手机设备】

QQXGProvider qqxg = new QQXGProvider();
XGPushSingleDeviceParam xgp = new XGPushSingleDeviceParam();
xgp.Timestamp = null;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//============测试DEMO==============
xgp.Access_id = ;
//xgp.Access_Key = "ARQ4CB14Q92X";
xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试DEMO==============
//xgp.Access_id = 2100025346;
//xgp.Access_Key = "AUP1I5W741WJ";
//xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
xgp.Message_type = ;
xgp.Message = new NotifyMessage()
{
Title = "XGTestSingleDevice",
Content = "XGTestSingleDevice",
Vibrate =
};
xgp.Device_token = "ef8d1c5b866652d14e62bbee2aac3b28b7ed2bf9";
//POSTopenapi.xg.qq.com/v2/push/all_deviceaccess_id=2100025233timestamp=1399859926valid_time=6006ae193c85570ad1cc8fc9540560093b1
XGResult<string> a = qqxg.PushSingleDevice(xgp);

单个Device_token设备

【单个账户、按标签推送、获取消息状态,获取应用添加的设备数,查询标签,取消定时发送的任务】

 QQXGProvider qqxg = new QQXGProvider();
XGPushSingleAccountParam xgp = new XGPushSingleAccountParam();
xgp.Timestamp = null;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//============测试DEMO==============
//xgp.Access_id = 2100025233;
//xgp.Access_Key = "ARQ4CB14Q92X";
//xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试DEMO==============
xgp.Access_id = ;
//xgp.Access_Key = "AUP1I5W741WJ";
xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
xgp.Message_type = ;
xgp.Message = new NotifyMessage()
{
Title = "XGTestSingleAccount",
Content = "XGTestSingleAccount",
Vibrate = ,
Ring =
};
xgp.Account = "ffff";
//POSTopenapi.xg.qq.com/v2/push/all_deviceaccess_id=2100025233timestamp=1399859926valid_time=6006ae193c85570ad1cc8fc9540560093b1
XGResult<string> a = qqxg.PushSingleAccount(xgp);

单个账户

 QQXGProvider qqxg = new QQXGProvider();
XGPushTagsDeviceParam xgp = new XGPushTagsDeviceParam();
xgp.Timestamp = null;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//============测试DEMO==============
//xgp.Access_id = 2100025233;
//xgp.Access_Key = "ARQ4CB14Q92X";
//xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试DEMO==============
xgp.Access_id = ;
//xgp.Access_Key = "AUP1I5W741WJ";
xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
xgp.Message_type = ;
xgp.Message = new NotifyMessage()
{
Title = "XGTestTagsDevice",
Content = "XGTestTagsDevice",
Vibrate = ,
Ring =
};
xgp.Tags_list = new System.Collections.Generic.List<string>();
xgp.Tags_list.Add("nature");
xgp.Tags_op = "OR";
//POSTopenapi.xg.qq.com/v2/push/all_deviceaccess_id=2100025233timestamp=1399859926valid_time=6006ae193c85570ad1cc8fc9540560093b1
XGResult<XGPushResult> a = qqxg.PushTagsDevice(xgp);
string a1 = a.Err_msg;

按标签推送

 QQXGProvider qqxg = new QQXGProvider();
XGPushGetMsgStatusParam xgp = new XGPushGetMsgStatusParam();
xgp.Timestamp = null;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//============测试DEMO==============
//xgp.Access_id = 2100025233;
//xgp.Access_Key = "ARQ4CB14Q92X";
//xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试DEMO==============
xgp.Access_id = ;
//xgp.Access_Key = "AUP1I5W741WJ";
xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
xgp.Push_ids = new System.Collections.Generic.List<Push_Id_Obj>();
xgp.Push_ids.Add(new Push_Id_Obj() { Push_id = "" });
xgp.Push_ids.Add(new Push_Id_Obj() { Push_id = "" });
xgp.Push_ids.Add(new Push_Id_Obj() { Push_id = "" });
XGResult<XGGetMsgStatusResult> a = qqxg.PushGetMsgStatus(xgp);

获取消息状态

QQXGProvider qqxg = new QQXGProvider("application");
XGPushGetAppDeviceNumParam xgp = new XGPushGetAppDeviceNumParam();
xgp.Timestamp = null;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//============测试DEMO==============
//xgp.Access_id = 2100025233;
//xgp.Access_Key = "ARQ4CB14Q92X";
//xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试DEMO==============
xgp.Access_id = ;
//xgp.Access_Key = "AUP1I5W741WJ";
xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
XGResult<XGDeviceNumResult> a = qqxg.GetAppDeviceNum(xgp);

应用添加的设备数

QQXGProvider qqxg = new QQXGProvider("tags");
XGPushQueryAppTagsParam xgp = new XGPushQueryAppTagsParam();
xgp.Timestamp = null;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//============测试DEMO==============
//xgp.Access_id = 2100025233;
//xgp.Access_Key = "ARQ4CB14Q92X";
//xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试DEMO==============
xgp.Access_id = ;
//xgp.Access_Key = "AUP1I5W741WJ";
xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f"; XGResult<XGQueryAppTagsResult> a = qqxg.QueryAppTags(xgp);

查询标签

QQXGProvider qqxg = new QQXGProvider();
XGOtherCommonParam xgp = new XGOtherCommonParam();
xgp.Timestamp = null;
xgp.Valid_time = ; //600;
xgp.Sign = null;
//============测试DEMO==============
//xgp.Access_id = 2100025233;
//xgp.Access_Key = "ARQ4CB14Q92X";
//xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
//============测试DEMO==============
xgp.Access_id = ;
//xgp.Access_Key = "AUP1I5W741WJ";
xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
xgp.Push_id = "";
XGResult<XGStatusResult> a = qqxg.PushCancelTimingTask(xgp);

取消定时发送的任务

开源代码地址

信鸽推送.NET库GitHub首页

https://github.com/jasnature/NSTool.XGPush 源码对你有帮助的话,请给星星哟。