友盟推送 .NET (C#) 服务端 SDK rest api 调用库

友盟推送 .NET SDK rest api 介绍

   该版本是基于友盟推送2.3版本封装的,网上查询了下发现没有.NET版本的调用库,官方也没有封装.NET的版本,只有python、java、php版本,您这又让.NET情何以堪啊,故分享一个简单易调用的版本分享给大家,本次封装的代码相比我封装的【信鸽推送】 简单很多,而且自由度很高,参数基本都是直接转json的实体,,需要根据友盟REST API   http://dev.umeng.com/push/android/api-doc 去具体赋值,所以拿到源码的同学也很容易修改josn对象实体,调用对象只有2个方法

//同步提交
public
ReturnJsonClass SendMessage(PostUMengJson paramsJsonObj) //异步提交 public void AsynSendMessage(PostUMengJson paramsJsonObj, Action<ReturnJsonClass> callback)

怎么样够简单吧!!

 

调用推送之前首先得实例化主体推送对象

1 UMengMessagePush umPush = new UMengMessagePush("你的appkey", "你的appMasterSecret");

这样您可以把必须的2个配置放到web.config里面,或者其他配置,赋值给对象后,后续所有的推送都无需添加此2项参数

 

调用代码示例一(推送给所有用户)

 

/// <summary>
        /// 推送给所有用户
        /// </summary>
        [TestMethod]
        public void TestPushByAllUser()
        {
            PostUMengJson postJson = new PostUMengJson();
            postJson.type = "broadcast";
            postJson.payload = new Payload();
            postJson.payload.display_type = "notification";
            postJson.payload.body = new ContentBody();
            postJson.payload.body.ticker = "评论提醒";
            postJson.payload.body.title = "您的评论有回复";
            postJson.payload.body.text = "您的评论有回复咯。。。。。";
            postJson.payload.body.after_open = "go_custom";
            postJson.payload.body.custom = "comment-notify";

            postJson.description = "评论提醒-UID:" + 123;

            postJson.thirdparty_id = "COMMENT";

            ReturnJsonClass resu = umPush.SendMessage(postJson);

            //umPush.SendMessage(postJson, callBack);

            Assert.AreEqual(resu.ret, "SUCCESS", true);
        }
调用代码示例二(根据自定义用户ID异步推送)

 

/// <summary>
        /// 根据自定义用户ID推送
        /// </summary>
        [TestMethod]
        public void TestPushByAlias()
        {
            PostUMengJson postJson = new PostUMengJson();
            postJson.type = "customizedcast";
            postJson.alias_type = "USER_ID";
            postJson.alias = "5583";
            postJson.payload = new Payload();
            postJson.payload.display_type = "notification";
            postJson.payload.body = new ContentBody();
            postJson.payload.body.ticker = "评论提醒Alias";
            postJson.payload.body.title = "您的评论有回复";
            postJson.payload.body.text = "Alias您的评论有回复咯。。。。。";
            postJson.payload.body.after_open = "go_custom";
            postJson.payload.body.custom = "comment-notify";

            postJson.thirdparty_id = "COMMENT";

            postJson.description = "评论提醒-UID:" + 5583;

            //ReturnJsonClass resu = umPush.SendMessage(postJson);

            umPush.AsynSendMessage(postJson, callBack);
        }

        private void callBack(ReturnJsonClass result)
        {
            ReturnJsonClass a1 = result;
        }

 

 

开源代码地址

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

 

posted @ 2015-06-12 11:18  JasNature  阅读(6165)  评论(6编辑  收藏  举报
我要赞个
我要评论
我要收藏