コード例 #1
0
        public bool SendPhoneAPNS(BaseInfo baseInfo)
        {
            PhoneGCMInfo info = (PhoneGCMInfo)baseInfo;
            JSONInfo Info1 = new JSONInfo();
            subJSONInfo Info2 = new subJSONInfo();
            JSONResult Info3 = new JSONResult();
            ArrayList _GetPhoneRegIDData = new ArrayList();
            ArrayList _GetCarAlarmData = new ArrayList();
            ArrayList _GetRuleInfoData = new ArrayList();
            ArrayList _IOSRegIDData = new ArrayList();
            ArrayList _RegIDData = new ArrayList();

            _GetCarAlarmData.Add(info.DeviceID);
            IDataReader reader1 = DataProvider.Instance().ChkPhoneDriverInfoDB(_GetCarAlarmData);//FMS_PhoneDriverInfo_Fetch;return CarNo,Driver
            if (reader1.Read())
            {
                Info1.type = "check";
                Info2.CarNo = reader1.GetString(0);
                Info2.Driver = reader1.GetString(1);
            }
            CBO.CloseDataReader(reader1, true);

            _GetRuleInfoData.Add(info.AlertRuleID);
            IDataReader reader2 = DataProvider.Instance().ChkPhoneRuleDB(_GetRuleInfoData);//FMS_PhoneRule_Fetch;return RuleName,AlarmType,Severity
            if (reader2.Read())
            {
                Info2.AlertDate = info.EventTime;
                Info2.RuleName = reader2.GetString(0);
                Info2.AlarmType = reader2.GetString(1);
                Info2.Severity = reader2.GetString(2);
            }
            CBO.CloseDataReader(reader2, true);

            StringBuilder _sb = new StringBuilder();
            _sb.Append("警報日期:");
            _sb.Append(Info2.AlertDate);
            _sb.Append("\\n");
            _sb.Append("類型/嚴重度:");
            if (Info2.Severity.Equals("3"))
            {
                _sb.Append(Info2.AlarmType + " / [嚴重]");
            }
            else if (Info2.Severity.Equals("2"))
            {
                _sb.Append(Info2.AlarmType + " / [一般]");
            }
            else
            {
                _sb.Append(Info2.AlarmType + " / [輕度]");
            }
            _sb.Append("\\n");
            _sb.Append("名稱:");
            _sb.Append(Info2.RuleName);
            _sb.Append("\\n");
            _sb.Append("車號/駕駛人:");
            _sb.Append(Info2.CarNo + " / " + Info2.Driver);

            string output = _sb.ToString();


            //  string output = "警報日期:2015/03/04 11:55:00 \\n類型/嚴重度:超速 / [嚴重]\\n名稱:連續超速70km  3分鐘\\n車號/駕駛人:kw-car03 / 易大師";


            _GetPhoneRegIDData.Add(info.AlertRuleID);
            _GetPhoneRegIDData.Add(info.DeviceID);
            IDataReader reader = DataProvider.Instance().GetAPNSDB(_GetPhoneRegIDData);//FMS_PhoneGCM_Fetch;return UserId,RegisterID,Phone_Mail_Logic
            APNSSender _apnsSender = new APNSSender();

            string strResultJson;
            while (reader.Read())
            {
                info.userID = reader.GetInt32(0).ToString();
                info.RegID = reader.GetString(1);
                strResultJson = _apnsSender.SendAPNS(info.RegID, output);
                //save log record
                CreatePushNoticeLog(info, output, "Apple");
            }
            CBO.CloseDataReader(reader, true);

            return true;
        }
コード例 #2
0
        public bool SendPhoneBaidu(BaseInfo baseInfo)
        {
            PhoneGCMInfo info = (PhoneGCMInfo)baseInfo;
            JSONInfo Info1 = new JSONInfo();
            subJSONInfo Info2 = new subJSONInfo();
            JSONResult Info3 = new JSONResult();
            ArrayList _GetPhoneRegIDData = new ArrayList();
            ArrayList _GetCarAlarmData = new ArrayList();
            ArrayList _GetRuleInfoData = new ArrayList();
            ArrayList _IOSRegIDData = new ArrayList();
            ArrayList _RegIDData = new ArrayList();

            _GetCarAlarmData.Add(info.DeviceID);
            IDataReader reader1 = DataProvider.Instance().ChkPhoneDriverInfoDB(_GetCarAlarmData);//FMS_PhoneDriverInfo_Fetch;return CarNo,Driver
            if (reader1.Read())
            {
                Info1.type = "alert";
                Info2.CarNo = reader1.GetString(0);
                Info2.Driver = reader1.GetString(1);
            }
            CBO.CloseDataReader(reader1, true);

            _GetRuleInfoData.Add(info.AlertRuleID);
            IDataReader reader2 = DataProvider.Instance().ChkPhoneRuleDB(_GetRuleInfoData);//FMS_PhoneRule_Fetch;return RuleName,AlarmType,Severity
            if (reader2.Read())
            {
                Info2.AlertDate = info.EventTime;
                Info2.RuleName = reader2.GetString(0);
                Info2.AlarmType = reader2.GetString(1);
                Info2.Severity = reader2.GetString(2);
            }
            CBO.CloseDataReader(reader2, true);


            Info1.data = new string[] { JsonConvert.SerializeObject(Info2) };
            string output = JsonConvert.SerializeObject(Info1);
            output = output.Replace("\\", "").Replace("[\"", "[").Replace("\"]", "]");



            _GetPhoneRegIDData.Add(info.AlertRuleID);
            _GetPhoneRegIDData.Add(info.DeviceID);
            IDataReader reader = DataProvider.Instance().GetBaiduDB(_GetPhoneRegIDData);//FMS_PhoneBaidu_Fetch;return UserId,RegisterID,Phone_Mail_Logic
            BaiduSender _BaiduPush = new BaiduSender();


            string strResultJson;
            while (reader.Read())
            {
                info.userID = reader.GetInt32(0).ToString();
                info.RegID = reader.GetString(1);
                Random rnd = new Random(Guid.NewGuid().GetHashCode());
                String msgKey = rnd.NextDouble() + "";
                strResultJson = _BaiduPush.Push(info.RegID, "", output, msgKey);

                //save log record
                CreatePushNoticeLog(info, output, "Baidu");

            }
            CBO.CloseDataReader(reader, true);

            return true;
        }
コード例 #3
0
 public bool ChkPhoneGCM(BaseInfo baseInfo)
 {
     PhoneGCMInfo info = (PhoneGCMInfo)baseInfo;
     JSONInfo Info1 = new JSONInfo();
     subJSONInfo Info2 = new subJSONInfo();
     ArrayList al = new ArrayList();
     ArrayList a2 = new ArrayList();
     ArrayList a3 = new ArrayList();
     //ArrayList a3 = new ArrayList();
     al.Add(info.AlertRuleID);
     a2.Add(info.DeviceID);
     IDataReader reader1 = DataProvider.Instance().ChkPhoneDriverInfoDB(a2);//FMS_PhoneDriverInfo_Fetch;return CarNo,Driver
     if (reader1.Read())
     {
         Info1.type = "check";
         //Info1.data.CarNo = reader1.GetString(0);
         //Info1.data.Driver = reader1.GetString(1);
         Info2.CarNo = reader1.GetString(0);
         Info2.Driver = reader1.GetString(1);
     }
     CBO.CloseDataReader(reader1, true);
     a2.Clear();
     a2.Add(info.AlertRuleID);
     IDataReader reader2 = DataProvider.Instance().ChkPhoneRuleDB(a2);//FMS_PhoneRule_Fetch;return RuleName,AlarmType,Severity
     if (reader2.Read())
     {
         //Info1.data.AlertDate = info.EventTime;
         //Info1.data.RuleName = reader2.GetString(0);
         //Info1.data.AlarmType = reader2.GetString(1);
         //Info1.data.Severity = reader2.GetString(2);
         Info2.AlertDate = info.EventTime;
         Info2.RuleName = reader2.GetString(0);
         Info2.AlarmType = reader2.GetString(1);
         Info2.Severity = reader2.GetString(2);
     }
     CBO.CloseDataReader(reader2, true);
     a2.Clear();
     //string output2 = JsonConvert.SerializeObject(Info2);
     Info1.data = new string[] { JsonConvert.SerializeObject(Info2) };
     string output = JsonConvert.SerializeObject(Info1);
     output = output.Replace("\\", "").Replace("[\"", "[").Replace("\"]", "]");
     //Info1.type = "alert";
     string output1 = output.Replace("check", "alert");
     al.Add(info.DeviceID);
     IDataReader reader = DataProvider.Instance().ChkGCMDB(al);//FMS_PhoneGCM_Fetch;return UserId,RegisterID,Phone_Mail_Logic
     GCMSender gcm = null;
     string strResultJson, strResultJson1;
     while (reader.Read())
     {
         info.userID = reader.GetInt32(0).ToString();
         info.RegID = reader.GetString(1);
         info.Phone_Mail_Logic = reader.GetString(2);
         gcm = new GCMSender(info.RegID , "AIzaSyAI7vpx-Q3gQ1l-2R0jH00IqnVEbaQgSR8");
         strResultJson = gcm.Send(output);                
         if (strResultJson.IndexOf("registration_id") == -1)
         {
             strResultJson1 = gcm.Send(output1);
             //save log record
             CreatePushNoticeLog(info, output1, "Google");
         }
         else
         {
             JObject obj = (JObject)JsonConvert.DeserializeObject(strResultJson);
             obj = (JObject)obj["results"][0];
             if (obj["registration_id"] != null)
             {
                 string newRegId = obj["registration_id"].ToString();
                 PhoneGCMInfo newGcmInfo = new PhoneGCMInfo();
                 newGcmInfo.RegID = info.RegID;
                 newGcmInfo.newRegID = newRegId;
                 newGcmInfo.userID = info.userID;
                 newGcmInfo.Phone_Mail_Logic = info.Phone_Mail_Logic;
                 newGcmInfo.WorkListAlertID = info.WorkListAlertID;
                 newGcmInfo.DeviceID = info.DeviceID;
                 newGcmInfo.AlertRuleID = info.AlertRuleID;
                 a3.Add(newGcmInfo);
             }
         }
     }
     if (a3.Count > 0)
     {               
         for (int i = 0; i < a3.Count; i++)
         {
             PhoneGCMInfo newGcmInfo = a3[i] as PhoneGCMInfo;
             a2.Clear();
             a2.Add(newGcmInfo.RegID);
             a2.Add(newGcmInfo.newRegID);
             a2.Add(newGcmInfo.userID);
             a2.Add(newGcmInfo.Phone_Mail_Logic);
             int reader3 = DataProvider.Instance().ChkPhoneOverRegIDDB(a2);
             gcm = new GCMSender(newGcmInfo.newRegID, "AIzaSyAI7vpx-Q3gQ1l-2R0jH00IqnVEbaQgSR8");
             strResultJson1 = gcm.Send(output1);
             //save log record
             newGcmInfo.RegID = newGcmInfo.newRegID;
             CreatePushNoticeLog(info, output1, "Google");
         }
     }
     CBO.CloseDataReader(reader, true);
     return true;
 }