麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

友盟移動(dòng)開發(fā)平臺(tái).NET版本SDK

2019-11-14 13:46:56
字體:
供稿:網(wǎng)友

由于項(xiàng)目需要給安卓、ios提供提送消息服務(wù)。找到了umeng這個(gè)平臺(tái),官方竟然沒有提供.net版本的SDK,同時(shí)項(xiàng)目需要就拿出來和大家分享一下需要的同學(xué)們可以做個(gè)參考,建議官方提供.net版本。

這里就提供、單播、組播和廣播模式

1.接口聲明

 1  public interface IMsgService 2     { 3         /// <summary> 4         /// 單播 5         /// </summary> 6         /// <param name="msg"></param> 7         MsgDTO UniCast(string msg, string deviceId); 8  9         /// <summary>10         /// 組播11         /// </summary>12         /// <param name="msg"></param>13         MsgDTO GroupCast(string msg, int OperatorId);14 15         /// <summary>16         /// 廣播17         /// </summary>18         /// <param name="msg"></param>19         MsgDTO BroadCast(string msg);20     }
View Code

 

2.安卓服務(wù)實(shí)現(xiàn)

  1 public class AndroidMsgService : MsgServiceBase, IMsgService  2     {  3   4         PRotected static readonly string App_Master_Secret = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/Android", "appmastersecret");  5   6         protected static readonly string App_Key = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/Android", "appkey");  7   8   9         private AndroidMsgService() 10         { 11  12         } 13  14         public static readonly AndroidMsgService Instance =new AndroidMsgService(); 15  16         protected override string GetSign(string post_body) 17         { 18             return (String.Concat("POST", SendUrl, post_body, App_Master_Secret)).md5().ToLower(); 19         } 20  21         public MsgDTO BroadCast(string msg) 22         { 23             var sendData = new 24             { 25                 appkey = App_Key, 26                 timestamp = GetTimeStamp, 27                 type = "broadcast", 28                 payload = new 29                 { 30                     display_type = "notification",// 通知,notification 31                     body = new 32                     { 33                         //custom = msg 34                         ticker =msg, 35                         title = msg, 36                         text = msg, 37                         after_open = "go_custom", 38                         custom="0" 39                     }, 40                     extra = new 41                     { 42                         key1 = "key1", 43                         key2 = "key2" 44                     } 45                 }, 46                 policy = new 47                 { 48                     // start_time = "2013-10-29 12:00:00", //定時(shí)發(fā)送 49                     expire_time = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd HH:mm:ss") 50                 }, 51                 production_mode = ProductMode, 52                 description = "測試廣播通知-android" 53             }; 54  55             //var result = this.GetResult(sendData, GetSign(sendData.ToJson())); 56             //return result; 57  58             var result = this.GetResult(sendData); 59             return result; 60         } 61  62         public MsgDTO GroupCast(string msg, int operatorId) 63         { 64             var sendData = new 65             { 66                 appkey = App_Key, 67                 timestamp = GetTimeStamp, 68                 type = "groupcast", 69                 filter = new 70                 { 71                     where = new 72                     { 73                         and = new[] 74                         { 75                             new {tag=operatorId.ToString()} 76                         } 77                     } 78                 }, 79                 payload = new 80                 { 81                     display_type = "notification", // 通知,notification 82                     body = new 83                     { 84                         //custom = msg 85                         ticker = msg, 86                         title = msg, 87                         text = msg, 88                         after_open = "go_custom", 89                         custom = "0" 90                     }, 91                     extra = new 92                     { 93                         key1 = "key1", 94                         key2 = "key2" 95                     } 96                 }, 97                 policy = new 98                 { 99                     expire_time = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd HH:mm:ss")100                 },101                 production_mode = ProductMode,102                 description = "測試組播通知-Android"103             };104             var result = base.GetResult(sendData);105             return result;106         }107 108         public MsgDTO UniCast(string msg, string deviceId)109         {110 111             var sendData = new112             {113                 appkey = App_Key,114                 timestamp = GetTimeStamp,115                 type = "unicast",116                 device_tokens = deviceId,117                 payload = new118                 {119                     display_type = "notification", // 消息,message120                     body = new121                     {122                         //custom = msg123                         ticker = msg,124                         title = msg,125                         text = msg,126                         after_open = "go_custom",127                         custom = "0"128                     },129                     extra = new130                     {131                         key1= "key1",132                         key2= "key2"133                     }134                 },135                 production_mode= ProductMode,136                 description = "測試單播"137             };138             var result = base.GetResult(sendData);139             return result;140 141         }142 143 144     }
View Code

3.IOS服務(wù)實(shí)現(xiàn)

  1 public class IosMsgService : MsgServiceBase, IMsgService  2     {  3         protected static readonly string App_Master_Secret = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/IOS", "appmastersecret");  4   5         protected static readonly string App_Key =  6             AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList/IOS", "appkey");  7   8         public static readonly IosMsgService Instance = new IosMsgService();  9  10         private IosMsgService() 11         { 12              13         } 14  15         protected override string GetSign(string post_body) 16         { 17             return (String.Concat("POST", SendUrl, post_body, App_Master_Secret)).MD5().ToLower(); 18         } 19  20         public MsgDTO BroadCast(string msg) 21         { 22             var sendData = new 23             { 24                 appkey = App_Key, 25                 timestamp = GetTimeStamp, 26                 type = "broadcast", 27                 payload = new 28                 { 29                     aps = new { alert = msg } // 蘋果必填字段 30                 }, 31                 policy = new 32                 { 33                     // start_time = "2013-10-29 12:00:00", //定時(shí)發(fā)送 34                     expire_time = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd HH:mm:ss") 35                 }, 36                 production_mode = ProductMode, 37                 description = "測試廣播通知-iOS" 38             }; 39  40             //var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={GetSign(sendData.ToJson())}"), sendData); 41             //return result; 42  43             var result = this.GetResult(sendData); 44             return result; 45         } 46  47         public MsgDTO GroupCast(string msg,int operatorId) 48         { 49             var sendData = new 50             { 51                 appkey = App_Key, 52                 timestamp = GetTimeStamp, 53                 type = "groupcast", 54                 filter = new 55                 { 56                     where = new 57                     { 58                         and = new [] 59                         { 60                             new {tag=operatorId.ToString()} 61                         } 62                     } 63                 }, 64                 payload = new 65                 { 66                     aps = new { alert = msg } // 蘋果必填字段 67                 }, 68                 policy = new 69                 { 70                     expire_time = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd HH:mm:ss") 71                 }, 72                 production_mode = ProductMode, 73                 description = "測試組播通知-IOS" 74             }; 75             var result = base.GetResult(sendData); 76             return result; 77             //var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={GetSign(sendData.ToJson())}"), sendData); 78             //return result; 79         } 80  81         public MsgDTO UniCast(string msg, string deviceId) 82         { 83             var sendData = new 84             { 85                 appkey = App_Key, 86                 timestamp = GetTimeStamp, 87                 type = "unicast", 88                 device_tokens = deviceId, 89                 payload = new 90                 { 91                     aps = new 92                     { 93                         alert = msg 94                     } // 蘋果必填字段 95                 }, 96                 policy = new 97                 { 98                     expire_time = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd HH:mm:ss") 99                 },100                 production_mode= ProductMode,101                 description = "測試單播消息"102             };103             var result = base.GetResult(sendData);104             return result;105             //var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={GetSign(sendData.ToJson())}"), sendData);106             //return result;107         }108     }
View Code

4.MsgServiceBase服務(wù)基類

 1 public abstract class MsgServiceBase 2     { 3         protected static readonly string SendUrl = AppSettingHelper.DomainSetting.GetValue("Api/UmengMsgList/RequestUrl"); 4  5         protected static readonly string ProductMode = AppSettingHelper.DomainSetting.GetAttribute<string>("Api/UmengMsgList", "productmode"); 6  7         protected abstract string GetSign(string sendData); 8  9         protected string GetTimeStamp => (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString(10             "#");11 12         protected MsgDTO GetResult(dynamic sendData)13         {14             15             var result = RequestHelper.HttpUtil<MsgDTO>(String.Concat(SendUrl, $"?sign={this.GetSign(JsonConvert.SerializeObject(sendData))}"), sendData);16             return result;17         }18     }
View Code

5.HttpUtil

 1 public static T HttpUtil<T>(string url, dynamic data) where T :new() 2         { 3             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 4             request.ContentType = "application/x-www-form-urlencoded"; //設(shè)置HTTP頭 5             request.Method = "POST"; 6  7             //byte[] postdata = Encoding.UTF8.GetBytes(data); 8             byte[] postdata = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data)); 9             request.ContentLength = postdata.Length;10 11             Stream newStream = request.GetRequestStream();12             newStream.Write(postdata, 0, postdata.Length);13             newStream.Close();14             15 16 17             HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();18             StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);19            return  (reader.ReadToEnd()).FromJson<T>();//得到結(jié)果20         }
View Code

 貼上源碼:http://files.VEVb.com/files/zpc870921/Common.rar


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美黄色一级片在线观看 | 中文欧美日韩 | 日日爱99| 久久久久久久久久久久久久久伊免 | 亚洲小视频网站 | 最新黄色电影网站 | a免费毛片| 精品一区二区三区在线观看视频 | 一级片999 | 日韩视频在线视频 | 吾色视频 | 国产亚洲精彩视频 | 性生活视频网站 | 欧美成人免费一区二区三区 | 伊久在线 | 亚洲国产超高清a毛毛片 | 国产精品爱久久久久久久 | 色成人在线 | 成人在线观看地址 | 新久草在线视频 | 国产欧美一区二区三区免费看 | 亚洲操比视频 | 精品成人av一区二区在线播放 | 91精品国产91 | 国产一级一级片 | 国产午夜三级一区二区三桃花影视 | 亚洲一级簧片 | 国产一区二区三区视频在线观看 | 久久成人在线观看 | 精品久久久久久久久久 | 激情综合网俺也去 | 国产一区二区国产 | 美女福利视频国产 | 精品久久久一二三区播放播放播放视频 | 成人激情在线观看 | 一区二区三区国产在线 | 日日碰日日操 | 久久欧美亚洲另类专区91大神 | 亚洲天堂岛国片 | 亚洲人成在线播放网站 | av国产片|