CloudManager.cs 6.0 KB

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