using System.Collections.Generic; using Amazon.SellingPartnerApiSDK.AmazonSpApiSDK.Models.Exceptions; using Amazon.SellingPartnerApiSDK.AmazonSpApiSDK.Models.Token; using Amazon.SellingPartnerApiSDK.Misc; using static Amazon.SellingPartnerApiSDK.Misc.Constants; namespace Amazon.SellingPartnerApiSDK { public class AmazonCredential { /// /// Amazon Credential /// /// ClientId /// ClientSecret /// RefreshToken /// /// /// public AmazonCredential( string clientId, string clientSecret, string refreshToken, string marketPlaceId, string sellerId = null, string proxyAddress = null ) { if (string.IsNullOrEmpty(clientId)) throw new AmazonInvalidInputException("无效输入, ClientId不能为空!"); if (string.IsNullOrEmpty(clientSecret)) throw new AmazonInvalidInputException("无效输入, ClientSecret不能为空!"); if (string.IsNullOrEmpty(refreshToken)) throw new AmazonInvalidInputException("无效输入, RefreshToken不能为空!"); if (string.IsNullOrEmpty(marketPlaceId)) throw new AmazonInvalidInputException("无效输入, MarketPlaceId不能为空!"); ClientId = clientId; ClientSecret = clientSecret; RefreshToken = refreshToken; MarketPlace = MarketPlace.GetMarketPlaceById(marketPlaceId); SellerId = sellerId; ProxyAddress = proxyAddress; CacheTokenData = new CacheTokenData(); } /// /// LAW ClientId /// public string ClientId { get; set; } /// /// LAW ClientSecret /// public string ClientSecret { get; set; } /// /// LWA RefreshToken /// public string RefreshToken { get; set; } /// /// 市场 /// public MarketPlace MarketPlace { get; set; } private CacheTokenData CacheTokenData { get; } /// /// 是否启用速率限制 /// public bool IsActiveLimitRate { get; set; } = true; /// /// 环境 /// public Constants.Environments Environment { get; set; } = Constants.Environments.Production; /// /// 最大重试次数 /// public int MaxThrottledRetryCount { get; set; } = 3; /// /// 是否启用调试模式 /// public bool IsDebugMode { get; set; } public string SellerId { get; set; } public string ProxyAddress { get; set; } public static bool DebugMode { get; set; } internal Dictionary UsagePlansTimings { get; set; } = RateLimitsDefinitions.RateLimitsTime(); public TokenResponse GetToken(CacheTokenData.TokenDataType tokenDataType) { return CacheTokenData.GetToken(tokenDataType); } public void SetToken(CacheTokenData.TokenDataType tokenDataType, TokenResponse token) { CacheTokenData.SetToken(tokenDataType, token); } } }