当前位置: 首页 > news >正文

PHP之 实现https ssl证书到期提醒,通过企微发送消息

参考文章
https://blog.51cto.com/17099933344/1935194
https://blog.csdn.net/m0_37346206/article/details/127333463
https://www.cnblogs.com/tk-bolg/p/18108106

使用的企微接口
https://qyapi.weixin.qq.com/cgi-bin/message/send
在这里插入图片描述

查询 ssl证书到期时间

 // ssl证书即将到期提醒
public function ssl_ts(){$domain_all = ['www.ylhdad.com',];$tz = false;foreach ($domain_all as $v){$cert_info = $this->get_cert_info($v);$validTo_time_t = $cert_info['validTo_time_t'];$validTo_time_d = date('Y-m-d H:i:s', $validTo_time_t);   // 过期时间// 计算剩余天数$xc_time = intval( ( $validTo_time_t - time() ) / (60*60*24)  );// if($xc_time > 80){if($xc_time <= 3){$tz=true;break;}}// if($xc_time <= 3){if($tz){// 替换为你的证书文件路径// $certificatePath = '/www/server/panel/vhost/cert/ylhdad.com/privkey.pem';$data = ["touser"=> "ZhuoZhuoTaoHuaYao|123",// "touser"=> "ZhuoZhuoTaoHuaYao","msgtype"=> "text","agentid"=> 1000002,"text"=> ["content"=> "ssl证书即将过期,请及时更新。"// "content"=> "你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>,聪明避开排队。"],"safe"=> 0,"enable_id_trans"=> 0,"enable_duplicate_check"=> 0,"duplicate_check_interval"=> 1800];$qwechat = new Qwechat('ww1', 'k1BuIwtk7p2pdem');$token = $qwechat->getAccessToken();$api = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=".$token;   // 正式域名$response = $this->post($api, json_encode($data)); Log::info('ssl证书过期,提醒成功'  . json_encode($response) );// var_dump('请求返回');// var_dump($response);}Log::info('没有即将ssl证书过期,执行成功' );}// 得到ssl证书信息
public function get_cert_info($domain){$context = stream_context_create(['ssl' => ['capture_peer_cert' => true,'capture_peer_cert_chain' => true,],]);$client = stream_socket_client("ssl://".$domain.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);if($client==false) {return false;}$params = stream_context_get_params($client);$cert = $params['options']['ssl']['peer_certificate'];$cert_info = openssl_x509_parse($cert);return $cert_info;
}//请求
public function post($url, $data) {$headers = [// "Authorization: " . $authorization,"Accept: application/json","Content-Type:application/json",];$ch = curl_init();curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置HTTP头curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);$res = curl_exec($ch);//         $error = curl_error($ch); // var_dump($error);exit(0);curl_close($ch);return json_decode($res, true);
}

http://www.mrgr.cn/news/36710.html

相关文章:

  • 江协科技STM32学习- P19 TIM编码器接口
  • 22.4k star,好用、强大的链路监控软件,skywalking
  • Appium跨平台测试实战:从Android到iOS
  • ai智能抠图有哪些?我只告诉你这些
  • 前端框架对比与选择
  • 算法葫芦书(笔试面试)
  • python数据分析在进行时间序列分析时,如何选择合适的频率进行重采样?
  • AI篮球投篮分析与投篮姿势的机器学习应用
  • 详解 Spring Boot 的 RedisAutoConfiguration 配置
  • 塑封芯片多大才需要点胶加固保护?
  • 我的领域-关怀三次元成长的二次元虚拟陪伴 | OPENAIGC开发者大赛高校组AI创作力奖
  • 基于Ubuntu 20.04 LTS上部署MicroK8s(最小生产的 Kubernetes)
  • 【Redis技术进阶之路】「原理分析系列开篇」揭秘分析客户端和服务端网络通信交互实现(服务端篇 - 命令执行过程)
  • Python基础(4)- 运算符
  • 何为supervisorctl以及我们如何使用它
  • 介绍篇| 爬虫工具介绍
  • 图论系列(dfs岛屿) 9/26
  • 【含文档】基于Springboot+Vue的高校教务管理系统(含源码+数据库+lw)
  • 在Vue.js中,你可以使用Element UI的el-input组件结合计算属性来实现模糊查询
  • Linux这几个冷门的命令,简直不要太好用!