Ejemplo n.º 1
0
        private string WsSendSimpleSms(string message, string targetNumber)
        {
            var smsWS = new JBSoft.Bll.Clickatell.PushServerWSPortTypeClient();

            try
            {
                var sessionId = smsWS.auth(Convert.ToInt32(ConfigurationManager.AppSettings["ClickatellApi"]),
                    ConfigurationManager.AppSettings["ClickatellUser"],
                    ConfigurationManager.AppSettings["ClickatellPassword"]);

                if (sessionId.Contains("OK"))
                {
                    sessionId = sessionId.Substring(sessionId.IndexOf(":") + 2);

                    targetNumber = targetNumber.Substring(0, 1) == "0"
                                       ? "27" + targetNumber.Substring(1, targetNumber.Length - 1)
                                       : targetNumber;

                    if (targetNumber.Length == 9)
                        targetNumber = "27" + targetNumber;

                    int noSmses = 1;
                    if (message.Length > 320)
                    {
                        noSmses = 3;
                    }
                    else if (message.Length > 160)
                        noSmses = 2;

                    if (ConfigurationManager.AppSettings["ProcessSmsButDontSend"] == "0")
                    {
                        var result = smsWS.sendmsg(sessionId, Convert.ToInt32(ConfigurationManager.AppSettings["ClickatellApi"]),
                        ConfigurationManager.AppSettings["ClickatellUser"], ConfigurationManager.AppSettings["ClickatellPassword"],
                        new string[] { targetNumber }, ConfigurationManager.AppSettings["ClickatellFromNumber"], message,
                        noSmses, 0, 0, 0, 0, 0, 0, 0, 1, null, 0, null, null, null, 0);

                        if (result.Length > 0 && result[0].Substring(0, 2).ToLower() == "id")
                            return result[0];
                        else
                            throw new Exception("Sms sending failed with Error number:" + result);
                    }
                    else
                        return "";
                }
                else
                {
                    throw new Exception("Sms sending failed. Failed to authenticate");
                }
            }
            finally
            {
                smsWS.Close();
            }
        }
Ejemplo n.º 2
0
        private string WsSendSimpleBatch(string message, List<string> targetNumbers)
        {
            var smsWS = new JBSoft.Bll.Clickatell.PushServerWSPortTypeClient();

            try
            {
                var sessionId = smsWS.auth(3322948, "TangentRoadtrip", "abc123");

                if (sessionId.Contains("OK"))
                {
                    sessionId = sessionId.Substring(sessionId.IndexOf(":") + 2);

                    var result = smsWS.sendmsg(sessionId, 3322948, "davidfnel", "yamaha1", targetNumbers.ToArray(), "41561", message,
                        1, 0, 0, 0, 0, 0, 0, 0, 0, null, 0, null, null, null, 0);

                    if (result.Length > 0 && result[0].Substring(0, 2).ToLower() == "id")
                        return result[0];
                    else
                        throw new Exception("Sms sending failed with Error number:" + result);

                }
                else
                {
                    throw new Exception("Sms sending failed. Failed to authenticate");
                }
            }
            finally
            {
                smsWS.Close();
            }
        }