You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

62 lines
2.7 KiB

//using log4net;
using Newtonsoft.Json;
using Swift.API.Common;
using Swift.API.Common.Enum;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
namespace Swift.API.TPAPIs
{
public static class NotifierV2
{
// private static readonly ILog Log = LogManager.GetLogger(typeof(NotifierV2));
public static JsonResponse SendNotification(SendNotificationRequestMobile request, NOTIFICATION_TYPE nOTIFICATION_TYPE = NOTIFICATION_TYPE.PUSH_NOTIFICATION)
{
using (var client = RestApiClient.CallJMEThirdParty())
{
JsonResponse jsonResponse = new JsonResponse();
var obj = JsonConvert.SerializeObject(request);
var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
try
{
var URL = "api/v1/TP/NotificationAPI";
HttpResponseMessage resp = client.PostAsync(URL, jbdContent).Result;
string resultData = resp.Content.ReadAsStringAsync().Result;
if (resp.IsSuccessStatusCode)
{
jsonResponse = JsonConvert.DeserializeObject<JsonResponse>(resultData);
var a = (jsonResponse.Data != null ? JsonConvert.DeserializeObject<JsonResponse>(jsonResponse.Data.ToString()) : null);
jsonResponse.Data = a;
return jsonResponse;
}
else
{
var errorJson = JsonConvert.DeserializeObject<ErrorJosn>(resultData);
var jsonResponseData = JsonConvert.DeserializeObject<JsonResponse>(errorJson.Message);
var data = JsonConvert.DeserializeObject<List<Data>>(jsonResponseData.Data.ToString());
jsonResponse.Id = jsonResponseData.Id;
jsonResponse.ResponseCode = jsonResponseData.ResponseCode;
jsonResponse.Msg = jsonResponseData.Msg;
jsonResponse.Data = data;
jsonResponse.Extra = jsonResponseData.Extra;
jsonResponse.Extra1 = jsonResponseData.Extra1;
return jsonResponse;
}
}
catch (Exception ex)
{
return new JsonResponse()
{
ResponseCode = "1",
Msg = (ex.InnerException == null ? ex.Message : ex.InnerException.Message)
};
}
}
}
}
}