Exemplo n.º 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());
                    }
                }
            }
        }
Exemplo n.º 2
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());
                 }
             }
         }
     }
 }
Exemplo n.º 3
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());
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 注册支付结果监听器
 /// </summary>
 /// <param name="listener"></param>
 public static void RegisterResultListener(IPayResultListener listener)
 {
     _PayResultListeners.Add(listener);
 }