zoukankan      html  css  js  c++  java
  • .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; }
        }

    与君共勉

  • 相关阅读:
    【HDU2007】平方和与立方和
    NetCore3.1使用Nexus包管理生成docker镜像(含权限)
    NetCore3.1使用nacos访问阿里云ACM配置中心中KVM加密后的配置
    【架构笔记】基础篇04 数组、队列、链表
    【架构笔记】基础篇03 CPU的运行与其对线程的影响
    【架构笔记】基础篇02 网络模型与细节思维方式构建
    【架构笔记】基础篇01 CPU运行基本原理
    dotnetcore使用selenium爬取svn代码路径目录
    【架构笔记】基础篇 09 简述N种查找算法
    【架构笔记】基础篇 08简述N种排序算法
  • 原文地址:https://www.cnblogs.com/qyzBlog/p/3621016.html
Copyright © 2011-2022 走看看