public static SenderRet PushMsg(PushChannelModel channel, PushMsgModel msg) { IOSPushDto iospush = PushMsgModelToIOSPushDto(channel, msg); int timeOut = channel.PushNum == 0 ? 2 : (int)Math.Ceiling((double)channel.TimeOut / channel.PushNum); return(pushApplicationSession.IPushIOSUnicast.SendMessage(iospush, timeOut)); }
public IHttpActionResult PassPushMsg([FromBody] PushMsgModel pushMsgModel) { bool processResult = false; processResult = ExecuteOrder(pushMsgModel); return(Json(new { success = processResult })); }
public static IOSPushDto PushMsgModelToIOSPushDto(PushChannelModel channel, PushMsgModel msg) { IOSPushDto iospush = new IOSPushDto { PushUrl = channel.Url, AppKey = channel.AppKey, AppMasterSecret = channel.AppSecret, DeviceTokens = msg.DeviceToken, ProductionMode = channel.ProductionMode, Alert = msg.Msg, Description = msg.Title, TimeStamp = Convert.ToString((int)(CurrentUnixTimeMillis() / 1000)), Sound = "default" }; if (!string.IsNullOrEmpty(msg.AttachInfo)) { try { iospush.Extra = JsonConvert.DeserializeObject <Dictionary <string, string> >(msg.AttachInfo); } catch { //LogHelper.Info.Write("PushMsg", string.Format("AttachInfo:{0},字段中内容不符合规范,序列化失败,置为空继续发送", msg.AttachInfo)); iospush.Extra = null; } } return(iospush); }
public SenderRet Send(PushChannelModel channel, PushMsgModel msg) { if (msg.SystemType == SystemTypeEnum.Android) { return(AndroidSender.PushMsg(channel, msg)); } return(IOSSender.PushMsg(channel, msg)); }
private void DebugPushMsgModel(PushMsgModel pushMsgModel) { LogManager.PrintLogMessage("RelayController", "DebugPushMsgModel", "push msg model -> orderType: " + pushMsgModel.orderType, DefineManager.LOG_LEVEL_DEBUG); LogManager.PrintLogMessage("RelayController", "DebugPushMsgModel", "push msg model -> downloadUrl: " + pushMsgModel.downloadUrl, DefineManager.LOG_LEVEL_DEBUG); LogManager.PrintLogMessage("RelayController", "DebugPushMsgModel", "push msg model -> updateTargetPath: " + pushMsgModel.updateTargetPath, DefineManager.LOG_LEVEL_DEBUG); LogManager.PrintLogMessage("RelayController", "DebugPushMsgModel", "push msg model -> msg: " + pushMsgModel.msg, DefineManager.LOG_LEVEL_DEBUG); LogManager.PrintLogMessage("RelayController", "DebugPushMsgModel", "push msg model -> version: " + pushMsgModel.version, DefineManager.LOG_LEVEL_DEBUG); LogManager.PrintLogMessage("RelayController", "DebugPushMsgModel", "push msg model -> callbackUrl: " + pushMsgModel.callbackUrl, DefineManager.LOG_LEVEL_DEBUG); }
/// <summary> /// 推送消息给推送平台 /// </summary> /// <param name="sendProcessDto">推送消息</param> /// <param name="rzTokenBrandDto">注册信息</param> /// <param name="rzTokenBrandDetailDto">注册明细</param> /// <param name="channelDto">通道</param> /// <param name="appChannelDto">App和通道的关系</param> /// <param name="requestTime">请求时间</param> /// <returns></returns> public SenderRet SendPushMsgToProvider(SendProcessDto sendProcessDto, DeviceChannelDto deviceChannelDto, out int requestTime) { SenderRet senderRet = new SenderRet { IsSuccess = true }; //底层发送消息 requestTime = 0; //获取ProductionMode object ProducttMode = _configLogic.GetConfigValue(ConfigKey.ProductionMode); //构造底层推送消息的参数 PushChannelModel pushChannelModel = new PushChannelModel { ChannelName = deviceChannelDto.ChannelName, Url = deviceChannelDto.Url, AppKey = deviceChannelDto.AppKey, AppSecret = deviceChannelDto.AppSecret, ProductionMode = Convert.ToBoolean(ProducttMode) //获取调试模式 }; PushMsgModel pushMsgModel = new PushMsgModel { Ticker = sendProcessDto.Title, Title = sendProcessDto.Title, Msg = sendProcessDto.Msg, AttachInfo = sendProcessDto.AttachInfo, DeviceToken = deviceChannelDto.DeviceToken, SystemType = (SystemTypeEnum)deviceChannelDto.SystemType }; ISender sender = PushSenderManager.GetSender(deviceChannelDto.ChannelId); if (sender == null) { senderRet.IsSuccess = false; senderRet.Msg = string.Format("ChannelId:{0},推送信息供应商不存在", deviceChannelDto.ChannelId); //LogHelper.Error.Write("SendPushMsgToProvider", senderRet.Msg); return(senderRet); } Stopwatch sw = new Stopwatch(); var isRealPushMsg = _configLogic.GetConfigValue(ConfigKey.IsRealPushMsg); sw.Start(); if (isRealPushMsg != null && Convert.ToBoolean(isRealPushMsg)) { senderRet = PushSender.Send(sender, pushChannelModel, pushMsgModel); } else { Thread.Sleep(200); senderRet = new SenderRet { IsSuccess = true, Sign = Guid.NewGuid().ToString() }; } sw.Stop(); requestTime = (int)sw.ElapsedMilliseconds; return(senderRet); }
public SenderRet Send(PushChannelModel channel, PushMsgModel msg) { if (channel.SystemType == SystemTypeEnum.Android || msg.SystemType == SystemTypeEnum.Android) { return(UniCast.SendMessage(channel, msg)); } return(new SenderRet() { IsSuccess = false, Code = "-1", Msg = "华为推送通道只支持android" }); }
/// <summary> /// 单播发送友盟消息 /// </summary> /// <param name="channel"></param> /// <param name="msg"></param> /// <returns></returns> public override SenderRet SendMessage(object channel, object msg) { PushChannelModel pushChannelModel = channel as PushChannelModel; PushMsgModel pushMsgModel = msg as PushMsgModel; string url = pushChannelModel.Url; string appSecret = pushChannelModel.AppSecret; var bodyStr = InitMiMessage(pushMsgModel); var ret = SendToMiPush(bodyStr, url, appSecret); return(ret); }
/// <summary> /// 生成消息体 /// </summary> /// <param name="model"></param> /// <param name="accessToken"></param> /// <returns></returns> public static string GeneratePostBody(PushMsgModel model, string accessToken) { List <Dictionary <string, object> > extra = new List <Dictionary <string, object> >(); if (model.AttachInfo != null) { extra = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object> >(model.AttachInfo).ConvertToDicList(); } AndroidModel androidModel = new AndroidModel(model.Title, model.Msg, 1, extra); string android = Newtonsoft.Json.JsonConvert.SerializeObject(androidModel); int cacheMode = 1; int msgType = 1; long nsp_ts = (long)(DateTimeHelper.GetNow().Subtract(new DateTime(1970, 1, 1)).TotalSeconds); // 构造请求 Dictionary <string, object> dic = new Dictionary <string, object>(); //必选 ,取值建议固定为“JSON”,另外两种取值为:“php-rpc”和“JS” dic.Add("nsp_fmt", "JSON"); // 目标用户,必选。 // 由客户端获取, 32 字节长度。手机上安装了push应用后,会到push服务器申请token,申请到的token会上报给应用服务器 //dic.Add("deviceToken", HttpUtility.UrlEncode(model.DeviceToken)); //// 必选 使用 OAuth2进行鉴权时的 AccessToken //dic.Add("access_token", HttpUtility.UrlEncode(accessToken)); //// 可选 //// 0: 当前用户 //// 1: 主要用户 //// -1: 默认用户 //dic.Add("userType", 1); //// 发送到设备上的消息,必选 //// 最长为4096 字节(开发者自定义,自解析) //dic.Add("android", HttpUtility.UrlEncode(android)); // 消息是否需要缓存,必选 // 0:不缓存 // 1:缓存 // 缺省值为0 dic.Add("cacheMode", cacheMode); // 标识消息类型(缓存机制),必选 // 由调用端赋值,取值范围(1~100)。当TMID+msgType的值一样时,仅缓存最新的一条消息 dic.Add("msgType", msgType); // unix时间戳,可选 // 格式:2013-08-29 19:55 // 消息过期删除时间 // 如果不填写,默认超时时间为当前时间后48小时 dic.Add("nsp_ts", nsp_ts); // 单播模式 dic.Add("nsp_svc", "openpush.message.psSingleSend"); string postData = dic.ConvertToParam(); return(postData); }
private bool ExecuteOrder(PushMsgModel pushMsgModel) { ADC_Status adcStatus = new ADC_Status(); ADCManager adcManager = new ADCManager(); adcStatus.ADC_Index = adcManager.CreateNewProcess(pushMsgModel); adcStatus.ADC_ProcessStatus = DefineManager.STATUS_CODE_RECEIVE_PUSH_MSG; ExecuteManager executeManager = new ExecuteManager(); executeManager.pushMsgModel = pushMsgModel; executeManager.adcManager = adcManager; executeManager.adcStatus = adcStatus; adcManager.UpdateCurrentProcessStatus(adcStatus); return(executeManager.Execute()); }
public int CreateNewProcess(PushMsgModel pushMsgModel) { int newProcessId = DefineManager.NOT_AVAILABLE; using (AutoDeployClientEntities context = new AutoDeployClientEntities()) using (var tran = context.Database.BeginTransaction()) { try { ADC_PushData adcPushData = new ADC_PushData(); adcPushData.ADC_OrderType = pushMsgModel.orderType; adcPushData.ADC_DownloadUrl = pushMsgModel.downloadUrl; adcPushData.ADC_UpdateTargetPath = pushMsgModel.updateTargetPath; adcPushData.ADC_PushMsg = pushMsgModel.msg; adcPushData.ADC_Version = pushMsgModel.version; adcPushData.ADC_CallbackUrl = pushMsgModel.callbackUrl; adcPushData.ADC_FileType = pushMsgModel.fileType; context.ADC_PushData.Add(adcPushData); context.SaveChanges(); newProcessId = adcPushData.ADC_Index; ADC_Status adcStatus = new ADC_Status(); adcStatus.ADC_Index = newProcessId; adcStatus.ADC_ProcessStatus = DefineManager.STATUS_CODE_DEFAULT; adcStatus.ADC_UpdateDateTime = DateTime.Now; context.ADC_Status.Add(adcStatus); context.SaveChanges(); tran.Commit(); LogManager.PrintLogMessage("ADCManager", "CreateNewProcess", "process created, id: " + newProcessId, DefineManager.LOG_LEVEL_DEBUG); } catch (Exception err) { tran.Rollback(); LogManager.PrintLogMessage("ADCManager", "CreateNewProcess", "cannot create new process: " + err.Message, DefineManager.LOG_LEVEL_ERROR); } } return(newProcessId); }
public string InitMiMessage(PushMsgModel msg) { StringBuilder body = newBody("registration_id", SherlockWebUtility.UrlEncode(msg.DeviceToken)); //推送Msg if (!string.IsNullOrEmpty(msg.Msg)) { addParameter(body, "payload", SherlockWebUtility.UrlEncode(msg.Msg)); addParameter(body, "description", SherlockWebUtility.UrlEncode(msg.Msg)); } //推送标题 if (!string.IsNullOrEmpty(msg.Title)) { addParameter(body, "title", SherlockWebUtility.UrlEncode(msg.Title)); } addParameter(body, "notify_type", "1");//提醒类型 if (!string.IsNullOrEmpty(msg.AttachInfo)) { Dictionary <string, string> extra = DictionaryUtil <string, string> .StringToDictionary(msg.AttachInfo); if (extra != null) { foreach (var item in extra) { addParameter(body, string.Format("extra.{0}", item.Key), SherlockWebUtility.UrlEncode(item.Value)); } } } string bodyStr = body.ToString(); if (!string.IsNullOrEmpty(bodyStr) && bodyStr.ElementAt(0) == '&') { bodyStr = bodyStr.Substring(1); } return(body.ToString()); }
public SenderRet Send(PushChannelModel channel, PushMsgModel msg) { //目前MiPush只做小米手机(Android系统) return(AndroidSender.PushMsg(channel, msg)); }
public static AndroidPushDto PushMsgModelToAndroidPushDto(PushChannelModel channel, PushMsgModel msg) { AndroidPushDto androidpush = new AndroidPushDto { DeviceToken = msg.DeviceToken, ProductionMode = channel.ProductionMode, Description = msg.Ticker, Title = msg.Title, PayLoad = msg.Msg }; if (!string.IsNullOrEmpty(msg.AttachInfo)) { try { androidpush.Extra = JsonConvert.DeserializeObject <Dictionary <string, string> >(msg.AttachInfo); } catch { //LogHelper.Info.Write("PushMsg", string.Format("AttachInfo:{0},字段中内容不符合规范,序列化失败,置为空继续发送", msg.AttachInfo)); androidpush.Extra = null; } } return(androidpush); }
public static SenderRet PushMsg(PushChannelModel channel, PushMsgModel msg) { return(pushApplicationSession.IPushAndroidUnicast.SendMessage(channel, msg)); }
public static SenderRet SendMessage(PushChannelModel channel, PushMsgModel msg) { int timeout = channel.TimeOut * 1000 / channel.PushNum; return(SendToHuaweiPush(channel.Url, channel.AppKey, channel.AppSecret, timeout, msg)); }
/// <summary> /// 发送推送 /// </summary> /// <param name="url"></param> /// <param name="appKey"></param> /// <param name="appSecret"></param> /// <param name="model"></param> /// <returns></returns> public static SenderRet SendToHuaweiPush(string url, string appKey, string appSecret, int timeout, PushMsgModel model) { try { string accessToken = GetAccessToken(appKey, appSecret); string postData = GeneratePostBody(model, accessToken); HttpWebRequest request = HttpWebRequest.CreateHttp(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "gzip"; request.ContinueTimeout = timeout; using (StreamWriter sendStream = new StreamWriter(request.GetRequestStreamAsync().Result)) { sendStream.Write(postData); } HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result; using (Stream responseStream = response.GetResponseStream()) { StreamReader sr = new StreamReader(responseStream, Encoding.GetEncoding("gbk")); var msg = sr.ReadToEnd(); PushRetModel ret = Newtonsoft.Json.JsonConvert.DeserializeObject <PushRetModel>(msg); if (ret.resultcode != null) { string code = null; if (ret.resultcode != "0") { code = "Code:" + ret.resultcode; } return(new SenderRet() { Code = code, IsSuccess = ret.resultcode == "0" ? true : false, Msg = ret.message, Sign = ret.requestID }); } return(new SenderRet() { IsSuccess = false, Msg = ret.message }); } } catch (Exception ex) { //LogHelper.Error.Write("HuaweiNotification", ex); return(new SenderRet() { IsSuccess = false, Msg = ex.Message }); } }
public static AndroidPushDto PushMsgModelToAndroidPushDto(PushChannelModel channel, PushMsgModel msg) { AndroidPushDto androidpush = new AndroidPushDto { Url = channel.Url, AppKey = channel.AppKey, AppMasterSecret = channel.AppSecret, DeviceTokens = msg.DeviceToken, ProductionMode = channel.ProductionMode, Ticker = msg.Ticker, Title = msg.Title, Text = msg.Msg, Description = msg.Title, Displaytype = DisplayType.notification, //默认通知 AfterOpen = AfterOpenAction.go_custom, //默认用户自定义 TimeStamp = Convert.ToString((int)(CurrentUnixTimeMillis() / 1000)), PlayVibrate = true, PlayLights = true, PlaySound = true, }; if (!string.IsNullOrEmpty(msg.AttachInfo)) { try { androidpush.Extra = JsonConvert.DeserializeObject <Dictionary <string, string> >(msg.AttachInfo); } catch { //LogHelper.Info.Write("PushMsg", string.Format("AttachInfo:{0},字段中内容不符合规范,序列化失败,置为空继续发送", msg.AttachInfo)); androidpush.Extra = null; } } return(androidpush); }