コード例 #1
0
    //Public Method SendSMS
    public string SendSMS(string mobileno, string message)
    {
        if (CheckConnection())
        {
            try
            {
                SmsClient.ServerAddress = ServerAddress;
                SmsClient.Port = Convert.ToInt32(ServerPort);
                SmsClient.HttpProxy.ProxyMode = HttpProxyMode.AutoDetect;
                //SmsClient.HttpProxy.Host = ProxyAddress;
                //SmsClient.HttpProxy.Port = Convert.ToInt32(ProxyPort);

                SmsClient sms = new SmsClient(Username, Password);
                try
                {
                    SendMessageResult result = sms.SendMessage(mobileno, message);
                    return result.TaskId + "|" + result.MessageId;
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        else
        {
            return "Error";
        }
    }
コード例 #2
0
ファイル: SmsSender.cs プロジェクト: phithakul/JBus
        public static void SendMessageAsync(string AccountUsername, string AccountPassword, string mobileNo, string message, DateTime scheduleTime)
        {
            var smsClient = new SmsClient(AccountUsername, AccountPassword);

            var smsLog = new SmsLog
            {
                UserId = Current.User.Id,
                MobileNo = mobileNo,
                Message = message,
                SentTime = DateTime.Now,
                SmsStatus = SmsStatus.Sending,
                MessageId = "",
                TaskId = "",
                ErrorMsg = ""
            };
            smsLog.Id = (int)Current.DB.SmsLogs.Insert(smsLog);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    SendMessageResult result;
                    if (scheduleTime == DateTime.MinValue)
                    {
                        result = smsClient.SendMessage(mobileNo, message);
                    }
                    else
                    {
                        result = smsClient.SendMessage(mobileNo, message, scheduleTime);
                    }
                    Current.DB.Execute(@"update SmsLogs
            set [email protected],
            [email protected],
            [email protected]
            where Id = @id", new
                    {
                        SmsStatus = (int)SmsStatus.Success,
                        MessageId = result.MessageId,
                        TaskId = result.TaskId,
                        id = smsLog.Id
                    });
                }
                catch (GatewayException ge)
                {
                    Current.DB.Execute(@"update SmsLogs
            set [email protected],
            [email protected]
            where Id = @id", new
                    {
                        SmsStatus = (int)SmsStatus.Error,
                        ErrorMsg = ge.Message,
                        id = smsLog.Id
                    });
                }
                catch (Exception ex)
                {
                    Current.DB.Execute(@"update SmsLogs
            set [email protected],
            [email protected]
            where Id = @id", new
                    {
                        SmsStatus = (int)SmsStatus.Error,
                        ErrorMsg = ex.Message,
                        id = smsLog.Id
                    });
                }
            });
        }