123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1.OCPPAuth
- {
- internal static class Ebus_capital
- {
- public static void Test()
- {
- //var url = "https://buscharge.zerovatech.com/service/api/v1/cpo/station";
- //var _body = "";
- //var timestamp = "";
- //string signature = GetSignature(GetUnencodeText(url, _body, timestamp, headers["PartnerId"], saltkey));
- var result = IsExpiryTime("1712031689");
- Console.WriteLine(result);
- }
- private static bool IsExpiryTime(string timestamp)
- {
- bool result = true;
- long minTime = DateTimeOffset.UtcNow.AddSeconds(-300).ToUnixTimeSeconds();
- long maxTime = DateTimeOffset.UtcNow.AddSeconds(300).ToUnixTimeSeconds();
- long requestTime = 0;
- if (long.TryParse(timestamp, out requestTime))
- {
- if (minTime < requestTime && maxTime > requestTime)
- {
- result = false;
- }
- }
- DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
- dateTime = dateTime.AddSeconds(requestTime).ToLocalTime();
- return result;
- }
- private static string GetUnencodeText(string url, string body, string timestamp, string partnerId, string saltkey)
- {
- string tempText = url.Substring(url.IndexOf('?') + 1).ToLower();
- tempText = tempText.StartsWith("http") ? string.Empty : tempText;
- body = tempText + body;
- string unencodeText = string.Format("{0}{1}{2}{3}", body, timestamp, partnerId, saltkey).ToLower();
- return unencodeText;
- }
- private static string GetSignature(string unencodeText)
- {
- if ((unencodeText == null) || (unencodeText.Length == 0))
- {
- return String.Empty;
- }
- unencodeText = unencodeText.ToLower();
- MD5 md5 = MD5.Create();// new MD5CryptoServiceProvider();
- byte[] textToHash = Encoding.UTF8.GetBytes(unencodeText);
- byte[] result = md5.ComputeHash(textToHash);
- return BitConverter.ToString(result).Replace("-", "").ToLower();
- }
- }
- }
|