Exemple #1
0
        private bool SendSms(ISmsNotificationModel message)
        {
            try
            {
                if (message.Valid)
                {
                    IClient client = new ClientOAuth(message.Config.Token);
                    var     api    = new SMSFactory(client);

                    var builder =
                        api.ActionSend()
                        .SetText(message.Text)
                        .SetTo(message.PhoneNumbers.ToArray());

                    if (message.Date.HasValue)
                    {
                        builder.SetDateSent(message.Date.Value);
                    }

                    builder.Execute();
                }
            }
            catch (System.Exception)
            {
                // log
            }

            return(false);
        }
Exemple #2
0
        public void SetUp()
        {
            client = new Client(ConfigurationManager.AppSettings["username"]);
            client.SetPasswordHash(ConfigurationManager.AppSettings["password"]);

            proxy = new ProxyHTTP(ConfigurationManager.AppSettings["baseUrl"]);

            smsFactory    = new SMSFactory(client, proxy);
            senderFactory = new SenderFactory(client, proxy);
            userFactory   = new UserFactory(client, proxy);

            contactsFactory = new ContactsFactory(client, proxy);

            var clientLegacy = new Client(ConfigurationManager.AppSettings["usernameOldPhonebook"]);

            clientLegacy.SetPasswordHash(ConfigurationManager.AppSettings["passwordOldPhonebook"]);
            phonebookFactory = new PhonebookFactory(clientLegacy, proxy);

            subUserName     = ConfigurationManager.AppSettings["subUserName"];
            validTestNumber = ConfigurationManager.AppSettings["validTestNumber"];
        }
Exemple #3
0
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public bool SendVerificationCode(string mobile)
        {
            string    code    = SiteHelper.CreateRandom(true, 4);
            bool      result  = SMSFactory.GetSMS().SendCheckCode(mobile, code);
            Hashtable hashLog = new Hashtable();

            hashLog["ID"]           = CommonHelper.GetGuid;
            hashLog["Sender"]       = mobile;
            hashLog["Receiver"]     = mobile;
            hashLog["ShortMessage"] = code;
            hashLog["AllMessage"]   = string.Format("尊敬的用户,您的验证码是{0}。请不要把验证码泄露给其他人。如非本人操作,请忽略本短信", code);
            hashLog["MessageType"]  = (int)SMSMessageType.User;
            if (result)
            {
                hashLog["MessageState"] = (int)SMSMessageState.AlreadySend;
            }
            else
            {
                hashLog["MessageState"] = (int)SMSMessageState.SendFaild;
            }
            AddSMSLog(hashLog);
            return(result);
        }
Exemple #4
0
        private static string SmsSender2(string messageText, string phoneNumber, string token)
        {
            string errors = string.Empty;

            try
            {
                IClient client = new ClientOAuth(token);
                var     smsApi = new SMSFactory(client);

                // .SetSender(_senderName) //Sender name
                var result =
                    smsApi.ActionSend()
                    .SetText(messageText)
                    .SetTo(phoneNumber)
                    .Execute();

                // System.Console.WriteLine("Send: " + result.Count);

                string[] ids = new string[result.Count];

                for (int i = 0, l = 0; i < result.List.Count; i++)
                {
                    if (!result.List[i].isError())
                    {
                        if (!result.List[i].isFinal())
                        {
                            ids[l] = result.List[i].ID;
                            l++;
                        }
                    }
                }
            }
            catch (SMSApi.Api.ActionException e)
            {
                errors += $"Action error: {e.Message}\n";
            }
            catch (SMSApi.Api.ClientException e)
            {
                /**
                 * Error codes (list available in smsapi docs). Example:
                 * 101  Invalid authorization info
                 * 102  Invalid username or password
                 * 103  Insufficient credits on Your account
                 * 104  No such template
                 * 105  Wrong IP address (for IP filter turned on)
                 * 110	Action not allowed for your account
                 */
                errors += $"Client error: {e.Message}\n";
            }
            catch (SMSApi.Api.HostException e)
            {
                /*
                 * Server errors
                 * SMSApi.Api.HostException.E_JSON_DECODE - problem with parsing data
                 */
                errors += $"Server error: {e.Message}\n";
            }
            catch (SMSApi.Api.ProxyException e)
            {
                // communication problem between client and sever
                errors += $"Proxy error: {e.Message}\n";
            }
            return(errors);
        }
Exemple #5
0
        public void TestSms()
        {
            const string to = "46734195147";

            try
            {
                var client = new Client("*****@*****.**");
                //client.SetUsername("*****@*****.**");
                client.SetPasswordHash("07a0fbb4e40877cb77074eff3494b958");

                var smsApi = new SMSFactory(client);

                var result = smsApi.ActionSend()
                             .SetText("Test")
                             .SetTo(to)
                             .SetSender("QTransport")
                             .Execute();

                var ids = new string[result.Count];

                for (int i = 0, l = 0; i < result.List.Count; i++)
                {
                    if (result.List[i].isError())
                    {
                        continue;
                    }
                    if (result.List[i].isFinal())
                    {
                        continue;
                    }
                    ids[l] = result.List[i].ID;
                    l++;
                }

                result =
                    smsApi.ActionGet()
                    .Ids(ids)
                    .Execute();

                foreach (var status in result.List)
                {
                    System.Console.WriteLine("ID: " + status.ID + " NUmber: " + status.Number + " Points:" + status.Points + " Status:" + status.Status + " IDx: " + status.IDx);
                }

                foreach (var t in result.List)
                {
                    if (t.isError())
                    {
                        continue;
                    }

                    var deleted =
                        smsApi.ActionDelete()
                        .Id(t.ID)
                        .Execute();
                    System.Console.WriteLine("Deleted: " + deleted.Count);
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
            }
        }
Exemple #6
0
 public override void SetUp()
 {
     base.SetUp();
     _factory = new SMSFactory(_client, _proxyAddress);
 }
Exemple #7
0
        public static bool SendSms(string to, string message, out string resultStr)
        {
            resultStr = "Kundens telefonenummer saknas.";
            if (string.IsNullOrEmpty(to))
            {
                return(false);
            }

            try
            {
                to = "46" + to.TrimStart('0');

                var client = new Client("*****@*****.**");
                client.SetPasswordHash("07a0fbb4e40877cb77074eff3494b958");

                var smsApi = new SMSFactory(client);

                var result = smsApi.ActionSend()
                             .SetText(message)
                             .SetTo(to)
                             .SetSender("QTransport")
                             .Execute();

                var ids = new string[result.Count];

                for (int i = 0, l = 0; i < result.List.Count; i++)
                {
                    if (result.List[i].isError())
                    {
                        continue;
                    }
                    if (result.List[i].isFinal())
                    {
                        continue;
                    }
                    ids[l] = result.List[i].ID;
                    l++;
                }

                result = smsApi.ActionGet()
                         .Ids(ids)
                         .Execute();

                resultStr = result.List.Aggregate(resultStr,
                                                  (current, status) =>
                                                  current +
                                                  ("ID: " + status.ID + " NUmber: " + status.Number + " Points:" + status.Points + " Status:" +
                                                   status.Status + " IDx: " + status.IDx + ". "));

                return(true);
            }
            catch (ActionException e)
            {
                resultStr = $"{e.Message}. {e.InnerException?.Message}";
            }
            catch (ClientException e)
            {
                resultStr = $"{e.Message}. {e.InnerException?.Message}";
            }
            catch (HostException e)
            {
                resultStr = $"{e.Message}. {e.InnerException?.Message}";
            }
            catch (ProxyException e)
            {
                resultStr = $"{e.Message}. {e.InnerException?.Message}";
            }

            return(false);
        }