You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.6 KiB
C#
106 lines
3.6 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Amazon Credential
|
|
/// </summary>
|
|
/// <param name="clientId">ClientId</param>
|
|
/// <param name="clientSecret">ClientSecret</param>
|
|
/// <param name="refreshToken">RefreshToken</param>
|
|
/// <param name="marketPlaceId"></param>
|
|
/// <param name="sellerId"></param>
|
|
/// <param name="proxyAddress"></param>
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// LAW ClientId
|
|
/// </summary>
|
|
public string ClientId { get; set; }
|
|
|
|
/// <summary>
|
|
/// LAW ClientSecret
|
|
/// </summary>
|
|
public string ClientSecret { get; set; }
|
|
|
|
/// <summary>
|
|
/// LWA RefreshToken
|
|
/// </summary>
|
|
public string RefreshToken { get; set; }
|
|
|
|
/// <summary>
|
|
/// 市场
|
|
/// </summary>
|
|
public MarketPlace MarketPlace { get; set; }
|
|
|
|
private CacheTokenData CacheTokenData { get; }
|
|
|
|
/// <summary>
|
|
/// 是否启用速率限制
|
|
/// </summary>
|
|
public bool IsActiveLimitRate { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// 环境
|
|
/// </summary>
|
|
public Constants.Environments Environment { get; set; } = Constants.Environments.Production;
|
|
|
|
/// <summary>
|
|
/// 最大重试次数
|
|
/// </summary>
|
|
public int MaxThrottledRetryCount { get; set; } = 3;
|
|
|
|
/// <summary>
|
|
/// 是否启用调试模式
|
|
/// </summary>
|
|
public bool IsDebugMode { get; set; }
|
|
|
|
public string SellerId { get; set; }
|
|
public string ProxyAddress { get; set; }
|
|
public static bool DebugMode { get; set; }
|
|
|
|
|
|
internal Dictionary<RateLimitType, RateLimits> 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);
|
|
}
|
|
}
|
|
} |