コード例 #1
0
        private Uri ComposeUrl(SmsMessage message)
        {
            const string pattern =
                "https://smsconnector.cz.o2.com/smsconnector/getpost/GP?action=send&baID={0}&toNumber={1}&text={2}&intruder=FALSE&multipart={3}&deliveryReport=FALSE&validityPeriod=10000&priority=1";

            var baId = WebUtility.UrlEncode(SmsConnectorConfiguration.ApplicationId);

            var phoneNumber = WebUtility.UrlEncode(message.PhoneNumber.FullPhoneNumberWithNormalizedPrefix);
            var messageText = WebUtility.UrlEncode(message.Text);
            var multipart = message.Multipart.ToString();

            return new Uri(string.Format(pattern, baId, phoneNumber, messageText, multipart));
        }
コード例 #2
0
        /// <summary>
        /// Sends an SMS message.
        /// </summary>
        /// <param name="message">SMS message.</param>
        /// <returns>Task.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="message"/> is <c>null</c>.</exception>
        public async Task SendSmsAsync(SmsMessage message)
        {
            if (message == null) throw new ArgumentNullException(nameof(message));

            var url = ComposeUrl(message);

#if NET45
            var messageHandler = new WebRequestHandler();
            messageHandler.ClientCertificates.Add(SmsConnectorConfiguration.Certificate);
#else
            var messageHandler = new WinHttpHandler();
            messageHandler.ClientCertificates.Add(SmsConnectorConfiguration.Certificate);
#endif

            using (var client = new HttpClient(messageHandler))
            {
                var response = await client.GetAsync(url).ConfigureAwait(false);

                await HandleErrorResponse(response).ConfigureAwait(false);
            }
        }