using System;
using System.ComponentModel.DataAnnotations;
using PaySharp.Core;
namespace PaySharp.Alipay
{
public class Merchant : IMerchant
{
#region 属性
///
/// 应用ID
///
[Required(ErrorMessage = "请输入支付机构提供的应用编号")]
public string AppId { get; set; }
///
/// 签名类型
///
public string SignType { get; set; } = "RSA2";
///
/// 格式
///
public string Format => "JSON";
///
/// 时间戳
///
public string Timestamp => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
///
/// 版本
///
public string Version => "1.0";
///
/// 编码格式
///
public string Charset => "UTF-8";
///
/// 商户私钥
///
[Required(ErrorMessage = "请设置商户私钥")]
[Ignore]
public string Privatekey { get; set; }
///
/// 支付宝公钥
/// 查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥
///
[Required(ErrorMessage = "请设置支付宝公钥")]
[Ignore]
public string AlipayPublicKey { get; set; }
private string returnUrl;
///
/// 返回地址
///
public string ReturnUrl
{
get => returnUrl;
set
{
if (value.StartsWith("http") || value.StartsWith("https"))
{
returnUrl = value;
}
else
{
throw new FormatException("返回地址必须以http或https开头");
}
}
}
///
/// 网关回发通知URL
///
public string NotifyUrl { get; set; }
///
/// 支付宝公钥证书文件路径
///
public string AlipayCertPath { get; set; }
///
/// 应用公钥证书文件路径
///
public string MerchantCertPath { get; set; }
///
/// 支付宝根证书文件路径
///
public string AlipayRootCertPath { get; set; }
#endregion
private CertEnvironment certEnvironment;
///
/// 证书模式运行时环境
///
public CertEnvironment CertEnvironment
{
get
{
if (string.IsNullOrEmpty(MerchantCertPath) && string.IsNullOrEmpty(AlipayCertPath) && string.IsNullOrEmpty(AlipayRootCertPath))
{
return null;
}
if (certEnvironment != null) return certEnvironment;
certEnvironment = new CertEnvironment(MerchantCertPath, AlipayCertPath, AlipayRootCertPath);
return certEnvironment;
}
}
}
}