Merchant.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using PaySharp.Core;
  4. namespace PaySharp.Alipay
  5. {
  6. public class Merchant : IMerchant
  7. {
  8. #region 属性
  9. /// <summary>
  10. /// 应用ID
  11. /// </summary>
  12. [Required(ErrorMessage = "请输入支付机构提供的应用编号")]
  13. public string AppId { get; set; }
  14. /// <summary>
  15. /// 签名类型
  16. /// </summary>
  17. public string SignType { get; set; } = "RSA2";
  18. /// <summary>
  19. /// 格式
  20. /// </summary>
  21. public string Format => "JSON";
  22. /// <summary>
  23. /// 时间戳
  24. /// </summary>
  25. public string Timestamp => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  26. /// <summary>
  27. /// 版本
  28. /// </summary>
  29. public string Version => "1.0";
  30. /// <summary>
  31. /// 编码格式
  32. /// </summary>
  33. public string Charset => "UTF-8";
  34. /// <summary>
  35. /// 商户私钥
  36. /// </summary>
  37. [Required(ErrorMessage = "请设置商户私钥")]
  38. [Ignore]
  39. public string Privatekey { get; set; }
  40. /// <summary>
  41. /// 支付宝公钥
  42. /// 查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥
  43. /// </summary>
  44. [Required(ErrorMessage = "请设置支付宝公钥")]
  45. [Ignore]
  46. public string AlipayPublicKey { get; set; }
  47. private string returnUrl;
  48. /// <summary>
  49. /// 返回地址
  50. /// </summary>
  51. public string ReturnUrl
  52. {
  53. get => returnUrl;
  54. set
  55. {
  56. if (value.StartsWith("http") || value.StartsWith("https"))
  57. {
  58. returnUrl = value;
  59. }
  60. else
  61. {
  62. throw new FormatException("返回地址必须以http或https开头");
  63. }
  64. }
  65. }
  66. /// <summary>
  67. /// 网关回发通知URL
  68. /// </summary>
  69. public string NotifyUrl { get; set; }
  70. /// <summary>
  71. /// 支付宝公钥证书文件路径
  72. /// </summary>
  73. public string AlipayCertPath { get; set; }
  74. /// <summary>
  75. /// 应用公钥证书文件路径
  76. /// </summary>
  77. public string MerchantCertPath { get; set; }
  78. /// <summary>
  79. /// 支付宝根证书文件路径
  80. /// </summary>
  81. public string AlipayRootCertPath { get; set; }
  82. #endregion
  83. private CertEnvironment certEnvironment;
  84. /// <summary>
  85. /// 证书模式运行时环境
  86. /// </summary>
  87. public CertEnvironment CertEnvironment
  88. {
  89. get
  90. {
  91. if (string.IsNullOrEmpty(MerchantCertPath) && string.IsNullOrEmpty(AlipayCertPath) && string.IsNullOrEmpty(AlipayRootCertPath))
  92. {
  93. return null;
  94. }
  95. if (certEnvironment != null) return certEnvironment;
  96. certEnvironment = new CertEnvironment(MerchantCertPath, AlipayCertPath, AlipayRootCertPath);
  97. return certEnvironment;
  98. }
  99. }
  100. }
  101. }