CloudManager.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using Dfs.WayneChina.SinochemEps;
  2. using SinochemCloudClient;
  3. using SinochemCloudClient.Models;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Wayne.Lib.Log;
  11. namespace SinochemInternetPlusApp
  12. {
  13. public class CloudManager
  14. {
  15. private readonly string SiteId = SinochemEpsApp.AppSettings["SinochemSiteId"];
  16. private readonly string UrlPrefix = SinochemEpsApp.AppSettings["SinochemCloudUrlPrefix"];
  17. private readonly string BalanceInquiryApi = SinochemEpsApp.AppSettings["SinochemCloudBalanceApi"];
  18. public BalanceInquiryResponse BalanceInquiry(string cardNo, string encryptedPin, string tid, int nozzleId, DebugLogger debugLogger)
  19. {
  20. CloudCommunicator<BalanceInquiryRequest, BalanceInquiryResponse> communicator =
  21. new CloudCommunicator<BalanceInquiryRequest, BalanceInquiryResponse>(UrlPrefix + BalanceInquiryApi);
  22. BalanceInquiryRequest request = new BalanceInquiryRequest
  23. {
  24. tid = tid,
  25. datetime = DateTime.Now.ToString("yyyyMMddHHmmss"),
  26. gun = nozzleId.ToString(),
  27. //token = "" , // not available
  28. mobile = "",
  29. dept_No = SiteId,
  30. card_No = cardNo,
  31. password = encryptedPin
  32. };
  33. debugLogger.Add("Sending BalanceInquiry: \n" + request.ToString());
  34. communicator.SendRequest(request);
  35. debugLogger.Add("Got BalanceInquiry response: \n" + communicator.Response?.ToString());
  36. return communicator.Response;
  37. }
  38. private readonly string PaymentApi = SinochemEpsApp.AppSettings["SinochemCloudPaymentApi"];
  39. public PaymentResponse Payment(EpsTransactionModel epsTrxModel, DebugLogger debugLogger)
  40. {
  41. CloudCommunicator<PaymentRequest, PaymentResponse> communicator =
  42. new CloudCommunicator<PaymentRequest, PaymentResponse>(UrlPrefix + PaymentApi);
  43. PaymentRequest request = new PaymentRequest
  44. {
  45. tid = epsTrxModel.tid,
  46. datetime = epsTrxModel.created_time.ToString("yyyyMMddHHmmss"),//DateTime.Now.ToString("yyyyMMddHHmmss"),
  47. gun = epsTrxModel.jihao.ToString(),
  48. mobile = "",
  49. dept_No = SiteId,
  50. ttc = epsTrxModel.ttc,
  51. card_No = epsTrxModel.card_no?.TrimStart('0'),
  52. password = epsTrxModel.EnryptedPIN,
  53. code = FuelGradeConvertor.GetGradeNo(epsTrxModel.youpin),
  54. price = epsTrxModel.danjia,
  55. lpm = epsTrxModel.qty,
  56. amount = epsTrxModel.amount,
  57. gas_Up_Time = epsTrxModel.auth_time,
  58. rear_Pump_Code = "",
  59. off_Line_Sign = "0",
  60. tradeDateTime = epsTrxModel.created_time.ToString("yyyyMMddHHmmss"),//DateTime.Now.ToString("yyyyMMddHHmmss"),
  61. mac = epsTrxModel.mac,
  62. token = epsTrxModel.token + DateTimeUtility.CurrentTimeMillis().ToString()
  63. };
  64. debugLogger.Add("Sending Payment: \n" + request.ToString());
  65. communicator.SendRequest(request);
  66. debugLogger.Add("Got Payment response: \n" + communicator.Response?.ToString());
  67. return communicator.Response;
  68. }
  69. private readonly string TrxStatusInquiryApi = SinochemEpsApp.AppSettings["SinochemCloudTrxStatusApi"];
  70. public TrxStatusInquiryResponse TrxStatusInquiry(EpsTransactionModel epsTrxModel, DebugLogger debugLogger)
  71. {
  72. CloudCommunicator<TrxStatusInquiryRequest, TrxStatusInquiryResponse> communicator =
  73. new CloudCommunicator<TrxStatusInquiryRequest, TrxStatusInquiryResponse>(UrlPrefix + TrxStatusInquiryApi);
  74. TrxStatusInquiryRequest request = new TrxStatusInquiryRequest
  75. {
  76. tid = epsTrxModel.tid,
  77. datetime = DateTime.Now.ToString("yyyyMMddHHmmss"),
  78. gun = epsTrxModel.jihao.ToString(),
  79. mobile = "",
  80. dept_No = SiteId,
  81. card_No = epsTrxModel.card_no,
  82. pre_Amount = epsTrxModel.real_pay_amount,
  83. ori_ttc = epsTrxModel.ttc,
  84. token = epsTrxModel.token + DateTimeUtility.CurrentTimeMillis().ToString()
  85. };
  86. debugLogger.Add("Sending TrxStatusInquiry: \n" + request.ToString());
  87. communicator.SendRequest(request);
  88. debugLogger.Add("Got TrxStatusInquiry response: \n" + communicator.Response?.ToString());
  89. return communicator.Response;
  90. }
  91. private readonly string RefundApi = SinochemEpsApp.AppSettings["SinochemCloudRefundApi"];
  92. public RefundResponse Refund(EpsTransactionModel epsTrxModel, DebugLogger debugLogger)
  93. {
  94. CloudCommunicator<RefundRequest, RefundResponse> communicator =
  95. new CloudCommunicator<RefundRequest, RefundResponse>(UrlPrefix + RefundApi);
  96. RefundRequest request = new RefundRequest
  97. {
  98. tid = epsTrxModel.tid,
  99. datetime = DateTime.Now.ToString("yyyyMMddHHmmss"),
  100. gun = epsTrxModel.jihao.ToString(),
  101. mobile = "",
  102. dept_No = SiteId,
  103. card_No = epsTrxModel.card_no,
  104. pre_Amount = epsTrxModel.real_pay_amount,
  105. ori_ttc = epsTrxModel.ttc,
  106. token = epsTrxModel.token + DateTimeUtility.CurrentTimeMillis().ToString()
  107. };
  108. debugLogger.Add("Sending Refund: \n" + request.ToString());
  109. communicator.SendRequest(request);
  110. debugLogger.Add("Got Refund response: \n" + communicator.Response?.ToString());
  111. return communicator.Response;
  112. }
  113. }
  114. class DateTimeUtility
  115. {
  116. private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  117. public static long CurrentTimeMillis()
  118. {
  119. return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
  120. }
  121. }
  122. }