示例#1
0
 /// <summary>
 /// Initiate a SMS verification process, 
 /// </summary>
 /// <param name="phoneNumber">e164 phonnumber</param>
 /// <returns></returns>
 public async Task<VerificationResponse> StartSMSVerification(string phoneNumber) {
     
     
     using (var client = new Core.Client(_applicationKey, _applicationSecret)) {
         var body = new VerificationRequest {
             identity = new Identity {
                 type = "number",
                 endpoint = phoneNumber
             }
                                                ,
             method = "sms"
         };
         
         var result = await client.PostAsJsonAsync(_baseUrl, body);
         var returnValue = new VerificationResponse();
         if (result.IsSuccessStatusCode) {
             try {
                 var response = await result.Content.ReadAsStringAsync();
                 var jsonobj = JsonConvert.DeserializeObject<JObject>(response);
                 returnValue = new VerificationResponse {
                     Id = jsonobj["id"].ToString(),
                     SmsTemplate = jsonobj["sms"]["template"].ToString()
                 };
                 return returnValue;
             } catch (Exception ex) {
                 returnValue.StatusMessage = ex.Message;
                 return returnValue;
             }
         }
         returnValue.StatusMessage = result.ReasonPhrase;
         return returnValue;
     }
 }
示例#2
0
        /// <summary>
        ///     Initiate a SMS verification process,
        /// </summary>
        /// <param name="phoneNumber">e164 phonnumber</param>
        /// <returns></returns>
        public async Task <VerificationResponse> StartSMSVerification(string phoneNumber)
        {
            using (var client = new Client(_applicationKey, _applicationSecret))
            {
                var body = new VerificationRequest
                {
                    identity = new Identity
                    {
                        type     = "number",
                        endpoint = phoneNumber
                    },
                    method = "sms"
                };

                var result = await client.PostAsJsonAsync(_baseUrl, body);

                var returnValue = new VerificationResponse();
                if (result.IsSuccessStatusCode)
                {
                    try
                    {
                        var response = await result.Content.ReadAsStringAsync();

                        var jsonobj = JsonConvert.DeserializeObject <JObject>(response);
                        returnValue = new VerificationResponse
                        {
                            Id          = jsonobj["id"].ToString(),
                            SmsTemplate = jsonobj["sms"]["template"].ToString()
                        };
                        return(returnValue);
                    }
                    catch (Exception ex)
                    {
                        returnValue.StatusMessage = ex.Message;
                        return(returnValue);
                    }
                }
                returnValue.StatusMessage = result.ReasonPhrase;
                return(returnValue);
            }
        }