該版本是基於友盟推送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