using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Security.Cryptography;
[GameInfo(rpName: "ExUsa3")]
[GameInfo(rpName: "ExUsa5")]
[GameInfo(rpName: "ExUsa6")]
public int Id { get;set;}
public string Name { get;set;}
[JsonConverter(typeof(StringEnumConverter))]
public MarketType MarketType { get;set;}
public class GameInfoAttribute : Attribute
public GameInfoAttribute(string rpName)
public string RPName { get; set; }
TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
string strRandomResult = NextRandom(1000, 4).ToString();
string randonTime=(long)ts.TotalMilliseconds+ strRandomResult;
Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
private string GetToken(string sToken)
var IV = "CLT40VYBZOUXJ49I";
return Utils.DecryptAES(sToken, key, IV);
private string GetOBSign(string memberCode, bool isMobile, string timestamp = "")
var merchantKey = "bRpRW$P5yJ0xH$LCXzXY3hJcCs1mXe";
var terminal = isMobile ? "mobile" : "pc";
if (string.IsNullOrWhiteSpace(timestamp))
timestamp = DateTime.Now.ToTimestampString();
var signParam = new List<string>
var preSignStr = signParam.Aggregate((result, next) => $"{result}&{next}");
var preSignWithKey = $"{preSignStr.ToMD5()}&{merchantKey.ToMD5()}";
var signHash = preSignWithKey.ToMD5();
private void CaseA(int x)
private void CaseB(int x)
var sw = new Stopwatch();
var compareCount = 50000;
Enumerable.Range(1, compareCount).ToList().ForEach(CaseB);
Console.WriteLine($"CaseB: {sw.ElapsedMilliseconds}");
Enumerable.Range(1, compareCount).ToList().ForEach(CaseA);
public int NextRandom(int numSeeds, int length)
byte[] randomNumber = new byte[length];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(randomNumber);
for (int i = 0; i<length; i++)
randomResult |= ((uint) randomNumber[i] << ((length - 1 - i) * 8));
return (int) (randomResult % numSeeds) + 1;
public void RestClientTest()
var url = "http://ggininder123.com/saintfsdfsf";
var client = new RestClient(url);
var request = new RestRequest(Method.GET);
var response = client.Execute(request);
response.StatusDescription,
Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
static DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
public static DateTime UnixTimestampToUTC(double unixTime)
long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond);
return new DateTime(unixStart.Ticks + unixTimeStampInTicks, DateTimeKind.Utc);
public static long UTCToUnixTimestamp(DateTime dateTime, long timeSpan)
long unixTimeStampInTicks = (dateTime.ToUniversalTime() - unixStart).Ticks;
return unixTimeStampInTicks / timeSpan;
public static string ToTimestampString(this DateTime dateTime)
var timestamp = UTCToUnixTimestamp(dateTime, TimeSpan.TicksPerMillisecond).ToString();
public static TResult IfNotNull<T, TResult>(this T target, Func<T, TResult> getValue)
public static string ToDateString(this DateTime input)
return input.ToString("yyyy-MM-dd");
public static string ToDateTimeString(this DateTime input)
return input.ToString("yyyy-MM-dd HH:mm:ss");
public static T GetAttribute<T>(this Enum enumVal) where T : Attribute
var type = enumVal.GetType();
var memInfo = type.GetMember(enumVal.ToString());
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
return (attributes.Length > 0) ? (T)attributes[0] : null;
public static GameInfoAttribute GetGameInfo(this GameEnum @enum)
return @enum.GetAttribute<GameInfoAttribute>();
private static IDictionary<GameEnum, GameInfoAttribute> _gameInfoCache = new Dictionary<GameEnum, GameInfoAttribute>();
public static GameInfoAttribute GetGameInfo2(this GameEnum @enum)
if (!_gameInfoCache.TryGetValue(@enum, out GameInfoAttribute value))
value = @enum.GetAttribute<GameInfoAttribute>();
_gameInfoCache.Add(@enum, value);
public static IEnumerable<IEnumerable<T>> GroupWhile<T>(this IEnumerable<T> seq, Func<T, T, bool> condition)
List<T> list = new List<T>() { prev };
foreach (T item in seq.Skip(1))
if (condition(prev, item) == false)
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunkSize)
yield return source.Take(chunkSize);
source = source.Skip(chunkSize);
public static string ToMD5(this string str)
using (var cryptoMD5 = System.Security.Cryptography.MD5.Create())
var bytes = Encoding.UTF8.GetBytes(str);
var hash = cryptoMD5.ComputeHash(bytes);
var md5 = BitConverter.ToString(hash)
.Replace("-", String.Empty)
public static class Utils
public static IEnumerable<T> GetEnumValues<T>() where T : Enum
return Enum.GetValues(typeof(T)).Cast<T>();
public static IEnumerable<T> GetAllItems<T>() where T : struct
foreach (object item in Enum.GetValues(typeof(T)))
public static string EncryptAES(string text, string key, string iv)
RijndaelManaged rijndaelCipher = new RijndaelManaged();
rijndaelCipher.Mode = CipherMode.CBC;
rijndaelCipher.Padding = PaddingMode.PKCS7;
rijndaelCipher.KeySize = 128;
rijndaelCipher.BlockSize = 128;
byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(key);
byte[] keyBytes = new byte[16];
int len = pwdBytes.Length;
if (len > keyBytes.Length) len = keyBytes.Length;
System.Array.Copy(pwdBytes, keyBytes, len);
rijndaelCipher.Key = keyBytes;
byte[] ivBytes1 = System.Text.Encoding.UTF8.GetBytes(iv);
byte[] keyBytes1 = new byte[16];
int len1 = ivBytes1.Length;
if (len1 > keyBytes1.Length) len1 = keyBytes1.Length;
System.Array.Copy(ivBytes1, keyBytes1, len1);
rijndaelCipher.IV = ivBytes1;
ICryptoTransform transform = rijndaelCipher.CreateEncryptor();
byte[] plainText = Encoding.UTF8.GetBytes(text);
byte[] cipherBytes = transform.TransformFinalBlock(plainText, 0, plainText.Length);
return Convert.ToBase64String(cipherBytes);
public static string DecryptAES(string text, string key, string iv)
RijndaelManaged rijndaelCipher = new RijndaelManaged();
rijndaelCipher.Mode = CipherMode.CBC;
rijndaelCipher.Padding = PaddingMode.PKCS7;
rijndaelCipher.KeySize = 128;
rijndaelCipher.BlockSize = 128;
byte[] encryptedData = Convert.FromBase64String(text);
byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(key);
byte[] keyBytes = new byte[16];
int len = pwdBytes.Length;
if (len > keyBytes.Length) len = keyBytes.Length;
System.Array.Copy(pwdBytes, keyBytes, len);
rijndaelCipher.Key = keyBytes;
byte[] ivBytes1 = System.Text.Encoding.UTF8.GetBytes(iv);
byte[] keyBytes1 = new byte[16];
int len1 = ivBytes1.Length;
if (len1 > keyBytes1.Length) len1 = keyBytes1.Length;
System.Array.Copy(ivBytes1, keyBytes1, len1);
rijndaelCipher.IV = keyBytes1;
ICryptoTransform transform = rijndaelCipher.CreateDecryptor();
byte[] plainText = transform.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
return Encoding.UTF8.GetString(plainText);
public static void Main()