友盟推送 .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個方法php

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

怎麼樣夠簡單吧!!html

 

調用推送以前首先得實例化主體推送對象java

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

這樣您能夠把必須的2個配置放到web.config裏面,或者其餘配置,賦值給對象後,後續全部的推送都無需添加此2項參數python

 

調用代碼示例一(推送給全部用戶)

 

/// <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  源碼對你有幫助的話,請給星星喲。android

相關文章
相關標籤/搜索