コード例 #1
0
        public long[] SendSms(long[] phoneNos, string[] message, ref string response)
        {
            MessageValidation(phoneNos, message);

            long[] result;
            int    smsLineId     = 0;
            var    messagesCount = message.Count();
            var    numbersCount  = phoneNos.Count();

            var details = new List <WebServiceSmsSend>();

            for (int i = 0; i < numbersCount; i++)
            {
                details.Add(new WebServiceSmsSend
                {
                    IsFlash     = false,
                    MessageBody = messagesCount > 1 ? message[i] : message[0],
                    MobileNo    = phoneNos[i]
                });
            }
            var userName = AppSettings.SmsUserName;
            var password = AppSettings.SmsPassword;
            var smsLines = GetLines(userName, password);

            if (smsLines != null && smsLines.Count() > 0)
            {
                smsLineId = smsLines[0].ID;
            }
            else
            {
                throw new Exception("هیچ خطی برای ارسال پیام یافت نشد.");
            }
            var sendReceive = new SendReceive();

            result = sendReceive.SendMessage(userName, password, details.ToArray(), smsLineId, DateTime.Now, ref response);
            if (!string.IsNullOrWhiteSpace(response))
            {
                throw new Exception(response);
            }
            return(result);
        }