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.

100 lines
4.1 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using Business.TPApi;
  2. using Common;
  3. using Common.Model;
  4. using Common.Model.Config;
  5. using Common.Model.Notification;
  6. using log4net;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Net.Http;
  12. using System.Text;
  13. using System.Web;
  14. using Data = Common.Data;
  15. using Notify = Common.Model.Notification;
  16. namespace Business
  17. {
  18. public static class NotifierV2
  19. {
  20. private static readonly ILog Log = LogManager.GetLogger(typeof(NotifierV2));
  21. public static JsonRxResponse SendNotification(SendNotificationRequest request, NOTIFICATION_TYPE nOTIFICATION_TYPE = NOTIFICATION_TYPE.PUSH_NOTIFICATION)
  22. {
  23. ThirdPartyAPI _tpApi = new ThirdPartyAPI();
  24. APIJsonResponse jsonResponse = new APIJsonResponse();
  25. if (string.IsNullOrEmpty(request.ProcessId))
  26. request.ProcessId = Guid.NewGuid().ToString();
  27. //request.ProviderId = Guid.NewGuid().ToString();
  28. request.NotificationTypeId = nOTIFICATION_TYPE.ToString();
  29. Log.Debug("NotifierV2.SendNotification | REQUEST : " + JsonConvert.SerializeObject(request));
  30. APIJsonResponse result = _tpApi.ThirdPartyApiGetDataOnly<SendNotificationRequest, APIJsonResponse>(request, "TP/NotificationAPI", out jsonResponse);
  31. Log.Debug("NotifierV2.SendNotification | RESPONSE : " + JsonConvert.SerializeObject(result));
  32. return new JsonRxResponse()
  33. {
  34. ErrorCode = result.ResponseCode,
  35. Id = result.Id,
  36. Msg = result.Msg,
  37. Data = result.Data,
  38. Extra = result.Extra,
  39. Extra2 = result.Extra1
  40. };
  41. }
  42. }
  43. public class SendSMSApiService
  44. {
  45. public APIJsonResponse SMSTPApi(SMSRequestModel model)
  46. {
  47. //Log.Debug("Calculate | Calling third party api to fetch the ex-rate details " + JsonConvert.SerializeObject(model));
  48. using (var client = RestApiClient.GetThirdPartyClient())
  49. {
  50. APIJsonResponse jsonResponse = new APIJsonResponse();
  51. var obj = JsonConvert.SerializeObject(model);
  52. var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
  53. try
  54. {
  55. var URL = "TP/SMSApi";
  56. HttpResponseMessage resp = client.PostAsync(URL, jbdContent).Result;
  57. string resultData = resp.Content.ReadAsStringAsync().Result;
  58. if (resp.IsSuccessStatusCode)
  59. {
  60. jsonResponse = JsonConvert.DeserializeObject<APIJsonResponse>(resultData);
  61. var a = (jsonResponse.Data != null ? JsonConvert.DeserializeObject<ExRateResponse>(jsonResponse.Data.ToString()) : null);
  62. jsonResponse.Data = a;
  63. return jsonResponse;
  64. }
  65. else
  66. {
  67. var errorJson = JsonConvert.DeserializeObject<ErrorJosn>(resultData);
  68. var jsonResponseData = JsonConvert.DeserializeObject<APIJsonResponse>(errorJson.Message);
  69. var data = JsonConvert.DeserializeObject<List<Data>>(jsonResponseData.Data.ToString());
  70. jsonResponse.Id = jsonResponseData.Id;
  71. jsonResponse.ResponseCode = jsonResponseData.ResponseCode;
  72. jsonResponse.Msg = jsonResponseData.Msg;
  73. jsonResponse.Data = data;
  74. jsonResponse.Extra = jsonResponseData.Extra;
  75. jsonResponse.Extra1 = jsonResponseData.Extra1;
  76. return jsonResponse;
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. return new APIJsonResponse()
  82. {
  83. ResponseCode = "1",
  84. Msg = (ex.InnerException == null ? ex.Message : ex.InnerException.Message)
  85. };
  86. }
  87. }
  88. }
  89. }
  90. }