Exemple #1
0
 /// <summary>
 /// 引发 SMS 事件。
 /// </summary>
 protected virtual void OnSMSEvent(SMSEventArgs e)
 {
     if (SMSEvent != null)
     {
         SMSEvent(this, e);
     }
 }
        private void ThreadedSendMessage(object AParam)
        {
            string _Error = string.Empty;
            string _Type  = string.Empty;

            try
            {
                SmsMessage _Sms = (SmsMessage)AParam;
                _Sms.Send();
            }
            catch (SmsException ex)
            {
                _Error = ex.Message;
                _Type  = "SMS Error";
            }
            catch (Exception ex)
            {
                _Error = ex.Message;
                _Type  = "General Error";
            }

            SMSEventArgs _args = new SMSEventArgs(_Error, _Type);

            OnCompleted(_args);
        }
 protected virtual void OnCompleted(SMSEventArgs e)
 {
     if (null != SMSCompleted)
     {
         SMSCompleted(this, e);
     }
 }
 protected virtual void OnCompleted(SMSEventArgs e)
 {
     if (null != SMSCompleted)
     {
         SMSCompleted(this, e);
     }
 }
Exemple #5
0
 private void GlobalEvents_OnSMSReceived(object sender, SMSEventArgs e)
 {
     Log.Debug("GlobalEvents_OnSMSReceived", "Message received is :" + e.Message + "-Phone:" + e.PhoneNumber);
     //EntryMessage.Text = e.Message;
     if (e.Message.Contains("Your OTP to redeem point is"))
     {
         OTP.Text = e.Message.Replace("Your OTP to redeem point is", "").Trim();
     }
 }
Exemple #6
0
        /// <summary>
        /// modem received event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _gsmModem_OnRecieved(object sender, SMSEventArgs e)
        {
            SMSSendInfo smsInfo  = new SMSSendInfo();
            GsmModem    gsmModem = sender as GsmModem;

            if (gsmModem != null)
            {
                smsInfo.Com     = gsmModem.Name;
                smsInfo.Phone   = e.SmsInfo.Number;
                smsInfo.Message = e.SmsInfo.Message;
                ReceiveEventArgs args = new ReceiveEventArgs();
                args.SmsInfo = smsInfo;
                OnReceived(args);
            }
        }
        private void ThreadedSendMessage(object AParam)
        {
            string _Error = string.Empty;
            string _Type = string.Empty;

            try
            {
                SmsMessage _Sms = (SmsMessage)AParam;
                _Sms.Send();
            }
            catch (SmsException ex)
            {
                _Error = ex.Message;
                _Type = "SMS Error";
            }
            catch (Exception ex)
            {
                _Error = ex.Message;
                _Type = "General Error";
            }

            SMSEventArgs _args = new SMSEventArgs(_Error, _Type);
            OnCompleted(_args);
        }
Exemple #8
0
 static void Gateway_SMSEvent(object sender, SMSEventArgs e)
 {
     //System.Diagnostics.Debug.WriteLine("Event -----> " + e.Type);
 }
Exemple #9
0
 public static void OnSMSReceived_Event(object sender, SMSEventArgs sms)
 {
     OnSMSReceived?.Invoke(sender, sms);
 }
Exemple #10
0
 private void GlobalEvents_OnSMSReceived(object sender, SMSEventArgs e)
 {
     EntryMessage.Text = e.Message;
 }
Exemple #11
0
        public async Task <ISmsClientResult> SendSmsAsync(string recipientNumber, string message)
        {
            var client  = new RestClient(SmsUri);
            var request = new RestRequest(Method.POST);

            request.AddHeader("content-type", "application/json");

            var body = new Dictionary <string, object>
            {
                { "Username", this.Credentials.Username },
                { "Password", this.Credentials.Password },
                { "Originator", this.Options.Originator },
                { "Recipients", new List <string> {
                      recipientNumber
                  } },
                { "MessageText", message },
                { "DeferredDeliveryTime", this.Options.DeferredDeliveryTime },
                { "FlashingSMS", this.Options.FlashingSms },
                { "URLDeliveryNotification", this.Options.UrlDeliveryNotification },
                { "URLNonDeliveryNotification", this.Options.UrlNonDeliveryNotification },
                { "AffiliateID", this.Options.AffiliateId },
                { "ForceGSM7bit", this.Options.ForceGsm7Bit }
            };


            request.AddParameter("application/json", Newtonsoft.Json.JsonConvert.SerializeObject(body), ParameterType.RequestBody);
            var response = await client.ExecutePostTaskAsync(request);

            if (response.IsSuccessful)
            {
                var responseJson = (ASPSMSClient.Base.TrackingInfo)
                                   Newtonsoft.Json.JsonConvert.DeserializeObject(response.Content, typeof(ASPSMSClient.Base.TrackingInfo));
                if (responseJson.StatusCode != "1")
                {
                    var result = new ASPSMSClient.Base.SmsResult
                    {
                        SMSStatus        = SMSStatus.FailedToSend,
                        ProviderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content)
                    };
                    OnSmSfailed(new SMSEventArgs()
                    {
                        Data = result.ProviderResponse
                    });

                    return(result);
                }
                else
                {
                    var result = new ASPSMSClient.Base.SmsResult
                    {
                        SMSStatus        = SMSStatus.Sent,
                        ProviderResponse = (Dictionary <string, string>)Newtonsoft.Json.JsonConvert.DeserializeObject(response.Content, typeof(Dictionary <string, string>)),
                        TrackingId       = "",

                        From = this.Options.Originator,
                        To   = recipientNumber
                    };
                    var eventargs = new SMSEventArgs {
                        Data = result
                    };

                    OnSmsSent(eventargs);
                    return(result);
                }
            }
            else
            {
                var result = new ASPSMSClient.Base.SmsResult
                {
                    SMSStatus        = SMSStatus.FailedToSend,
                    ProviderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content)
                };
                OnSmSfailed(new SMSEventArgs()
                {
                    Data = result.ProviderResponse
                });

                return(result);
            }
        }
Exemple #12
0
 protected virtual void OnSmsSent(SMSEventArgs e)
 {
     SmsSent?.Invoke(this, e);
 }
Exemple #13
0
 protected virtual void OnSmSfailed(SMSEventArgs e)
 {
     SmSfailed?.Invoke(this, e);
 }
Exemple #14
0
 /// <summary>
 /// Raises the <see cref="E:AuthorizationFailed" /> event.
 /// </summary>
 /// <param name="e">The <see cref="SMSEventArgs"/> instance containing the event data.</param>
 protected virtual void OnAuthorizationFailed(SMSEventArgs e)
 {
     AuthorizationFailed?.Invoke(this, e);
 }
Exemple #15
0
        /// <summary>
        /// Sends the SMS asynchronous.
        /// </summary>
        /// <param name="recipientNumber">The recipient number.</param>
        /// <param name="message">The message.</param>
        /// <returns cref="SmSResult"></returns>
        public async Task <ISmsClientResult> SendSmsAsync(string recipientNumber, string message)
        {
            var client  = new RestClient(SmsUri);
            var request = new RestRequest(Method.POST);

            request.AddHeader("content-type", "application/json");
            request.AddHeader("authorization", "Bearer " + Token.access_token);
            object body;

            if (string.IsNullOrEmpty(Options.CallBackUri))
            {
                body = new
                {
                    body = message,
                    to   = recipientNumber,
                    from = Options.Originator
                };
            }
            else
            {
                body = new
                {
                    body     = message,
                    to       = recipientNumber,
                    from     = Options.Originator,
                    callback = new { url = Options.CallBackUri }
                };
            }

            request.AddParameter("application/json", Newtonsoft.Json.JsonConvert.SerializeObject(body), ParameterType.RequestBody);
            var response = await client.ExecutePostTaskAsync(request);

            if (response.IsSuccessful)
            {
                var result = new SmSResult
                {
                    SMSStatus        = SMSStatus.Sent,
                    ProviderResponse = (Dictionary <string, string>)Newtonsoft.Json.JsonConvert.DeserializeObject(response.Content, typeof(Dictionary <string, string>))
                };
                result.TrackingId = result.ProviderResponse["trackingId"];
                result.Body       = result.ProviderResponse["body"];
                result.CreatedAt  = DateTime.Parse(result.ProviderResponse["createdAt"]);
                result.From       = result.ProviderResponse["from"];
                result.To         = result.ProviderResponse["to"];
                result.TrackingId = result.ProviderResponse["trackingId"];
                var eventargs = new SMSEventArgs {
                    Data = result
                };

                OnSmsSent(eventargs);
                return(result);
            }
            else
            {
                SmSResult result = new SmSResult();
                switch (response.StatusCode)
                {
                case HttpStatusCode.Unauthorized:
                    result.SMSStatus        = SMSStatus.BadAuthorization;
                    result.ProviderResponse =
                        Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content);

                    OnAuthorizationFailed(new SMSEventArgs()
                    {
                        Data = result.ProviderResponse
                    });
                    break;

                default:
                    result.SMSStatus        = SMSStatus.FailedToSend;
                    result.ProviderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content);
                    OnSmSfailed(new SMSEventArgs()
                    {
                        Data = result.ProviderResponse
                    });
                    break;
                }
                return(result);
            }
        }