Ejemplo n.º 1
0
        public UnionPayClient(IOptions <UnionPayOptions> optionsAccessor)
        {
            Options = optionsAccessor?.Value ?? new UnionPayOptions();
            Client  = new HttpClientEx();

            if (string.IsNullOrEmpty(Options.SignCert) || string.IsNullOrEmpty(Options.SignCertPassword))
            {
                throw new Exception("SignCert or SignCertPassword is Empty!");
            }
            SignCertificate = UnionPaySignature.GetSignCertificate(Options.SignCert, Options.SignCertPassword);

            if (string.IsNullOrEmpty(Options.EncryptCert))
            {
                throw new Exception("EncryptCert is Empty!");
            }
            EncryptCertificate = UnionPaySignature.GetCertificate(Options.EncryptCert);

            if (string.IsNullOrEmpty(Options.MiddleCert))
            {
                throw new Exception("MiddleCert is Empty!");
            }
            MiddleCertificate = UnionPaySignature.GetCertificate(Options.MiddleCert);

            if (string.IsNullOrEmpty(Options.RootCert))
            {
                throw new Exception("RootCert is Empty!");
            }
            RootCertificate = UnionPaySignature.GetCertificate(Options.RootCert);
        }
Ejemplo n.º 2
0
        private void Init()
        {
            if (string.IsNullOrEmpty(Options.SignCert) || string.IsNullOrEmpty(Options.SignCertPassword))
            {
                throw new Exception("SignCert or SignCertPassword is Empty!");
            }
            SignCertificate = UnionPaySignature.GetSignCertificate(Options.SignCert, Options.SignCertPassword);

            if (string.IsNullOrEmpty(Options.EncryptCert))
            {
                throw new Exception("EncryptCert is Empty!");
            }
            EncryptCertificate = UnionPaySignature.GetCertificate(Options.EncryptCert);

            if (string.IsNullOrEmpty(Options.MiddleCert))
            {
                throw new Exception("MiddleCert is Empty!");
            }
            MiddleCertificate = UnionPaySignature.GetCertificate(Options.MiddleCert);

            if (string.IsNullOrEmpty(Options.RootCert))
            {
                throw new Exception("RootCert is Empty!");
            }
            RootCertificate = UnionPaySignature.GetCertificate(Options.RootCert);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="certificate"></param>
        /// <param name="certPwd"></param>
        /// <returns></returns>
        public static UnionPayCertificate GetSignCertificate(string certificate, string certPwd)
        {
            FileStream fs          = null;
            var        Certificate = new UnionPayCertificate();

            try
            {
                fs = new FileStream(certificate, FileMode.Open, FileAccess.Read);
                var store = new Pkcs12Store(fs, certPwd.ToCharArray());

                var alias = string.Empty;
                foreach (string n in store.Aliases)
                {
                    if (store.IsKeyEntry(n))
                    {
                        alias = n;
                    }
                }

                var chain = store.GetCertificateChain(alias);
                var cert  = chain[0].Certificate;

                Certificate.key    = store.GetKey(alias).Key;
                Certificate.cert   = cert;
                Certificate.certId = cert.SerialNumber.ToString();
                //return new UnionPayCertificate
                //{
                //    key = store.GetKey(alias).Key,
                //    cert = cert,
                //    certId = cert.SerialNumber.ToString()
                //};
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return(Certificate);
        }
Ejemplo n.º 4
0
        public UnionPayNotifyClient(
            IOptions <UnionPayOptions> optionsAccessor,
            ILogger <UnionPayNotifyClient> logger)
        {
            Options = optionsAccessor?.Value ?? new UnionPayOptions();
            Logger  = logger;

            if (string.IsNullOrEmpty(Options.MiddleCert))
            {
                throw new ArgumentNullException(nameof(Options.MiddleCert));
            }

            if (string.IsNullOrEmpty(Options.RootCert))
            {
                throw new ArgumentNullException(nameof(Options.RootCert));
            }

            MiddleCertificate = UnionPaySignature.GetCertificate(Options.MiddleCert);
            RootCertificate   = UnionPaySignature.GetCertificate(Options.RootCert);
        }
Ejemplo n.º 5
0
        public UnionPayClient(
            IOptions <UnionPayOptions> optionsAccessor,
            ILogger <UnionPayClient> logger)
        {
            Options = optionsAccessor.Value;
            Logger  = logger;
            Client  = new HttpClientEx();

            if (string.IsNullOrEmpty(Options.SignCert))
            {
                throw new ArgumentNullException(nameof(Options.SignCert));
            }

            if (string.IsNullOrEmpty(Options.SignCertPassword))
            {
                throw new ArgumentNullException(nameof(Options.SignCertPassword));
            }

            if (string.IsNullOrEmpty(Options.EncryptCert))
            {
                throw new ArgumentNullException(nameof(Options.EncryptCert));
            }

            if (string.IsNullOrEmpty(Options.MiddleCert))
            {
                throw new ArgumentNullException(nameof(Options.MiddleCert));
            }

            if (string.IsNullOrEmpty(Options.RootCert))
            {
                throw new ArgumentNullException(nameof(Options.RootCert));
            }

            SignCertificate    = UnionPaySignature.GetSignCertificate(Options.SignCert, Options.SignCertPassword);
            EncryptCertificate = UnionPaySignature.GetCertificate(Options.EncryptCert);
            MiddleCertificate  = UnionPaySignature.GetCertificate(Options.MiddleCert);
            RootCertificate    = UnionPaySignature.GetCertificate(Options.RootCert);
        }
Ejemplo n.º 6
0
        public UnionPayClient(IOptions <UnionPayOptions> unionPayOptions, ILogger <UnionPayClient> logger)
        {
            this._unionPayOptions = unionPayOptions.Value;
            this._logger          = logger;

            if (string.IsNullOrWhiteSpace(_unionPayOptions.Version))
            {
                throw new OmniPayException(nameof(_unionPayOptions.Version));
            }
            if (string.IsNullOrWhiteSpace(_unionPayOptions.SignCertPath))
            {
                throw new OmniPayException(nameof(_unionPayOptions.SignCertPath));
            }
            if (string.IsNullOrWhiteSpace(_unionPayOptions.SignCertPwd))
            {
                throw new OmniPayException(nameof(_unionPayOptions.SignCertPwd));
            }

            SignCertificate    = UnionPayUntil.GetSignCertificate(_unionPayOptions.SignCertPath, _unionPayOptions.SignCertPwd);
            EncryptCertificate = UnionPayUntil.GetCertificate(_unionPayOptions.EncryptCertPath);
            MiddleCertificate  = UnionPayUntil.GetCertificate(_unionPayOptions.MiddleCertPath);
            RootCertificate    = UnionPayUntil.GetCertificate(_unionPayOptions.RootCertPath);
        }