Example #1
0
        public string InitMiMultiMessage(List <PushMsgModel> msgList)
        {
            if (msgList == null)
            {
                return(null);
            }
            StringBuilder body = new StringBuilder();

            body.Append("messages=");
            dynamic messagesList = msgList.Select(e =>
            {
                Dictionary <string, string> extra = DictionaryUtil <string, string> .StringToDictionary(e.AttachInfo);
                return(new
                {
                    target = e.DeviceToken,
                    message = new
                    {
                        payload = e.Msg,
                        notify_type = 1,
                        description = e.Msg,
                        title = e.Title,
                        extra = extra
                    },
                });
            }).ToList();
            string messages = JsonConvert.SerializeObject(messagesList);

            body.Append(messages);
            return(body.ToString());
        }
Example #2
0
        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());
        }