Exemplo de Webhooks - Cs

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

using System;

using System.Collections;
using System.Data;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace NsAssertivoPainel
{
public partial class PgnApi : System.Web.UI.Page
{

string json_return = "";

protected void Form1_LoadCompleted()


{
string json_response = "";
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
try
{
if (ParamName.Equals("Bankys"))
{
try
{
Request.InputStream.Position = 0;
using (var inputStream = new
StreamReader(Request.InputStream))
{
json_response = inputStream.ReadToEnd();
}

if (json_response != null && json_response.Length > 0)


{
if (Dao.ExecuteNonQuery(
"INSERT INTO " + Dao.PoeColAspas("TB_WEBHOOKS")
+
" ( " + Dao.PoeColAspas("CREATED_AT") +
" ," + Dao.PoeColAspas("WEBHK_STATUS") +
" ," + Dao.PoeColAspas("WEBHK_JSON") +
") VALUES (" +
Dao.ToSql(DateTime.Now.ToString("s"),
FieldType.Date) +
", " + Dao.ToSql("Recebido", FieldType.Text) +
", " +
Dao.ToSql(JObject.Parse(json_response).ToString(), FieldType.Text) +
")"
) == 1)
{
json_return = "Confirmação com sucesso!";
Response.StatusCode = 200;

Processar();
}
else
{
Response.StatusCode = 406;
json_return = "Falha na inclusão do retorno.";
}
}
else
{
Response.StatusCode = 406;
json_return = "Conteúdo incorreto.";
}
}
catch (FormatException)
{
Response.StatusCode = 401;
json_return = "Credenciais formatadas incorretamente.";
}
}
else
{
Response.StatusCode = 406;
json_return = "Parâmetro incorreto.";
}

}
catch (Exception ex)
{
Response.StatusCode = 500;
string sMsg = ex.Message.ToString().Replace("'", "").Replace("\
r\n", "<br>");

if (ex.InnerException != null)
sMsg += ex.InnerException.Message.ToString().Replace("'",
"").Replace("\r\n", "<br>");
json_return = sMsg;
}

Response.Write(json_return);
try
{
Response.End();
}
catch (Exception) { }
}

void Processar()
{
try
{
PrvTratarWebHookProcessProvider PreDefProvider = new
PrvTratarWebHookProcessProvider(this);
PreDefProvider.AliasVariables = new Dictionary<string,
object>();
PreDefProvider.AliasVariables.Clear();
PreDefProvider.ExecutePreDefinedProcess();
}
catch (Exception) { }
}
}
}

You might also like