/* using asap.core; using game; using Newtonsoft.Json; using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using UnityEngine; public class RedeemCodeService { public class CheckRedemptionKeyRequest { public string playerID; public string Key { get; set; } } public class CheckRedemptionKeyResponse { /// /// RedeemSucc:DropID RegisterDayNotEnough:NeedDays /// public int Code; public ECheckValidateResult Result; } public enum ECheckValidateResult { invalid = 0, success, hasRedeemed, expired, NotFound, MaxRedeemCount, BusyServer, RegisterDayNotEnough, } #region Field&&Property ༼ つ ◕_◕ ༽つ--ฅʕ•̫͡•ʔฅ public bool IsUnlock = false; public DateTime nextRedeemTime; private HttpClient _funcClient; private string _funcKey; private IConfig _config; #endregion #region Function ( =∩王∩= )m~~o(=•ェ•=)m public RedeemCodeService(IConfig config) { this._config = config; var url = config.Get(GConstant.K_FuncUrl, ""); _funcKey = config.Get(GConstant.K_FuncKey, ""); if(string.IsNullOrEmpty(_funcKey)||string.IsNullOrEmpty(url)) { Debug.LogError("FuncUrl or FuncKey is Null"); return; } _funcClient = new HttpClient(); _funcClient.BaseAddress = new System.Uri(url); _funcClient.DefaultRequestHeaders.Add("x-functions-key", _funcKey); _funcClient.Timeout = TimeSpan.FromSeconds(15); } /// /// /// /// 0:success 1:invalide 2:hasUsed 3:timeExpired public async Task CheckRedemptionKeyValidate(string key) { var response = new CheckRedemptionKeyResponse(); // var cdKeys = GContext.container.Resolve().TbCDKey.DataMap; // var dropID = -1; if ( string.IsNullOrEmpty(key) ) { response.Result = ECheckValidateResult.invalid; return response; } var result = await CheckRedmptionKeyVallidateInServer(key); return result; } private async Task CheckRedmptionKeyVallidateInServer(string key) { var checkValidateRequest = new CheckRedemptionKeyRequest { Key = key, playerID = GContext.container.Resolve().UserId, }; //Request var reqJson = JsonConvert.SerializeObject(checkValidateRequest); var reqContent = new StringContent(reqJson, Encoding.UTF8, "application/json"); var postResponse= await _funcClient.PostAsync("api/CheckRedeemCodeValiad", reqContent); //Response var respJson = ""; if ( postResponse.IsSuccessStatusCode ) { respJson= await postResponse.Content.ReadAsStringAsync(); } //error else { UnityEngine.Debug.LogError($"[RedemptionKey error] {postResponse.StatusCode}"); UnityEngine.Debug.LogError($"[RedemptionKey content][{respJson}]"); } if ( string.IsNullOrEmpty(respJson) ) { var response = new CheckRedemptionKeyResponse(); response.Result = ECheckValidateResult.invalid; return response; } //success return JsonConvert.DeserializeObject(respJson); } #endregion } */