Beispiel #1
0
        public async Task <string> SendMessageAsync(RequestData data)
        {
            var token = AuthorizationHelper.CreateSASToken(Config._keyValue, Config._keyName, TimeSpan.FromSeconds(30));

            string jsonPayload = JsonConvert.SerializeObject(data);

            var request = new HttpRequestMessage(HttpMethod.Post, $"{Config._endpoint}")
            {
                Headers =
                {
                    { HttpRequestHeader.Accept.ToString(), "application/json"        },
                    { "MS-RequestId",                      Guid.NewGuid().ToString() },
                    { "Account",                           Config._testCcsAccount    },
                    { "Authorization",                     token                     }
                },
                Content = new StringContent(jsonPayload, Encoding.UTF8)
            };


            var response = await _client.SendAsync(request);

            var json = await response.Content.ReadAsStringAsync();

            return(json);
        }
Beispiel #2
0
        public async Task <string> SendOtpMessageAsync(OtpRequestData data, SMSCredential credential)
        {
            var token = AuthorizationHelper.CreateSASToken(credential.KeyValue, credential.KeyName, TimeSpan.FromSeconds(30));

            string jsonPayload = JsonConvert.SerializeObject(data);

            var request = new HttpRequestMessage(HttpMethod.Post, $"{credential.Endpoint}/services/otp/start?api-version=2018-10-01")
            {
                Headers =
                {
                    { HttpRequestHeader.Accept.ToString(), "application/json"        },
                    { "MS-RequestId",                      Guid.NewGuid().ToString() },
                    { "Account",                           credential.AccountName    },
                    { "Authorization",                     token                     }
                },
                Content = new StringContent(jsonPayload, Encoding.UTF8)
            };


            var response = await _client.SendAsync(request);

            var json = await response.Content.ReadAsStringAsync();

            return(json);
        }
Beispiel #3
0
        public async Task <string> SendMessageAsync()
        {
            var requestData = new RequestData();

            requestData.PhoneNumber = new List <string>()
            {
                Config._testMobile
            };
            requestData.ExtendCode  = Config._testExtend;
            requestData.MessageBody = new MessageBody();
            requestData.MessageBody.TemplateName  = Config._testTemplateName;
            requestData.MessageBody.TemplateParam = new Dictionary <string, string>();

            var token = AuthorizationHelper.CreateSASToken(Config._keyValue, Config._keyName, TimeSpan.FromSeconds(30));


            string jsonPayload = JsonConvert.SerializeObject(requestData);

            var request = new HttpRequestMessage(HttpMethod.Post, $"{Config._endpoint}")
            {
                Headers =
                {
                    { HttpRequestHeader.Accept.ToString(), "application/json"        },
                    { "MS-RequestId",                      Guid.NewGuid().ToString() },
                    { "Account",                           Config._testCcsAccount    },
                    { "Authorization",                     token                     }
                },
                Content = new StringContent(jsonPayload, Encoding.UTF8)
            };


            var response = await _client.SendAsync(request);

            var json = await response.Content.ReadAsStringAsync();

            return(json);
        }