Context.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using Tea;
  4. using Alipay.EasySDK.Kernel.Util;
  5. namespace Alipay.EasySDK.Kernel
  6. {
  7. public class Context
  8. {
  9. /// <summary>
  10. /// 客户端配置参数
  11. /// </summary>
  12. private readonly Dictionary<string, object> config;
  13. /// <summary>
  14. /// 证书模式运行时环境
  15. /// </summary>
  16. public CertEnvironment CertEnvironment { get; }
  17. /// <summary>
  18. /// SDK版本号
  19. /// </summary>
  20. public string SdkVersion { get; set; }
  21. public Context(Config config, string sdkVersion)
  22. {
  23. this.config = config.ToMap();
  24. SdkVersion = sdkVersion;
  25. ArgumentValidator.CheckArgument(AlipayConstants.RSA2.Equals(GetConfig(AlipayConstants.SIGN_TYPE_CONFIG_KEY)),
  26. "Alipay Easy SDK只允许使用RSA2签名方式,RSA签名方式由于安全性相比RSA2弱已不再推荐。");
  27. if (!string.IsNullOrEmpty(GetConfig(AlipayConstants.ALIPAY_CERT_PATH_CONFIG_KEY)))
  28. {
  29. CertEnvironment = new CertEnvironment(
  30. GetConfig(AlipayConstants.MERCHANT_CERT_PATH_CONFIG_KEY),
  31. GetConfig(AlipayConstants.ALIPAY_CERT_PATH_CONFIG_KEY),
  32. GetConfig(AlipayConstants.ALIPAY_ROOT_CERT_PATH_CONFIG_KEY));
  33. }
  34. }
  35. public string GetConfig(string key)
  36. {
  37. return (string)config[key];
  38. }
  39. }
  40. }