public void should_auto_download_alipay_public_cert()
        {
            CertParams certParams = TestAccount.ProdCert.CertParams;

            //将支付宝公钥证书路径故意设置成商户证书路径,以便触发自动下载支付宝公钥证书链路
            certParams.AlipayPublicCertPath = certParams.AppCertPath;
            IAopClient client = new DefaultAopClient(TestAccount.ProdCert.Gateway, TestAccount.ProdCert.AppId,
                                                     TestAccount.ProdCert.AppPrivateKey, "json", "1.0", "RSA2", "utf-8", false, certParams);
            AlipayOpenOperationOpenbizmockBizQueryRequest request = GetRequest();

            AlipayOpenOperationOpenbizmockBizQueryResponse response = client.CertificateExecute(request);

            Assert.AreEqual(response.IsError, false);
            Assert.AreEqual(response.Code, "10000");
        }
        public static CertParams GetCertParams(string appid, HttpServerUtilityBase httpServerUtilityBase)
        {
            string alipayCertPublicKey_RSA2 = httpServerUtilityBase.MapPath("~" + $"/Cert/alipayCertPublicKey_RSA2.crt");
            string alipayRootCert           = httpServerUtilityBase.MapPath("~" + $"/Cert/alipayRootCert.crt");
            string appCertPublicKey         = httpServerUtilityBase.MapPath("~" + $"/Cert/appCertPublicKey_" + appid + ".crt");

            CertParams certParams = new CertParams
            {
                AlipayPublicCertPath = alipayCertPublicKey_RSA2,
                AppCertPath          = appCertPublicKey,
                RootCertPath         = alipayRootCert
            };

            return(certParams);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初始化证书所需运行时参数
        /// </summary>
        /// <param name="certParams">用户传入的证书相关参数</param>
        /// <param name="signType">算法类型</param>
        public CertEnvironment(CertParams certParams, string signType)
        {
            //解析支付宝根证书序列号
            if (!string.IsNullOrEmpty(certParams.RootCertContent))
            {
                this.RootCertContent = certParams.RootCertContent;
            }
            else
            {
                this.RootCertContent = File.ReadAllText(certParams.RootCertPath);
            }

            this.RootCertSN = AntCertificationUtil.GetRootCertSN(RootCertContent, signType);

            //解析应用证书序列号
            if (!string.IsNullOrEmpty(certParams.AppCertContent))
            {
                X509Certificate appCert = AntCertificationUtil.ParseCert(certParams.AppCertContent);
                this.AppCertSN = AntCertificationUtil.GetCertSN(appCert);
            }
            else
            {
                X509Certificate appCert = AntCertificationUtil.ParseCert(File.ReadAllText(certParams.AppCertPath));
                this.AppCertSN = AntCertificationUtil.GetCertSN(appCert);
            }


            //解析支付宝公钥证书序列号
            X509Certificate alipayPublicKeyCert;

            if (!string.IsNullOrEmpty(certParams.AlipayPublicCertContent))
            {
                alipayPublicKeyCert = AntCertificationUtil.ParseCert(certParams.AlipayPublicCertContent);
            }
            else
            {
                alipayPublicKeyCert = AntCertificationUtil.ParseCert(File.ReadAllText(certParams.AlipayPublicCertPath));
            }
            string alipayPublicKeyCertSN = AntCertificationUtil.GetCertSN(alipayPublicKeyCert);
            //解析支付宝公钥
            string alipayPublicKey = AntCertificationUtil.ExtractPemPublicKeyFromCert(alipayPublicKeyCert);

            //缓存支付宝公钥证书序号对应的支付宝公钥
            AddNewAlipayPublicKey(alipayPublicKeyCertSN, alipayPublicKey);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetCertificationsForUser([FromQuery] CertParams certParams)
        {
            var user = await _genUserRepo.GetByIdAsync(certParams.UserId);

            if (user == null)
            {
                return(BadRequest("Invalid Trainer"));
            }
            if (user.IsTrainer == false)
            {
                return(BadRequest("You have to be a Trainer"));
            }

            var certs = await _repo.GetCertificationsForUser(certParams);

            var certsToReturn = _mapper.Map <IEnumerable <CertificationForReturnDto> >(certs);

            Response.AddPagination(certs.CurrentPage, certs.PageSize,
                                   certs.TotalCount, certs.TotalPages);

            return(Ok(certsToReturn));
        }
Exemplo n.º 5
0
        public async Task <PagedList <Certification> > GetCertificationsForUser(CertParams certParams)
        {
            var certs = _context.Certifications.AsQueryable();

            certs = certs.Where(x => x.UserId == certParams.UserId);
            if (string.IsNullOrEmpty(certParams.OrderBy))
            {
                certParams.OrderBy = "most_recent";
            }
            switch (certParams.OrderBy.ToLower())
            {
            case "most_recent":
                certs = certs.OrderByDescending(u => u.Created);
                break;

            case "oldest":
                certs = certs.OrderBy(u => u.Created);
                break;
            }

            return(await PagedList <Certification> .CreateAsync(certs, certParams.PageNumber, certParams.PageSize));
        }