public async Task <bool> Recargar(customer_info customer) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://smsteleyuma.azurewebsites.net/Service1.svc/TransferTo/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var param = new topupInfo() { msisdn = customer.phone1, destination_msisdn = this.numero, product = this.monto.ToString(), sender_sms = "yes", action = "topup" }; var response = await client.PostAsync("topup", param.AsJsonStringContent()); var Result = await response.Content.ReadAsStringAsync(); try { this.topupResponse = JsonConvert.DeserializeObject <topupResponse>(Result); return(true); } catch { return(false); } } }
public async Task <topupResponse> movil() { var Login = "******"; var Token = "Yj2F8oVRZB"; var date = DateTime.Now; var Key = date.Year + date.Month + date.Day + date.TimeOfDay.Hours + date.TimeOfDay.Minutes + date.TimeOfDay.Seconds + date.TimeOfDay.Milliseconds; var md5Code = GetMd5Hash(Login + Token + Key); using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://airtime.transferto.com/cgi-bin/shop/"); //Simulation var param = new topupInfo() { login = Login, key = Convert.ToInt32(Key), md5 = md5Code, msisdn = this.msisdn, destination_msisdn = this.destination_msisdn, product = this.product, sender_sms = this.sender_sms, action = this.action }; try { var response = await client.PostAsXmlAsync("topup", param); var Result = await response.Content.ReadAsStringAsync(); //cambiar operator por operador para poder cojer el valos (operator es un nombre reservado de c# y no se puede user en una clase como atributo) Result = Result.Replace("operator", "operador"); XmlDocument doc = new XmlDocument(); doc.LoadXml(Result); string json = JsonConvert.SerializeXmlNode(doc); return(JsonConvert.DeserializeObject <topupResponseObject>(json).TransferTo); } catch (Exception ex) { return(new topupResponse { country = this.destination_msisdn }); } } }