SystemPemServices.php 926 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\services\system;
  3. use app\dao\system\SystemPemDao;
  4. use app\services\BaseServices;
  5. class SystemPemServices extends BaseServices
  6. {
  7. public function __construct(SystemPemDao $dao)
  8. {
  9. $this->dao = $dao;
  10. }
  11. public function savePem($data)
  12. {
  13. $this->dao->savePem($data);
  14. return true;
  15. }
  16. public function getPemPath($name)
  17. {
  18. $path = '';
  19. $info = $this->dao->get(['name' => $name]);
  20. if ($info) {
  21. $path = root_path('runtime/pem') . $info['path'] . '.pem';
  22. if (!file_exists($path)) {
  23. // 如果runtime/pem文件夹不存在,创建文件夹
  24. if (!file_exists(root_path('runtime/pem'))) {
  25. mkdir(root_path('runtime/pem'), 0777, true);
  26. }
  27. file_put_contents($path, $info['content']);
  28. }
  29. }
  30. return $path;
  31. }
  32. }