CertEnvironment.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Alipay\EasySDK\Kernel;
  3. use Alipay\EasySDK\Kernel\Util\AntCertificationUtil;
  4. use http\Exception\RuntimeException;
  5. class CertEnvironment
  6. {
  7. private $rootCertSN;
  8. private $merchantCertSN;
  9. private $cachedAlipayPublicKey;
  10. /**
  11. * 构造证书运行环境
  12. * @param $merchantCertPath string 商户公钥证书路径
  13. * @param $alipayCertPath string 支付宝公钥证书路径
  14. * @param $alipayRootCertPath string 支付宝根证书路径
  15. */
  16. public function certEnvironment($merchantCertPath, $alipayCertPath, $alipayRootCertPath)
  17. {
  18. if (empty($merchantCertPath) || empty($alipayCertPath) || empty($alipayRootCertPath)) {
  19. throw new RuntimeException("证书参数merchantCertPath、alipayCertPath或alipayRootCertPath设置不完整。");
  20. }
  21. $antCertificationUtil = new AntCertificationUtil();
  22. $this->rootCertSN = $antCertificationUtil->getRootCertSN($alipayRootCertPath);
  23. $this->merchantCertSN = $antCertificationUtil->getCertSN($merchantCertPath);
  24. $this->cachedAlipayPublicKey = $antCertificationUtil->getPublicKey($alipayCertPath);
  25. }
  26. /**
  27. * @return mixed
  28. */
  29. public function getRootCertSN()
  30. {
  31. return $this->rootCertSN;
  32. }
  33. /**
  34. * @return mixed
  35. */
  36. public function getMerchantCertSN()
  37. {
  38. return $this->merchantCertSN;
  39. }
  40. /**
  41. * @return mixed
  42. */
  43. public function getCachedAlipayPublicKey()
  44. {
  45. return $this->cachedAlipayPublicKey;
  46. }
  47. }