Ejemplo n.º 1
0
        public async Task <int> SendSMS(string number, string message)
        {
            try
            {
                using (var httpClient = new Sinch.Core.Client(_applicationKey, _applicationSecret)) {
                    var url        = baseURL + number;
                    var smsRequest = new SMSRequest {
                        Message = message
                    };
                    var response = await httpClient.PostAsJsonAsync(url, smsRequest);

                    System.IO.StreamReader sr = new System.IO.StreamReader(await response.Content.ReadAsStreamAsync());
                    var responseData          = sr.ReadToEnd().Trim();
                    response.EnsureSuccessStatusCode();
                    //var result = await response.Content.ReadAsAsync<SMSResult>();
                    // return result.MessageId;
                    return(2);
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
                string at  = str;
                return(0);
            }
        }
Ejemplo n.º 2
0
        public async Task<int> SendSMS(string number, string message) {

            using (var httpClient = new Sinch.Core.Client(_applicationKey, _applicationSecret)) {
                var url = baseURL + number;
                var smsRequest = new SMSRequest { Message = message };
                var response = await httpClient.PostAsJsonAsync(url, smsRequest);
                response.EnsureSuccessStatusCode();
                var result = await response.Content.ReadAsAsync<SMSResult>();
                return result.MessageId;
            }
        }
Ejemplo n.º 3
0
        public async Task<int> SendSMS(string fromNumber, string number, string message) {
            var url = baseURL + number;
            var smsRequest = new SMSRequest { Message = message, From = fromNumber };
            string errormessage = "";
            using (var httpClient = new Sinch.Core.Client(_applicationKey, _applicationSecret)) {
                try {
                    var response = await httpClient.PostAsJsonAsync(url, smsRequest);
                    errormessage = response.ReasonPhrase;
                    response.EnsureSuccessStatusCode();
                    var result = await response.Content.ReadAsAsync<SMSResult>();
                    return result.MessageId;
                } catch (Exception ex) {

                    throw new Exception(errormessage);

                }

            }
        }