使用ThinkPHP6中集成Acmephp实现SSL证书在线生成,并自动续签。
直接上代码1,安装Acmephp用Composer来安装Acmephp。在项目根目录下执行以下命令:SSL在线生成网址:https://ssl.goolibao.com/sslcomposer require acmephp/acmephp2,创建证书目录在config目录下创建一个acmephp.php配置文件,用于配置Acmephp。return ['storage' => ['class' => AcmePhpSslStoreFilesystemStore::class,'directory' => __DIR__.'/../public/certs',],'acme' => ['directory' => 'https://acme-v02.api.letsencrypt.org/directory','contact' => ['mailto:admin@example.com'],],];在上面的配置中,我们指定了证书存储的目录为public/certs,以及ACME服务器的地址和联系方式。4,创建SSL证书用Acmephp的API来创建SSL证书。
使用ThinkPHP6中集成Acmephp实现SSL证书在线生成,并自动续签。
直接上代码
1,安装Acmephp
用Composer来安装Acmephp。在项目根目录下执行以下命令:
SSL在线生成网址:https://ssl.goolibao.com/ssl
composer require acmephp/acmephp
2,创建证书目录
在config目录下创建一个acmephp.php配置文件,用于配置Acmephp。
return ['storage' => ['class' => AcmePhpSslStoreFilesystemStore::class,'directory' => __DIR__.'/../public/certs',],'acme' => ['directory' => 'https://acme-v02.api.letsencrypt.org/directory','contact' => ['mailto:admin@example.com'],],];
在上面的配置中,我们指定了证书存储的目录为public/certs,以及ACME服务器的地址和联系方式。
4,创建SSL证书
用Acmephp的API来创建SSL证书。控制器:
<?phpnamespace appcontroller;use AcmePhpSslPrivateKey;use AcmePhpSslCertificate;use AcmePhpCoreAcmeClient;use AcmePhpBundleAcmeDomainAuthorizationChallengeSolver;use AcmePhpBundleAcmeDomainAuthorizationChallenge;use AcmePhpBundleAcmeDomainDomainValidator;use SymfonyComponentHttpFoundationRequest;class CertController{public function create(Request $request) {$domain = $request->get('domain');$email = $request->get('email');$client = new AcmeClient($domain, $email);$solver = new AuthorizationChallengeSolver();$challenge = $client->requestAuthorization($domain);$solver->solve($challenge, $domain);$validator = new DomainValidator();$validator->validate($domain);$privateKey = new PrivateKey();$certificate = new Certificate($client->getCertificateData());$privateKey->saveToFile(__DIR__.'/../public/certs/'.$domain.'.key');$certificate->saveToFile(__DIR__.'/../public/certs/'.$domain.'.crt');return 'OK';}}
我们首先从请求参数中获取域名和电子邮件地址,然后创建一个AcmeClient对象来请求证书。接着,我们通过AuthorizationChallengeSolver来解决验证挑战,然后使用DomainValidator来验证域名。*后,我们将私钥和证书保存到public/certs目录下。
5,自动续签SSL证书
用Acmephp的API来自动续签SSL证书。
<?phpnamespace appcontroller;use AcmePhpSslPrivateKey;use AcmePhpSslCertificate;use AcmePhpCoreAcmeClient;use AcmePhpBundleAcmeDomainAuthorizationChallengeSolver;use AcmePhpBundleAcmeDomainAuthorizationChallenge;use AcmePhpBundleAcmeDomainDomainValidator;use SymfonyComponentHttpFoundationRequest;class CertController{public function renew(Request $request) {$domain = $request->get('domain');$email = $request->get('email');$client = new AcmeClient($domain, $email);$certificate = new Certificate(file_get_contents(__DIR__.'/../public/certs/'.$domain.'.crt'));$privateKey = new PrivateKey(file_get_contents(__DIR__.'/../public/certs/'.$domain.'.key'));$client->renewCertificate($certificate, $privateKey);$certificate->saveToFile(__DIR__.'/../public/certs/'.$domain.'.crt');$privateKey->saveToFile(__DIR__.'/../public/certs/'.$domain.'.key');return 'OK';}}
思路:我们首先从请求参数中获取域名和电子邮件地址,然后创建一个AcmeClient对象来请求证书。接着,我们加载之前生成的证书和私钥文件,然后调用renewCertificate方法来自动续签证书。*后,我们将新的证书和私钥保存到public/certs目录下。
★友情提示: ①如果您购买的资源链接失效或者脚本过期,请及时联系客服:QQ/微信:124686488; ②如果你购买的资源有操作指导视频的,请务必先看视频,再操作! ③源码类本站仅保证其完整性,并未做深度实测,下载后自行研究,请支持正版! ④重要:下载链接失效或者打不开的记得在评论区留言或者直接联系客服喔! ⑤本站内容如有侵权,请提供书面反馈至:cnzxt12340@163.com

相关文章
- 视频号无限私信机,号称日发十万条精准引流【引流脚本+使用教程】
- 提供抖音黑科技免费下载使用,外面镭射云端商城*低收费1598
- 喜番短剧24小时智能全自动G机掘金助手,单机一天20+【G机脚本+使用教程】
- 音柚漂流瓶智能G机聊天,号称单窗口日收益40-70+【智能脚本+使用教程】
- 抖音黑科技源头,抖音云端商城怎么使用更有效果?
- 抖音虚拟直播助手,无限多开+虚拟定位+文档助手【年卡软件+使用教程】
- 零基础网盘拉新秘籍Canva + 影刀 RPA 自动化内容矩阵实战日更 7 天笔记仅需 1 小时【飞书文档教程】
- soul突破送礼限制无限私信机,解放双手单天打粉500+【引流脚本+使用教程】
- sol和doge钱包助记词碰撞器,单窗口月利润可达5000+可无限放大【协议脚本+使用教程】
- 瞬火美女视频制作软件,AI智能一键换脸自动生成【永久软件+使用教程】