2025-06-04 23:53:34 +08:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Web.Configuration;
|
|
|
|
|
2022-11-24 11:45:00 +08:00
|
|
|
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample.Options
|
2021-12-28 14:05:39 +08:00
|
|
|
{
|
|
|
|
public partial class TenpayOptions
|
|
|
|
{
|
|
|
|
public static readonly Lazy<TenpayOptions> Instance = new Lazy<TenpayOptions>(() =>
|
|
|
|
{
|
|
|
|
var configMerchantRegex = new Regex("^TenpayOptions_Merchant_(\\d+)_MerchantId$");
|
|
|
|
var configMerchantIndexes = WebConfigurationManager.AppSettings.AllKeys
|
|
|
|
.Where(key => configMerchantRegex.IsMatch(key))
|
|
|
|
.Select(key => configMerchantRegex.Matches(key)[0].Groups[1].Value)
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
return new TenpayOptions()
|
|
|
|
{
|
|
|
|
Merchants = configMerchantIndexes
|
|
|
|
.Select(i => new Types.WechatMerchant()
|
|
|
|
{
|
|
|
|
MerchantId = WebConfigurationManager.AppSettings[$"TenpayOptions_Merchant_{i}_MerchantId"],
|
|
|
|
SecretV3 = WebConfigurationManager.AppSettings[$"TenpayOptions_Merchant_{i}_SecretV3"],
|
2022-11-24 11:45:00 +08:00
|
|
|
CertificateSerialNumber = WebConfigurationManager.AppSettings[$"TenpayOptions_Merchant_{i}_CertificateSerialNumber"],
|
|
|
|
CertificatePrivateKey = WebConfigurationManager.AppSettings[$"TenpayOptions_Merchant_{i}_CertificatePrivateKey"],
|
2025-06-04 23:53:34 +08:00
|
|
|
PlatformPublicKeyId = WebConfigurationManager.AppSettings[$"TenpayOptions_Merchant_{i}_PlatformPublicKeyId"],
|
|
|
|
PlatformPublicKey = WebConfigurationManager.AppSettings[$"TenpayOptions_Merchant_{i}_PlatformPublicKey"],
|
2021-12-28 14:05:39 +08:00
|
|
|
})
|
|
|
|
.ToArray(),
|
|
|
|
NotifyUrl = WebConfigurationManager.AppSettings[$"TenpayOptions_NotifyUrl"]
|
|
|
|
};
|
|
|
|
}, isThreadSafe: true);
|
|
|
|
}
|
|
|
|
|
2022-01-21 14:30:17 +08:00
|
|
|
public partial class TenpayOptions
|
2021-12-28 14:05:39 +08:00
|
|
|
{
|
|
|
|
public Types.WechatMerchant[] Merchants { get; set; } = Array.Empty<Types.WechatMerchant>();
|
|
|
|
|
|
|
|
public string NotifyUrl { get; set; } = string.Empty;
|
|
|
|
}
|
|
|
|
|
2022-01-21 14:30:17 +08:00
|
|
|
public partial class TenpayOptions
|
2021-12-28 14:05:39 +08:00
|
|
|
{
|
|
|
|
public static class Types
|
|
|
|
{
|
|
|
|
public class WechatMerchant
|
|
|
|
{
|
|
|
|
public string MerchantId { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
public string SecretV3 { get; set; } = string.Empty;
|
|
|
|
|
2022-11-24 11:45:00 +08:00
|
|
|
public string CertificateSerialNumber { get; set; } = string.Empty;
|
2021-12-28 14:05:39 +08:00
|
|
|
|
2022-11-24 11:45:00 +08:00
|
|
|
public string CertificatePrivateKey { get; set; } = string.Empty;
|
2025-06-04 23:53:34 +08:00
|
|
|
|
|
|
|
public string PlatformPublicKeyId { get; set; }
|
|
|
|
|
|
|
|
public string PlatformPublicKey { get; set; }
|
2021-12-28 14:05:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|