zoukankan      html  css  js  c++  java
  • .Net Core3.1 MVC + EF Core+ AutoFac+LayUI+Sqlserver的框架搭建极光推送

       极光推送是一款不错的开源免费的产品,能满足一般需求,但是如果想要特殊需求,还是需要付费的。极光推送系统需要配合手机端实现消息的推送,所以能不能到达,也要看收集端的配置了,关于极光推送的如何配置,请阅读:(https://www.cnblogs.com/zpy1993-09/p/14750604.html)。

     下面就是直接上代码了:

    也就要一个消息推送的通用类:

    using Jiguang.JPush;
    using Jiguang.JPush.Model;
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace Core.Net.Common.Core.Net.Core.JiGuang
    {
      
    
            public class registration_i
            {
                public List<string> registration_id = new List<string>();
            }
            public class JiGuangHelper
            {
    
                // 极光推送
                private static JPushClient client = new JPushClient("4f82eabcec25693495e4b346", "8dff2c43b3770418c9029092");
            /// <summary>
            /// 极光推送传递一个参数
            /// </summary>
            /// <param name="sTitle">标题</param>
            /// <param name="sContent">内容</param>
            /// <param name="name">参数字段</param>
            /// <param name="value">参数值</param>
            /// <param name="sAudience">all 代表广推  如果不是all,那么就是根据激光Id给特定人推送</param>
            /// <returns></returns>
                                                                                                                        
                public static string PushMsg(string sTitle, string sContent, string name, string value, string sAudience)
                {
                    object toUser = sAudience;
                    if (sAudience != "all")
                    {
                        registration_i registration = new registration_i();
                        List<string> users = new List<string>();
                        users.Add(sAudience);
                        registration.registration_id = users;
                        toUser = registration;
                    }
                    PushPayload pushPayload = new PushPayload()
                    {
                        Platform = new List<string> { "android" },
                        Audience = toUser,
                        Notification = new Notification
                        {
                            Alert = sContent,
                            Android = new Android
                            {
                                Alert = sContent,
                                Title = sTitle,
                                Extras = new Dictionary<string, object>
                                {
                                    [name] = value
                                }
                            }
                        },
                        Message = new Message
                        {
                            Title = sTitle,
                            Content = sContent,
                            Extras = new Dictionary<string, string>
                            {
                                [name] = value
                            }
                        },
                    };
                    var response = client.SendPush(pushPayload);
                    return response.Content;
                }
            /// <summary>
            /// 极光推送传递一个参数
            /// </summary>
            /// <param name="sTitle">标题</param>
            /// <param name="sContent">内容</param>
            /// <param name="name">参数字段</param>
            /// <param name="value">参数值</param>
            /// <param name="users"></param>
            /// <returns></returns>
            public static string PushWarnMsg(string sTitle, string sContent,  string name, string value, List<string> users)
                {
                    registration_i registration = new registration_i();
                    registration.registration_id = users;
                    PushPayload pushPayload = new PushPayload()
                    {
                        Platform = new List<string> { "android" },
                        Audience = registration,
                        Notification = new Notification
                        {
                            Alert = sContent,
                            Android = new Android
                            {
                                Alert = sContent,
                                Title = sTitle,
                                Extras = new Dictionary<string, object>
                                {
                                    [name] = value
                                }
                            }
                        },
                        Message = new Message
                        {
                            Title = sTitle,
                            Content = sContent,
                            Extras = new Dictionary<string, object>
                            {
                                [name] = value
                            }
                        }
                    };
                    var response = client.SendPush(pushPayload);
                    //FileHelper.AddSaveFile("UpFile/Content/Send.txt", DateTime.Now.ToString() + "调用极光推送: " + response.Content, "utf-8");
                    return response.Content;
                }
                public static string NewPushWarnMsg(string sTitle, string sContent, List<string> users)
                {
                    registration_i registration = new registration_i();
                    registration.registration_id = users;
                    PushPayload pushPayload = new PushPayload()
                    {
                        Platform = new List<string> { "android" },
                        Audience = registration,
                        Notification = new Notification
                        {
                            Alert = sContent,
                            Android = new Android
                            {
                                Alert = sContent,
                                Title = sTitle,
    
                            }
                        },
                        Message = new Message
                        {
                            Title = sTitle,
                            Content = sContent,
    
                        }
                    };
                    var response = client.SendPush(pushPayload);
                    return response.Content;
                }
            }
    
       
    }
    .Net Core
  • 相关阅读:
    centos7下git服务器端搭建(转)
    IDEA各个版本激活(亲测有效,永久有效)(转)
    维护贴--linux下 mysql数据库的备份和还原 (转)
    维护贴--验证可用--mysql给root开启远程访问权限,修改root密码(转)
    开通mysql root 用户远程访问权限(转)
    安装mysql时包冲突解决方法
    mysql5.5 for linux 安装(转)
    Centos中iptables和firewall防火墙开启、关闭、查看状态、基本设置等(转)
    一个div宽度不固定的左右居中效果
    多行文字在一个div中上下左右居中
  • 原文地址:https://www.cnblogs.com/zpy1993-09/p/15573204.html
Copyright © 2011-2022 走看看