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.

63 lines
2.7 KiB

11 months ago
  1. using JMETxnPushScheduler.Common;
  2. using Newtonsoft.Json;
  3. using Swift.API.Common.Enum;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Net.Http;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace JMETxnPushScheduler.API
  11. {
  12. public static class NotifierV2
  13. {
  14. // private static readonly ILog Log = LogManager.GetLogger(typeof(NotifierV2));
  15. public static JsonResponse SendNotification(SendNotificationRequestMobile request, NOTIFICATION_TYPE nOTIFICATION_TYPE = NOTIFICATION_TYPE.PUSH_NOTIFICATION)
  16. {
  17. using (var client = RestApiClient.CallJMEThirdParty())
  18. {
  19. JsonResponse jsonResponse = new JsonResponse();
  20. var obj = JsonConvert.SerializeObject(request);
  21. var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
  22. try
  23. {
  24. var URL = "api/v1/TP/NotificationAPI";
  25. HttpResponseMessage resp = client.PostAsync(URL, jbdContent).Result;
  26. string resultData = resp.Content.ReadAsStringAsync().Result;
  27. if (resp.IsSuccessStatusCode)
  28. {
  29. jsonResponse = JsonConvert.DeserializeObject<JsonResponse>(resultData);
  30. var a = (jsonResponse.Data != null ? JsonConvert.DeserializeObject<JsonResponse>(jsonResponse.Data.ToString()) : null);
  31. jsonResponse.Data = a;
  32. return jsonResponse;
  33. }
  34. else
  35. {
  36. var errorJson = JsonConvert.DeserializeObject<ErrorJosn>(resultData);
  37. var jsonResponseData = JsonConvert.DeserializeObject<JsonResponse>(errorJson.Message);
  38. var data = JsonConvert.DeserializeObject<List<Data>>(jsonResponseData.Data.ToString());
  39. jsonResponse.Id = jsonResponseData.Id;
  40. jsonResponse.ResponseCode = jsonResponseData.ResponseCode;
  41. jsonResponse.Msg = jsonResponseData.Msg;
  42. jsonResponse.Data = data;
  43. jsonResponse.Extra = jsonResponseData.Extra;
  44. jsonResponse.Extra1 = jsonResponseData.Extra1;
  45. return jsonResponse;
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. return new JsonResponse()
  51. {
  52. ResponseCode = "1",
  53. Msg = (ex.InnerException == null ? ex.Message : ex.InnerException.Message)
  54. };
  55. }
  56. }
  57. }
  58. }
  59. }