void Start()
    {
        LocalNotification.CancelNotification(1);
        System.DateTime datetime   = System.DateTime.Today;
        int             today      = (int)datetime.DayOfWeek;
        int             dateRemind = 0;

        dateRemind = today + minDate;
        dateRemind = minDate + CountToDate(dateRemind);
        timeDelay  = dateRemind * 24 * 60 * 60 + SecondOnDate(dateRemind - 1);
        print("=====\nRimind after: " + dateRemind + " days count down: " + timeDelay + " secs\n======");
#if !UNITY_EDITOR
        string titleNotification   = AllLanguages.notifiTitle[Modules.indexLanguage];
        string contentNotification = AllLanguages.notifiContent[Modules.indexLanguage];
#endif
#if UNITY_IOS && !UNITY_EDITOR
        IOSNotification.RegisterForNotif();
        IOSNotification.CancelNotifications();
        IOSNotification.ScheduleNotification(timeDelay, loopRemind, titleNotification, contentNotification);
#elif UNITY_ANDROID && !UNITY_EDITOR
        if (loopRemind)
        {
            LocalNotification.SendRepeatingNotification(1, timeDelay, timeDelay, titleNotification, contentNotification, new Color32(0xff, 0x44, 0x44, 255), true, true, true, "app_icon");
        }
        else
        {
            LocalNotification.SendNotification(1, timeDelay, titleNotification, contentNotification, new Color32(0xff, 0x44, 0x44, 255), true, true, true, "app_icon");
        }
#endif
    }
Example #2
0
        public string PushMsg(string strJson)
        {
            string result = string.Empty;
            string message = string.Empty;
            try
            {
                Dictionary<string, string> dic = json.Deserialize<Dictionary<string, string>>(strJson);
                BaiduPush Bpush = new BaiduPush("POST");
                String messages = "";
                String method = "push_msg";
                TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
                uint device_type = uint.Parse(dic["deviceType"]);
                uint unixTime = (uint)ts.TotalSeconds;
                string messageksy = "pushkeys";
                string apiKey = SysFunction.GetConfigValue("ApiKey");

                if (device_type == 4)
                {
                    IOSNotification notification = new IOSNotification();
                    notification.title = dic["title"];
                    notification.description = dic["des"];
                    messages = notification.getJsonString();
                }
                else if (device_type == 3)
                {
                    AndroidNotification notification = new AndroidNotification();
                    notification.title = dic["title"];
                    notification.description = dic["des"];
                    messages = notification.getJsonString();
                }

                PushOptions pOpts;
                if (dic["pushType"].Equals("1"))
                {
                    pOpts = new PushOptions(method, apiKey, dic["userID"], dic["channelID"], device_type, messages, messageksy, unixTime);
                }
                else if (dic["pushType"].Equals("2"))
                {
                    pOpts = new PushOptions(method, apiKey, dic["tag"], device_type, messages, messageksy, unixTime);
                }
                else
                {
                    pOpts = new PushOptions(method, apiKey, device_type, messages, messageksy, unixTime);
                }

                pOpts.message_type = uint.Parse(dic["msgType"]);

                message = Bpush.PushMessage(pOpts);
                result = "0";
            }
            catch (Exception ex)
            {
                HandleException(ex, ref result, ref message);
            }
            return GetResultStr(result, message);
        }
        public async Task <int> CreateNotification(IOSNotification iOSNotification)
        {
            var query = @"INSERT Into [dbo].[IOSNotification] ([TokenId], [NotificationId], [Success], [CreatedAt])
                Values(@TokenId, @NotificationId, @Success, @CreatedAt)";

            iOSNotification.CreatedAt = DateTime.UtcNow;
            using (IDbConnection conn = Connection)
            {
                conn.Open();
                return(await conn.ExecuteAsync(query.ToString(), iOSNotification));
            }
        }
Example #4
0
        private async Task SendPushIOSAsync(IOSNotification iOSNotification, Notification notification, IOSToken iOSToken, object data, Microsoft.Azure.WebJobs.ExecutionContext context)
        {
            int    port     = 2195;
            string hostname = "gateway.sandbox.push.apple.com";

            var certificatePath = Path.GetFullPath(Path.Combine(context.FunctionDirectory, "..\\Files\\test.txt"));

            var lol = System.IO.File.ReadAllBytes(certificatePath);
            X509Certificate2           clientCertificate      = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "YOUR_PASSWORD");
            X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);

            TcpClient client = new TcpClient(AddressFamily.InterNetwork);
            await client.ConnectAsync(hostname, port);

            SslStream sslStream = new SslStream(
                client.GetStream(), false,
                new RemoteCertificateValidationCallback(ValidateServerCertificate),
                null);

            try
            {
                await sslStream.AuthenticateAsClientAsync(hostname, certificatesCollection, SslProtocols.Tls, false);

                MemoryStream memoryStream = new MemoryStream();
                BinaryWriter writer       = new BinaryWriter(memoryStream);
                writer.Write((byte)0);
                writer.Write((byte)0);
                writer.Write((byte)32);

                writer.Write(HexStringToByteArray(iOSToken.Id.ToUpper()));
                string payload = "{\"aps\":{\"alert\":\"" + notification.Message + "\",\"badge\":0,\"sound\":\"default\"}}";
                writer.Write((byte)0);
                writer.Write((byte)payload.Length);
                byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
                writer.Write(b1);
                writer.Flush();
                byte[] array = memoryStream.ToArray();
                sslStream.Write(array);
                sslStream.Flush();
                client.Dispose();
            }
            catch (AuthenticationException ex)
            {
                client.Dispose();
            }
            catch (Exception e)
            {
                client.Dispose();
            }
        }
Example #5
0
    INotification CreateObj()
    {
        INotification obj;

#if UNITY_EDITOR
        obj = new DefaultNotification();
#elif UNITY_ANDROID
        obj = new AndroidNotification();
#elif  UNITY_IPHONE || UNITY_IOS
        obj = new IOSNotification();
#else
        obj = new DefaultNotification();
        Debugger.LogWarning("Local push not support this platform");
#endif
        return(obj);
    }
Example #6
0
        protected void BtnSend_Click(object sender, EventArgs e)
        {
            try
            {
                string secretKey = PubSql.SecretKey;
                string apiKey    = PubSql.ApiKey;


                CodeBehind.BaiduPush Bpush = new CodeBehind.BaiduPush("POST", secretKey);
                String   messages          = "";
                String   method            = "push_msg";
                TimeSpan ts          = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
                uint     device_type = 3;
                uint     unixTime    = (uint)ts.TotalSeconds;

                uint   message_type;
                string messageksy = "xxxxxx";
                if (RbMessage.Checked)
                {
                    message_type = 0;
                    messages     = TBMessage.Text;
                }
                else
                {
                    message_type = 1;

                    if (RBIOSPRO.Checked == true || RBIOSDEV.Checked == true)
                    {
                        device_type = 4;
                        IOSNotification notification = new IOSNotification();
                        notification.title       = TBTitle.Text;
                        notification.description = TBDescription.Text;
                        messages = notification.getJsonString();
                    }
                    else
                    {
                        BaiduPushNotification notification = new BaiduPushNotification();
                        notification.title       = TBTitle.Text;
                        notification.description = TBDescription.Text;
                        messages = notification.getJsonString();
                    }
                }


                PushOptions pOpts;
                if (RBUnicast.Checked)
                {
                    pOpts = new PushOptions(method, apiKey, TBUserId.Text, TBChannelID.Text, device_type, messages,
                                            messageksy, unixTime);
                }
                else if (RBMulticast.Checked)
                {
                    pOpts = new PushOptions(method, apiKey, TBTag.Text, device_type, messages, messageksy, unixTime);
                }
                else
                {
                    pOpts = new PushOptions(method, apiKey, device_type, messages, messageksy, unixTime);
                }

                pOpts.message_type = message_type;
                if (RBIOSPRO.Checked == true)
                {
                    pOpts.deploy_status = 2;
                }
                else if (RBIOSDEV.Checked == true)
                {
                    pOpts.deploy_status = 1;
                }


                string response = Bpush.PushMessage(pOpts);

                TextBoxResponse.Text = response;
            }
            catch (Exception ex)
            {
                TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
            }
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ApiKey"></param>
        /// <param name="SecretKey"></param>
        /// <param name="sandbox"></param>
        /// <param name="platform">1:苹果 2:安卓</param>
        /// <param name="BDUserID"></param>
        /// <param name="BDChannelID"></param>
        /// <returns></returns>
        public static string SendPush(string ApiKey, string SecretKey, bool sandbox, int platform, string BDUserID, string BDChannelID, string NoticeTitle, string NoticeContent, string custom_content)
        {
            //当前APIKEY
            string sk = SecretKey;
            //当前SecreKey
            string ak = ApiKey;

            //百度推送
            BaiduPush Bpush    = new BaiduPush("POST", sk);
            String    apiKey   = ak;
            String    messages = "";
            String    method   = "push_msg";//默认消息推送

            //当前时间戳为 PushOptions服务
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
            //默认设备为安卓

            /*
             * 云推送支持多种设备,各种设备的类型编号如下:
             * 3:Andriod设备;
             * 4:iOS设备;
             * 如果存在此字段,则向指定的设备类型推送消息。 默认为android设备类型。
             */
            uint device_type = platform == 1 ? (uint)4 : (uint)3;
            //获取总秒数
            uint unixTime = (uint)ts.TotalSeconds;
            //当前消息类型
            uint message_type;
            //消息签名一一对应
            string messageksy = "xxx000";

            //通知
            message_type = 1;

            //如果选择的是通知并且是苹果,那么设备类型改变为4
            if (platform == 1) //1:苹果 2:安卓
            {
                IOSNotification notification = new IOSNotification();
                notification.title       = NoticeContent;
                notification.description = NoticeTitle;
                messages = notification.getJsonString();
            }
            else
            {
                BaiduPushNotification notification = new BaiduPushNotification();
                notification.title          = NoticeTitle;
                notification.description    = NoticeContent;
                notification.custom_content = custom_content;
                messages = notification.getJsonString();
            }
            PushOptions pOpts = new PushOptions(method, apiKey, BDUserID, BDChannelID, device_type, messages, messageksy, unixTime);

            //消息或则通知
            pOpts.message_type = message_type;

            //如果是苹果发布版本
            if (platform == 1 && sandbox)
            {
                //则当前是开发状态
                pOpts.deploy_status = 1;
            }
            else if (platform == 1 && !sandbox)//如果是苹果开发版本
            {
                //则当前是生产状态
                pOpts.deploy_status = 2;
            }
            string response = Bpush.PushMessage(pOpts);

            return(response);
        }
        public override void OnLoad(HttpContext context)
        {
            base.OnLoad(context);
            requestBody             = new RequestBody();
            requestBody.accessToken = context.Request["accessToken"];
            requestBody.uTo         = Convert.ToInt32(context.Request["to"]);
            requestBody.content     = context.Request["content"];

            if (requestBody.content.Length == 0 || requestBody.accessToken.Trim().Length == 0 || requestBody.uTo == 0)
            {
                SystemResponse.Output(SystemResponse.TYPE_NULLPARAMETER, out statusCode, out responseJson);
            }
            else
            {
                //验证用户
                TokenHelper    token     = new TokenHelper();
                UserTokenModel fromModel = token.getUserToken(requestBody.accessToken);
                UserTokenModel toModel   = token.getUserToken(requestBody.uTo);
                if (fromModel == null)
                {
                    SystemResponse.Output(SystemResponse.TYPE_EXPIRE, out statusCode, out responseJson);
                }
                else
                {
                    int msgstatus = 0;

                    #region 入库至本地
                    ModelAdo <MsgModel> modelAdo = new ModelAdo <MsgModel>();
                    MsgModel            msg      = new MsgModel();
                    msg.ufrom      = Convert.ToInt32(fromModel.uid);
                    msg.uto        = requestBody.uTo;
                    msg.content    = requestBody.content;
                    msg.createTime = StringHelper.ConvertDateTimeInt(DateTime.Now);
                    msg.status     = msgstatus;
                    if (modelAdo.Insert(msg) >= 1)
                    {
                        #region 百度推送
                        if (toModel != null && toModel.bpuserId.Length >= 1 && toModel.channelId.Length >= 1)
                        {
                            //获取插入本地数据
                            MsgModel msgPush = modelAdo.GetModel("ufrom=?ufrom AND uto=?uto AND createTime=?createTime AND status=0", "",
                                                                 new MySqlParameter("?ufrom", msg.ufrom),
                                                                 new MySqlParameter("?uto", msg.uto),
                                                                 new MySqlParameter("?createTime", msg.createTime));
                            if (msgPush != null)
                            {
                                try
                                {
                                    //百度配置信息
                                    string secretKey    = ConfigurationManager.AppSettings["baidu_secret_key"];
                                    string apiKey       = ConfigurationManager.AppSettings["baidu_api_key"];
                                    uint   depolyStatus = uint.Parse(ConfigurationManager.AppSettings["baidu_depoly_status"]);

                                    String    messages     = "";
                                    TimeSpan  ts           = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
                                    uint      unixTime     = (uint)ts.TotalSeconds;
                                    string    messageksy   = "api";
                                    uint      message_type = 1;
                                    BaiduPush Bpush        = new BaiduPush("POST", secretKey);



                                    if (toModel.deviceType == 1)
                                    {
                                        message_type       = 1;
                                        toModel.deviceType = 4;
                                        IOSNotification notifaction = new IOSNotification();
                                        notifaction.id         = msgPush.id;
                                        notifaction.ufrom      = msgPush.ufrom;
                                        notifaction.uto        = msgPush.uto;
                                        notifaction.content    = msgPush.content.Trim();
                                        notifaction.createTime = string.Format("{0:yyyy/MM/dd HH:mm:ss}", System.DateTime.Now);
                                        notifaction.type       = msgPush.type;
                                        notifaction.status     = 1;
                                        IOSAPS aps = new IOSAPS()
                                        {
                                            alert = "收到一条新消息",
                                        };
                                        notifaction.aps = aps;
                                        messages        = notifaction.getJsonString();
                                    }
                                    else
                                    {
                                        message_type       = 0;
                                        toModel.deviceType = 3;
                                        BaiduPushNotification notifaction = new BaiduPushNotification();
                                        notifaction.title = "";
                                        //构建custom_content信息
                                        BaiduDescription bdMsg = new BaiduDescription();
                                        bdMsg.id                   = msgPush.id;
                                        bdMsg.ufrom                = msgPush.ufrom;
                                        bdMsg.uto                  = msgPush.uto;
                                        bdMsg.content              = msgPush.content;
                                        bdMsg.createTime           = string.Format("{0:yyyy/MM/dd HH:mm:ss}", System.DateTime.Now);
                                        bdMsg.type                 = msgPush.type;
                                        bdMsg.status               = 1;
                                        notifaction.description    = "收到一条新消息";
                                        notifaction.custom_content = bdMsg;
                                        messages                   = notifaction.getJsonString();
                                    }



                                    PushOptions pOpts = new PushOptions("push_msg", apiKey, toModel.bpuserId.ToString(),
                                                                        toModel.channelId.ToString(), Convert.ToUInt32(toModel.deviceType), messages, messageksy, unixTime);
                                    pOpts.message_type  = message_type;
                                    pOpts.deploy_status = depolyStatus;
                                    pOpts.push_type     = 1;
                                    string response = Bpush.PushMessage(pOpts);
                                    responseJson = response;
                                    msgstatus    = 1;

                                    //处理数据为已读
                                    if (msg.status == 0)
                                    {
                                        msgPush.status = 1;
                                        modelAdo.Update(msgPush);
                                    }

                                    //SystemResponse.Output(SystemResponse.TYPE_OK, out statusCode, out responseJson);
                                    //responseJson = strBDMsg;
                                }
                                catch (Exception ex)
                                {
                                    responseJson = ex.ToString();
                                    SystemResponse.Output(SystemResponse.TYPE_ERROR, out statusCode, out responseJson);
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            SystemResponse.Output(SystemResponse.TYPE_ERROR, out statusCode, out responseJson);
                        }
                        #endregion
                    }
                }
            }
        }