Beispiel #1
0
        /// <summary>
        /// 开启支付功能,如果是网站应用,需要在static Global 静态构造函数中调用
        /// </summary>
        /// <param name="config"></param>
        /// <param name="listener"></param>
        /// <param name="useHttps">运行的站点是否采用https</param>
        public static void Enable(IPayConfig config, IPayResultListener listener, bool useHttps)
        {
            _Config = config;
            if (listener != null)
            {
                RegisterResultListener(listener);
            }
            UseHttps = useHttps;
            if (!SettedRequestHandlers)
            {
                SettedRequestHandlers = true;

                try
                {
                    using (Log log = new Log("Jack.Pay.Enable"))
                    {
                        log.Log("Begin AddRequestHandlers");

                        Jack.HttpRequestHandlers.Manager.AddRequestHandlers(typeof(PayFactory).Assembly);
                        log.Log("End AddRequestHandlers");
                    }
                }
                catch (Exception ex)
                {
                    using (Log log = new Log("AddRequestHandlers error"))
                    {
                        log.Log(ex.ToString());
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 创建签名服务
 /// </summary>
 /// <param name="config">微信支付配置</param>
 /// <param name="builder">参数生成器</param>
 public static ISignManager Create(IPayConfig config, HttpRequest httpRequest, ParameterBuilder builder, PaySignType?signType = null)
 {
     if (signType != null && signType == PaySignType.Md5)
     {
         return(new Md5SignManager(new SignKey(config.PrivateKey), httpRequest, builder));
     }
     if (signType != null && signType == PaySignType.HmacSha256)
     {
         return(new HmacSha256SignManager(new SignKey(config.PrivateKey), httpRequest, builder));
     }
     if (builder.GetValue(config.SignType.ToString())?.ToString() == PaySignType.Md5.Description())
     {
         return(new Md5SignManager(new SignKey(config.PrivateKey), httpRequest, builder));
     }
     if (builder.GetValue(config.SignType.ToString())?.ToString() == PaySignType.HmacSha256.Description())
     {
         return(new HmacSha256SignManager(new SignKey(config.PrivateKey), httpRequest, builder));
     }
     if (config.SignType == PaySignType.Md5)
     {
         return(new Md5SignManager(new SignKey(config.PrivateKey), httpRequest, builder));
     }
     if (config.SignType == PaySignType.HmacSha256)
     {
         return(new HmacSha256SignManager(new SignKey(config.PrivateKey), httpRequest, builder));
     }
     throw new NotImplementedException($"未实现签名算法:{config.SignType.Description()}");
 }
Beispiel #3
0
 /// <summary>
 /// 开启支付功能,如果是mvc core,需要在Configure里面调用此方法
 /// </summary>
 /// <param name="config"></param>
 /// <param name="listener"></param>
 /// <param name="mvcApp">如果设为null,表示支付接口的服务器不会主动通知支付结果,Jack.Pay会在后台自动轮询获取支付结果</param>
 /// <param name="useHttps">运行的站点是否采用https</param>
 public static void Enable(IPayConfig config, IPayResultListener listener, IApplicationBuilder mvcApp, bool useHttps)
 {
     if (mvcApp != null)
     {
         _ServiceProvider = mvcApp.ApplicationServices;
     }
     UseHttps = useHttps;
     _Config  = config;
     if (listener != null)
     {
         RegisterResultListener(listener);
     }
     if (!SettedRequestHandlers)
     {
         SettedRequestHandlers = true;
         if (mvcApp != null)
         {
             try
             {
                 Jack.HttpRequestHandlers.Manager.AddRequestHandlers(mvcApp, typeof(PayFactory).Assembly);
             }
             catch (Exception ex)
             {
                 using (CLog logErr = new CLog("PayFactory.Enable error "))
                 {
                     logErr.Log(ex.ToString());
                 }
             }
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// 开启支付功能,此方法必须在static Global()这个静态构造函数里面执行
 /// </summary>
 public static void Enable(IPayConfig config, IPayResultListener listener)
 {
     if (config == null)
     {
         throw new Exception("config is null");
     }
     _Config = config;
     if (listener != null)
     {
         RegisterResultListener(listener);
     }
     if (!SettedWebBeginRequest)
     {
         SettedWebBeginRequest = true;
         using (CLog log = new CLog("PayFactory.Enable "))
         {
             try
             {
                 //取出所有IHttpModule,注册到HttpApplication
                 Type[] types      = typeof(IPay).Assembly.GetTypes();
                 string moduleName = typeof(IHttpModule).FullName;
                 foreach (Type type in types)
                 {
                     //判断这个类是否实现了取出所有IHttpModule接口
                     if (type.GetInterface(moduleName) != null)
                     {
                         log.Log(type.FullName);
                         HttpApplication.RegisterModule(type);
                     }
                 }
             }
             catch (Exception ex)
             {
                 using (CLog logErr = new CLog("PayFactory.Enable error "))
                 {
                     logErr.Log(ex.ToString());
                 }
             }
         }
     }
 }