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


    信鸽推送 .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; //600;
                xgp.Sign = null;
                //实际key请使用实际的,下面仅演示作用
                //============测试key1==============
                xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试key2==============
                //xgp.Access_id = 2100025346;
                //xgp.Access_Key = "AUP1I5W741WJ";
                //xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
                xgp.Message_type = 1;
                xgp.Expire_time = 3600;
                xgp.Message = new NotifyMessage()
                {
                    Custom_content = new  SerializableDictionary<string,string>(){
                      {"type","123"},{"type1","456"}
                    },
                    //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 = 1,
                    Title = "XGTestAllDevice-50%",
                    Content = "有中文10%,人们有1%以及,$abcdef", //中文测试
                    Vibrate = 1,
                    Ring = 1,
                    Action = new NotifyMessageAction()
                    {
                        Action_type = 2,
                        Browser = new NotifyMessageAction_Browser()
                        {
                            Url = "http://baidu.com",
                            Confirm = 0
                        },
                        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; //600;
                xgp.Sign = null;
                //============测试DEMO==============
                xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试DEMO==============
                //xgp.Access_id = 2100025346;
                //xgp.Access_Key = "AUP1I5W741WJ";
                //xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
                xgp.Message_type = 1;
                xgp.Message = new NotifyMessage()
                {
                    Title = "XGTestSingleDevice",
                    Content = "XGTestSingleDevice",
                    Vibrate = 1
                };
                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; //600;
                xgp.Sign = null;
                //============测试DEMO==============
                //xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                //xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试DEMO==============
                xgp.Access_id = 2100025346;
                //xgp.Access_Key = "AUP1I5W741WJ";
                xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
                xgp.Message_type = 1;
                xgp.Message = new NotifyMessage()
                {
                    Title = "XGTestSingleAccount",
                    Content = "XGTestSingleAccount",
                    Vibrate = 1,
                    Ring = 1
                };
                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; //600;
                xgp.Sign = null;
                //============测试DEMO==============
                //xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                //xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试DEMO==============
                xgp.Access_id = 2100025346;
                //xgp.Access_Key = "AUP1I5W741WJ";
                xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
                xgp.Message_type = 1;
                xgp.Message = new NotifyMessage()
                {
                    Title = "XGTestTagsDevice",
                    Content = "XGTestTagsDevice",
                    Vibrate = 1,
                    Ring = 1
                };
                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; //600;
                xgp.Sign = null;
                //============测试DEMO==============
                //xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                //xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试DEMO==============
                xgp.Access_id = 2100025346;
                //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 = "152947" });
                xgp.Push_ids.Add(new Push_Id_Obj() { Push_id = "152944" });
                xgp.Push_ids.Add(new Push_Id_Obj() { Push_id = "139303" });
                XGResult<XGGetMsgStatusResult> a = qqxg.PushGetMsgStatus(xgp);
    获取消息状态
    QQXGProvider qqxg = new QQXGProvider("application");
                XGPushGetAppDeviceNumParam xgp = new XGPushGetAppDeviceNumParam();
                xgp.Timestamp = null;
                xgp.Valid_time = 600; //600;
                xgp.Sign = null;
                //============测试DEMO==============
                //xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                //xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试DEMO==============
                xgp.Access_id = 2100025346;
                //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; //600;
                xgp.Sign = null;
                //============测试DEMO==============
                //xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                //xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试DEMO==============
                xgp.Access_id = 2100025346;
                //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; //600;
                xgp.Sign = null;
                //============测试DEMO==============
                //xgp.Access_id = 2100025233;
                //xgp.Access_Key = "ARQ4CB14Q92X";
                //xgp.Secret_Key = "6ae193c85570ad1cc8fc9540560093b1";
                //============测试DEMO==============
                xgp.Access_id = 2100025346;
                //xgp.Access_Key = "AUP1I5W741WJ";
                xgp.Secret_Key = "f2391810bc98c0d7435ec7c96b8f524f";
                xgp.Push_id = "139303";
                XGResult<XGStatusResult> a = qqxg.PushCancelTimingTask(xgp);
    取消定时发送的任务
    开源代码地址

     信鸽推送.NET库GitHub首页

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

  • 相关阅读:
    对自己负责~~
    继续负责
    问题的一天
    1个月=22年
    刚才写的没显示?
    布置任务
    心情很糟
    考试结束
    没有负责哈
    php获取任意时间的时间戳
  • 原文地址:https://www.cnblogs.com/NatureSex/p/4551343.html
Copyright © 2020-2023  润新知