123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using SinochemCloudClient;
- using SinochemCloudClient.Models;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Wayne.Lib.Log;
- namespace SinochemInternetPlusApp
- {
- public class CloudManager
- {
- private readonly string SiteId = App.AppSettings["SinochemSiteId"];
- private readonly string UrlPrefix = App.AppSettings["SinochemCloudUrlPrefix"];
- private readonly string BalanceInquiryApi = App.AppSettings["SinochemCloudBalanceApi"];
- public BalanceInquiryResponse BalanceInquiry(string cardNo, string encryptedPin, string tid, int nozzleId, DebugLogger debugLogger)
- {
- CloudCommunicator<BalanceInquiryRequest, BalanceInquiryResponse> communicator =
- new CloudCommunicator<BalanceInquiryRequest, BalanceInquiryResponse>(UrlPrefix + BalanceInquiryApi);
- BalanceInquiryRequest request = new BalanceInquiryRequest
- {
- tid = tid,
- datetime = DateTime.Now.ToString("yyyyMMddHHmmss"),
- gun = nozzleId.ToString(),
- //token = "" , // not available
- mobile = "",
- dept_No = SiteId,
- card_No = cardNo,
- password = encryptedPin
- };
- debugLogger.Add("Sending BalanceInquiry: \n" + request.ToString());
- communicator.SendRequest(request);
- debugLogger.Add("Got BalanceInquiry response: \n" + communicator.Response?.ToString());
- return communicator.Response;
- }
- private readonly string PaymentApi = App.AppSettings["SinochemCloudPaymentApi"];
- public PaymentResponse Payment(EpsTransactionModel epsTrxModel, DebugLogger debugLogger)
- {
- CloudCommunicator<PaymentRequest, PaymentResponse> communicator =
- new CloudCommunicator<PaymentRequest, PaymentResponse>(UrlPrefix + PaymentApi);
- PaymentRequest request = new PaymentRequest
- {
- tid = epsTrxModel.tid,
- datetime = epsTrxModel.created_time.ToString("yyyyMMddHHmmss"),//DateTime.Now.ToString("yyyyMMddHHmmss"),
- gun = epsTrxModel.jihao.ToString(),
- mobile = "",
- dept_No = SiteId,
- ttc = epsTrxModel.ttc,
- card_No = epsTrxModel.card_no?.TrimStart('0'),
- password = epsTrxModel.EnryptedPIN,
- code = FuelGradeConvertor.GetGradeNo(epsTrxModel.youpin),
- price = epsTrxModel.danjia,
- lpm = epsTrxModel.qty,
- amount = epsTrxModel.amount,
- gas_Up_Time = epsTrxModel.auth_time,
- rear_Pump_Code = "",
- off_Line_Sign = "0",
- tradeDateTime = epsTrxModel.created_time.ToString("yyyyMMddHHmmss"),//DateTime.Now.ToString("yyyyMMddHHmmss"),
- mac = epsTrxModel.mac,
- token = epsTrxModel.token + DateTimeUtility.CurrentTimeMillis().ToString()
- };
- debugLogger.Add("Sending Payment: \n" + request.ToString());
- communicator.SendRequest(request);
- debugLogger.Add("Got Payment response: \n" + communicator.Response?.ToString());
- return communicator.Response;
- }
- private readonly string TrxStatusInquiryApi = App.AppSettings["SinochemCloudTrxStatusApi"];
- public TrxStatusInquiryResponse TrxStatusInquiry(EpsTransactionModel epsTrxModel, DebugLogger debugLogger)
- {
- CloudCommunicator<TrxStatusInquiryRequest, TrxStatusInquiryResponse> communicator =
- new CloudCommunicator<TrxStatusInquiryRequest, TrxStatusInquiryResponse>(UrlPrefix + TrxStatusInquiryApi);
- TrxStatusInquiryRequest request = new TrxStatusInquiryRequest
- {
- tid = epsTrxModel.tid,
- datetime = DateTime.Now.ToString("yyyyMMddHHmmss"),
- gun = epsTrxModel.jihao.ToString(),
- mobile = "",
- dept_No = SiteId,
- card_No = epsTrxModel.card_no,
- pre_Amount = epsTrxModel.real_pay_amount,
- ori_ttc = epsTrxModel.ttc,
- token = epsTrxModel.token + DateTimeUtility.CurrentTimeMillis().ToString()
- };
- debugLogger.Add("Sending TrxStatusInquiry: \n" + request.ToString());
- communicator.SendRequest(request);
- debugLogger.Add("Got TrxStatusInquiry response: \n" + communicator.Response?.ToString());
- return communicator.Response;
- }
- private readonly string RefundApi = App.AppSettings["SinochemCloudRefundApi"];
- public RefundResponse Refund(EpsTransactionModel epsTrxModel, DebugLogger debugLogger)
- {
- CloudCommunicator<RefundRequest, RefundResponse> communicator =
- new CloudCommunicator<RefundRequest, RefundResponse>(UrlPrefix + RefundApi);
- RefundRequest request = new RefundRequest
- {
- tid = epsTrxModel.tid,
- datetime = DateTime.Now.ToString("yyyyMMddHHmmss"),
- gun = epsTrxModel.jihao.ToString(),
- mobile = "",
- dept_No = SiteId,
- card_No = epsTrxModel.card_no,
- pre_Amount = epsTrxModel.real_pay_amount,
- ori_ttc = epsTrxModel.ttc,
- token = epsTrxModel.token + DateTimeUtility.CurrentTimeMillis().ToString()
- };
- debugLogger.Add("Sending Refund: \n" + request.ToString());
- communicator.SendRequest(request);
- debugLogger.Add("Got Refund response: \n" + communicator.Response?.ToString());
- return communicator.Response;
- }
- }
- class DateTimeUtility
- {
- private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- public static long CurrentTimeMillis()
- {
- return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
- }
- }
- }
|