.NET平台下 极光推送

正好看到别人发了个极光的推送例子,想来前面也刚做过这个,就把我的push类共享下

public class JPush

    {

        /// <summary>

        /// push信息到手机应用上   JPush.Push("sanheng", "分站故障", "东三强力皮带头1分站故障,请查看", "")

        /// 具体参数说明详看http://docs.jpush.cn/display/dev/Push+API+v2

        /// </summary>

        public static string Push(string alias, string sendername, string title, string taskid)

        {

            string sendno = "1";

            string receiverType = "2";

            string receiverValue = alias;

            string masterSecret = "c01903e397720a31651e14b4";

            string copy = sendno + receiverType + receiverValue + masterSecret;

            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();

            string verificationCode = BitConverter.ToString((md5.ComputeHash(Encoding.UTF8.GetBytes(copy)))).Replace("-", "").ToLower();



            JPushMessageContent message = new JPushMessageContent

            {

                n_title = sendername,

                n_content = title,

                n_extras = new JPushMessageExtras

                {

                    task_id = taskid

                },

            };

            NameValueCollection parameters = new NameValueCollection();

            parameters.Add("sendno", sendno);

            parameters.Add("app_key", "82fc1fa74f4ac08958a7a830");

            parameters.Add("receiver_type", receiverType);//2、指定的 tag。3、指定的 alias。4、广播:对 app_key 下的所有用户推送消息。  

            parameters.Add("receiver_value", receiverValue);

            parameters.Add("verification_code", verificationCode);   //MD5  

            parameters.Add("msg_type", "1");  //1、通知2、自定义消息(只有 Android 支持)

            parameters.Add("msg_content", JsonConvert.SerializeObject(message));        //内容  

            parameters.Add("platform", "android,ios");





            WebClient webClient = new WebClient();

            webClient.Encoding = Encoding.UTF8;

            byte[] rData = webClient.UploadValues("http://api.jpush.cn:8800/sendmsg/v2/sendmsg", parameters);

            string rString = Encoding.UTF8.GetString(rData);

            return rString;

        }



    }

    public class JPushMessageContent

    {

        //n_builder_id 可选1-1000的数值,不填则默认为 0,使用 极光Push SDK 的默认通知样式。只有 Android 支持这个参数。进一步了解请参考文档 通知栏样式定制API

        public string n_title { get; set; }// 可选通知标题。不填则默认使用该应用的名称。只有 Android支持这个参考。

        public string n_content { get; set; } //必须通知内容。

        public JPushMessageExtras n_extras { get; set; }//可选 通知附加参数。JSON格式。客户端可取得全部内容。

    }

    public class JPushMessageExtras

    {

        public string task_id { get; set; }

    }

与君共勉

你可能感兴趣的:(.net)