Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 3
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);
        }