using System; using Alipay.EasySDK.Kernel; using System.Reflection; namespace Alipay.EasySDK.Factory { /// /// 客户端工厂,用于快速配置和访问各种场景下的API Client /// /// 注:该Factory获取的Client不可储存重复使用,请每次均通过Factory完成调用 /// public static class Factory { public const string SDK_VERSION = "alipay-easysdk-net-2.1.0"; /// /// 将一些初始化耗时较多的信息缓存在上下文中 /// private static Context context; /// /// 设置客户端参数,只需设置一次,即可反复使用各种场景下的API Client /// /// 客户端参数对象 public static void SetOptions(Config options) { context = new Context(options, SDK_VERSION); } /// /// 获取调用OpenAPI所需的客户端实例 /// 本方法用于调用SDK扩展包中的API Client下的方法 /// /// 注:返回的实例不可重复使用,只可用于单次调用 /// /// 泛型参数 /// API Client的类型对象 /// client实例,用于发起单次调用 public static T GetClient() { Type type = typeof(T); ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(Client) }); context.SdkVersion = GetSdkVersion(type); return (T)constructor.Invoke(new object[] { new Client(context) }); } private static string GetSdkVersion(Type client) { return context.SdkVersion + "-" + client.FullName .Replace("EasySDK.", "") .Replace(".Client", "") .Replace(".", "-"); } /// /// 基础能力相关 /// public static class Base { /// /// 获取图片相关API Client /// /// 图片相关API Client public static EasySDK.Base.Image.Client Image() { return new EasySDK.Base.Image.Client(new Client(context)); } /// /// 获取视频相关API Client /// /// 视频相关API Client public static EasySDK.Base.Video.Client Video() { return new EasySDK.Base.Video.Client(new Client(context)); } /// /// 获取OAuth认证相关API Client /// /// OAuth认证相关API Client public static EasySDK.Base.OAuth.Client OAuth() { return new EasySDK.Base.OAuth.Client(new Client(context)); } /// /// 获取小程序二维码相关API Client /// /// 小程序二维码相关API Client public static EasySDK.Base.Qrcode.Client Qrcode() { return new EasySDK.Base.Qrcode.Client(new Client(context)); } } /// /// 营销能力相关 /// public static class Marketing { /// /// 获取生活号相关API Client /// /// 生活号相关API Client public static EasySDK.Marketing.OpenLife.Client OpenLife() { return new EasySDK.Marketing.OpenLife.Client(new Client(context)); } /// /// 获取支付宝卡包相关API Client /// /// 支付宝卡包相关API Client public static EasySDK.Marketing.Pass.Client Pass() { return new EasySDK.Marketing.Pass.Client(new Client(context)); } /// /// 获取小程序模板消息相关API Client /// /// 小程序模板消息相关API Client public static EasySDK.Marketing.TemplateMessage.Client TemplateMessage() { return new EasySDK.Marketing.TemplateMessage.Client(new Client(context)); } } /// /// 会员能力相关 /// public static class Member { /// /// 获取支付宝身份认证相关API Client /// /// 支付宝身份认证相关API Client public static EasySDK.Member.Identification.Client Identification() { return new EasySDK.Member.Identification.Client(new Client(context)); } } /// /// 支付能力相关 /// public static class Payment { /// /// 获取支付通用API Client /// /// 支付通用API Client public static EasySDK.Payment.Common.Client Common() { return new EasySDK.Payment.Common.Client(new Client(context)); } /// /// 获取当面付API Client /// /// 当面付API Client public static EasySDK.Payment.FaceToFace.Client FaceToFace() { return new EasySDK.Payment.FaceToFace.Client(new Client(context)); } /// /// 获取花呗API Client /// /// 花呗API Client public static EasySDK.Payment.Huabei.Client Huabei() { return new EasySDK.Payment.Huabei.Client(new Client(context)); } /// /// 获取手机APP支付API Client /// /// 手机APP支付API Client public static EasySDK.Payment.App.Client App() { return new EasySDK.Payment.App.Client(new Client(context)); } /// /// 获取电脑网站支付API Client /// /// 电脑网站支付API public static EasySDK.Payment.Page.Client Page() { return new EasySDK.Payment.Page.Client(new Client(context)); } /// /// 获取手机网站支付API Client /// /// 手机网站支付API public static EasySDK.Payment.Wap.Client Wap() { return new EasySDK.Payment.Wap.Client(new Client(context)); } } /// /// 安全能力相关 /// public static class Security { /// /// 获取文本风险识别相关API Client /// /// 文本风险识别相关API Client public static EasySDK.Security.TextRisk.Client TextRisk() { return new EasySDK.Security.TextRisk.Client(new Client(context)); } } /// /// 辅助工具 /// public static class Util { /// /// 获取OpenAPI通用接口,可通过自行拼装参数,调用几乎所有OpenAPI /// /// OpenAPI通用接口 public static EasySDK.Util.Generic.Client Generic() { return new EasySDK.Util.Generic.Client(new Client(context)); } /// /// 获取AES128加解密相关API Client,常用于会员手机号的解密 /// /// AES128加解密相关API Client public static EasySDK.Util.AES.Client AES() { return new EasySDK.Util.AES.Client(new Client(context)); } } } }