public async Task EnviarAsync(String Tabela, Int32 Empresa_id) { String TelFormat = ""; Int32 Enviados = 0; Int32 Falhas = 0; WhatsAppSendPST App; Hlp Hlp; try { App = new WhatsAppSendPST(); Con = new Connect(); Hlp = new Hlp(); EnviarOperadores(); if (cb_filtros.Checked == true) { DisplayData(App.Pesquisar(Tabela, Empresa_id, Hlp.DateFormat(dtp_inicial.Text), Hlp.DateFormat(dtp_final.Text))); } else { DisplayData(App.Pesquisar(Tabela, Empresa_id)); } for (int Cont = 0; Cont < Table.Rows.Count; Cont++) { //Controles if (Parar == true) { break; } if (Contador > 1000) { Contador = 0; } // Timer await Task.Delay(Hlp.WaitTime(Contador)); App.Destinatario = new Destinatario(); App.Destinatario.Nome = Table.Rows[Cont]["nome"].ToString(); App.Destinatario.Telefone = Hlp.TelFind(Table, Tabela, Cont); if (!String.IsNullOrEmpty(App.Destinatario.Telefone)) { TelFormat = Hlp.TelFormat(App.Destinatario.Telefone); } if (!String.IsNullOrEmpty(TelFormat)) { if (cb_testar.Checked == false) { WebReq(URL_PLATFORM, TelFormat, App.Destinatario.Nome); } else { WebReq(URL_PLATFORM, TESTE_DESTINATARIO, App.Destinatario.Nome); break; } Enviados++; lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); } else { dataGridView2.Rows.Add(App.Destinatario.Nome, App.Destinatario.Telefone, "FALHA"); Falhas++; lbl_falhas.Text = "FALHAS: " + Falhas.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); } Contador++; } lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString(); lbl_falhas.Text = "FALHAS: " + Falhas.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); MessageBox.Show("O ENVIO FOI CONCLUIDO!"); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void WebReq(String ApiUrl, String Tel, String Nome) { String Result = ""; String TextFormat = ""; WhatsAppSendPST Send; Hlp Hlp; ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { return(true); }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (WebClient WebPost = new WebClient()) { NameValueCollection WebFields = null; Byte[] WebResponse = null; try { Hlp = new Hlp(); Send = new WhatsAppSendPST(); WebFields = new NameValueCollection(); Send.Cmd = "chat"; String[] NomeFormat = Nome.Split(' '); TextFormat = Rtxt_Texto.Text.Replace("{nome}", NomeFormat[0]); TextFormat = TextFormat.Replace("{hix}", "Texto fixo 1"); TextFormat = TextFormat.Replace("{hi}", "Texto fixo 2"); TextFormat = TextFormat.Replace("{comprimento}", Hlp.RandomTalk()); TextFormat = TextFormat.Replace("{comprimentoplus}", Hlp.RandomTalk(NomeFormat[0])); Send.Texto = TextFormat; if (!String.IsNullOrEmpty(txt_img.Text)) { Send.Cmd = "image"; Send.UrlImg = txt_img.Text; } /* * * //Waboxapp * WebFields["token"] = TOKEN; * WebFields["uid"] = REMETENTE; * WebFields["to"] = Tel; * WebFields["custom_uid"] = Hlp.RandomIdGenerator(); * WebFields["text"] = Send.Texto; * * if (!String.IsNullOrEmpty(txt_img.Text)) * { * WebFields["url"] = Send.UrlImg; * WebFields["caption"] = Send.Titulo; * WebFields["description"] = Send.Descricao; * } */ //Winzap WebFields["token"] = TOKEN; WebFields["cmd"] = Send.Cmd; WebFields["id"] = Hlp.RandomIdGenerator(); WebFields["de"] = "5581" + txt_remetente.Text; WebFields["para"] = Tel; WebFields["msg"] = Send.Texto; if (!String.IsNullOrEmpty(txt_img.Text)) { WebFields["link"] = Send.UrlImg; } MessageBox.Show(Send.Texto); //WebResponse = WebPost.UploadValues(ApiUrl, "POST", WebFields); //Result = HTTP_ENCODING.GetString(WebResponse); Result = "{\"message\":\"sucesso\"}"; if (Result == SUCCESS) { dataGridView2.Rows.Add(Nome, Tel, "ENVIADO"); } } catch (Exception e) { MessageBox.Show(e.Message + ""); } finally { WebFields = null; WebResponse = null; } } }