友盟移动开发平台.NET版本SDK
由于项目需要给安卓、ios提供提送消息服务。找到了umeng这个平台,官方竟然没有提供.net版本的SDK,同时项目需要就拿出来和大家分享一下需要的同学们可以做个参考,建议官方提供.net版本。
这里就提供、单播、组播和广播模式
1.接口声明
public interface IMsgService
{
/// <summary>
/// 单播
/// </summary>
/// <param name="msg"></param>
MsgDTO UniCast(string msg, string deviceId); /// <summary>
/// 组播
/// </summary>
/// <param name="msg"></param>
MsgDTO GroupCast(string msg, int operatorId); /// <summary>
/// 广播
/// </summary>
/// <param name="msg"></param>
MsgDTO BroadCast(string msg);
}
2.安卓服务实现
public class AndroidMsgService : MsgServiceBase, IMsgService
{ protected static readonly string App_Master_Secret = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/Android", "appmastersecret"); protected static readonly string App_Key = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/Android", "appkey"); private AndroidMsgService()
{ } public static readonly AndroidMsgService Instance =new AndroidMsgService(); protected override string GetSign(string post_body)
{
return (String.Concat("POST", SendUrl, post_body, App_Master_Secret)).MD5().ToLower();
} public MsgDTO BroadCast(string msg)
{
var sendData = new
{
appkey = App_Key,
timestamp = GetTimeStamp,
type = "broadcast",
payload = new
{
display_type = "notification",// 通知,notification
body = new
{
//custom = msg
ticker =msg,
title = msg,
text = msg,
after_open = "go_custom",
custom=""
},
extra = new
{
key1 = "key1",
key2 = "key2"
}
},
policy = new
{
// start_time = "2013-10-29 12:00:00", //定时发送
expire_time = DateTime.Now.AddDays().ToString("yyyy-MM-dd HH:mm:ss")
},
production_mode = ProductMode,
description = "测试广播通知-android"
}; //var result = this.GetResult(sendData, GetSign(sendData.ToJson()));
//return result; var result = this.GetResult(sendData);
return result;
} public MsgDTO GroupCast(string msg, int operatorId)
{
var sendData = new
{
appkey = App_Key,
timestamp = GetTimeStamp,
type = "groupcast",
filter = new
{
where = new
{
and = new[]
{
new {tag=operatorId.ToString()}
}
}
},
payload = new
{
display_type = "notification", // 通知,notification
body = new
{
//custom = msg
ticker = msg,
title = msg,
text = msg,
after_open = "go_custom",
custom = ""
},
extra = new
{
key1 = "key1",
key2 = "key2"
}
},
policy = new
{
expire_time = DateTime.Now.AddDays().ToString("yyyy-MM-dd HH:mm:ss")
},
production_mode = ProductMode,
description = "测试组播通知-Android"
};
var result = base.GetResult(sendData);
return result;
} public MsgDTO UniCast(string msg, string deviceId)
{ var sendData = new
{
appkey = App_Key,
timestamp = GetTimeStamp,
type = "unicast",
device_tokens = deviceId,
payload = new
{
display_type = "notification", // 消息,message
body = new
{
//custom = msg
ticker = msg,
title = msg,
text = msg,
after_open = "go_custom",
custom = ""
},
extra = new
{
key1= "key1",
key2= "key2"
}
},
production_mode= ProductMode,
description = "测试单播"
};
var result = base.GetResult(sendData);
return result; } }
3.IOS服务实现
public class IosMsgService : MsgServiceBase, IMsgService
{
protected static readonly string App_Master_Secret = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/IOS", "appmastersecret"); protected static readonly string App_Key =
AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/IOS", "appkey"); public static readonly IosMsgService Instance = new IosMsgService(); private IosMsgService()
{ } protected override string GetSign(string post_body)
{
return (String.Concat("POST", SendUrl, post_body, App_Master_Secret)).MD5().ToLower();
} public MsgDTO BroadCast(string msg)
{
var sendData = new
{
appkey = App_Key,
timestamp = GetTimeStamp,
type = "broadcast",
payload = new
{
aps = new { alert = msg } // 苹果必填字段
},
policy = new
{
// start_time = "2013-10-29 12:00:00", //定时发送
expire_time = DateTime.Now.AddDays().ToString("yyyy-MM-dd HH:mm:ss")
},
production_mode = ProductMode,
description = "测试广播通知-iOS"
}; //var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={GetSign(sendData.ToJson())}"), sendData);
//return result; var result = this.GetResult(sendData);
return result;
} public MsgDTO GroupCast(string msg,int operatorId)
{
var sendData = new
{
appkey = App_Key,
timestamp = GetTimeStamp,
type = "groupcast",
filter = new
{
where = new
{
and = new []
{
new {tag=operatorId.ToString()}
}
}
},
payload = new
{
aps = new { alert = msg } // 苹果必填字段
},
policy = new
{
expire_time = DateTime.Now.AddDays().ToString("yyyy-MM-dd HH:mm:ss")
},
production_mode = ProductMode,
description = "测试组播通知-IOS"
};
var result = base.GetResult(sendData);
return result;
//var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={GetSign(sendData.ToJson())}"), sendData);
//return result;
} public MsgDTO UniCast(string msg, string deviceId)
{
var sendData = new
{
appkey = App_Key,
timestamp = GetTimeStamp,
type = "unicast",
device_tokens = deviceId,
payload = new
{
aps = new
{
alert = msg
} // 苹果必填字段
},
policy = new
{
expire_time = DateTime.Now.AddDays().ToString("yyyy-MM-dd HH:mm:ss")
},
production_mode= ProductMode,
description = "测试单播消息"
};
var result = base.GetResult(sendData);
return result;
//var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={GetSign(sendData.ToJson())}"), sendData);
//return result;
}
}
4.MsgServiceBase服务基类
public abstract class MsgServiceBase
{
protected static readonly string SendUrl = AppSettingHelper.DomainSetting.GetValue("Api/UmengMsgList/RequestUrl"); protected static readonly string ProductMode = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList", "productmode"); protected abstract string GetSign(string sendData); protected string GetTimeStamp => (DateTime.UtcNow - new DateTime(, , , , , , DateTimeKind.Utc)).TotalMilliseconds.ToString(
"#"); protected MsgDTO GetResult(dynamic sendData)
{ var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={this.GetSign(JsonConvert.SerializeObject(sendData))}"), sendData);
return result;
}
}
5.HttpUtil
public static T HttpUtil<T>(string url, dynamic data) where T :new()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/x-www-form-urlencoded"; //设置HTTP头
request.Method = "POST"; //byte[] postdata = Encoding.UTF8.GetBytes(data);
byte[] postdata = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data));
request.ContentLength = postdata.Length; Stream newStream = request.GetRequestStream();
newStream.Write(postdata, , postdata.Length);
newStream.Close(); HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
return (reader.ReadToEnd()).FromJson<T>();//得到结果
}
贴上源码:http://files.cnblogs.com/files/zpc870921/Common.rar
友盟移动开发平台.NET版本SDK的更多相关文章
- 友盟分享各平台URL设置
首先,想要进项友盟分享,需要到各平台去申请ID和KEY 比如想进行微信分享,就到微信开发者平台去创建应用,拿到对应的id和appScreat,然后进行设置: 参考资料
- 商业创新不能等?用友低代码开发平台YonBuilder为您加速!
随着云计算.人工智能.物联网.大数据.5G等新一代技术的快速发展,越来越多的企业希望借助技术的力量加速数智化转型,期许通过更加敏捷和强大的应用系统推动企业的商业创新速度.但传统软件开发周期长.开发成本 ...
- 用友低代码开发平台YonBuilder首次亮相DevRun开发者沙龙
2020年的今天,没有人会再质疑企业上云的必要性与价值所在.从高科技行业到传统领域,大大小小的企业都希望走在变革道路前列,通过企业云加快业务数字化转型,更好地维护和管理企业数据. 然而,大多数企业都很 ...
- UmengAppDemo【友盟统计SDK集成以及多渠道打包配置,基于V7.5.3版本】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 这里只是记录下集成友盟统计SDK以及简单配置多渠道打包的步骤.所以1.该Demo不能运行:2.配置多渠道打包只是一种简单的写法,具体 ...
- 友盟推送 .NET (C#) 服务端 SDK rest api 调用库
友盟推送 .NET SDK rest api 介绍 该版本是基于友盟推送2.3版本封装的,网上查询了下发现没有.NET版本的调用库,官方也没有封装.NET的版本,只有python.java.php版本 ...
- iOS开发-友盟分享(3)
iOS 友盟分享 这个主要是提到如何通过友盟去自定义分享的步骤: 一.肯定要去友盟官网下载最新的SDK包,然后将SDK导入到你的工程文件夹里面去: 二.注册友盟账号,将你的APP添加到你的账号里面然后 ...
- android开发系列之友盟统计集成
相比大家都遇到这种情况,当我们的app上线之后,我们想要实时的跟踪了解到app里面的bug情况.新增用户情况.用户相关的行为属性情况等.但是如果自己在app里面去开发集成这些功能,一方面开发工作量还挺 ...
- Android中用友盟实现QQ的第三方登录
//首先应该去友盟的官网注册你的账号,创建一个应用,获得它的APPkey,也可以用它的API上的appkey,下载SDK,下面根据API文档一步步实现就行了. //下面是友盟的APi文档 1. 产品 ...
- Android 友盟分享详细集成过程及所遇问题解决
最近项目需要针对微信.朋友圈.QQ.QQ空间集成友盟分享的功能,说实话,我也是第一次做,期间碰到过很多问题,这篇随笔就来写一下我是怎么集成友盟分享的,还有碰到哪些问题,都是怎样解决的! 其实集成友盟并 ...
随机推荐
- ACM1258邻接表
教训:使用邻接表的时候一定要把邻接表的结构组定义的足够大,不能仅仅等于节点的个数,因为线段的数量往往远超过节点的数量. 这个题目是拓扑排序练习,提高下理解. #include<iostream& ...
- phantomjs 无法打开https网站
最近一直在用phantomjs 自动登陆并爬取一些数据,突然发现爬取https类型的网站的时候无法正常操作了 困扰了两天的问题在经过google和stackoverflow的一番搜索后发现原来Phan ...
- 百度地图定位API,精度提高
我使用百度定位API DEMO上面好像就可以setCoorType("bd09ll");//百度地图坐标. 然后我找了下从其它坐标体系迁移到百度坐标. 问下: 1.那我还能不能在百 ...
- Sublime Text 3 一些简单使用
1.注释 选中需要注释的代码,“Ctrl+/”单行注释,“Ctrl+Shift+/”多行注释.同样操作,可以取消注释. 2.查找 “Ctrl+F”,在底部会出现快速搜索框,在搜索框中输入需要搜索的变量 ...
- SpringBoot打war包并部署到tomcat下运行
一.修改pom.xml. 1.packaging改为war 2.build节点添加<finalName>你的项目名</finalName> 二.修改项目启动类,继承Spring ...
- LightOJ 1326 – Race 第二类Stirling数/
简单的模板题. 题意:问n匹马出现的不同排名数. 题解:可以使用DP,本质上还是第二类Stirling数(隔板法) #include <stdio.h> #include <iost ...
- c# bootstrap-table 知识
bootstrap-table 提供手机端,电脑端访问,提供分页,筛选等. bootstrap-table说明文档:http://bootstrap-table.wenzhixin.net.cn/zh ...
- MQTT协议-MQTT协议简介及协议原理
MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的“轻量级”通讯协议,该协议构建 ...
- Everything Has Changed(HDU6354+圆交+求周长)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6354 题目: 题意:用一堆圆来切割一个圆心为原点,半径为R的圆A,问切割完毕后圆A外围剩余部分的周长( ...
- 灵活使用ARM汇编的WEAK关键字
//=====================================================================//TITLE:// 灵活使用ARM汇编的WEAK关 ...