Typecho 使用 CommentToDingtalk (评论推送至钉钉)插件遇到的问题 作者: Chuwen 时间: 2020-04-06 分类: PHP 3 条评论 > CommentToDingtalk 项目地址:https://github.com/MoLeft/CommentToDingtalk # 运行报以下错误 ``` Using $this when not in object context Error: Using $this when not in object context in //nowtime.cc/usr/plugins/CommentToDingtalk/Plugin.php:123 Stack trace: #0 /nowtime.cc/usr/plugins/CommentToDingtalk/Plugin.php(87): CommentToDingtalk_Plugin::getWebhook('https://oapi.di...', 'SECca000000000...') #1 /nowtime.cc/var/Typecho/Plugin.php(489): CommentToDingtalk_Plugin::send(Object(Widget_Feedback), NULL) #2 /nowtime.cc/var/Widget/Feedback.php(146): Typecho_Plugin->__call('Widget_Feedback...', Array) #3 /nowtime.cc/var/Widget/Feedback.php(336): Widget_Feedback->comment() #4 /nowtime.cc/var/Typecho/Router.php(138): Widget_Feedback->action() #5 /nowtime.cc/index.php(30): Typecho_Router::dispatch() #6 {main} ``` # 原因 在静态方法中调用非静态方法,导致其报错 # 解决方法 将 **静态方法** 中调用 **非静态方法** `$this->` 改成 `(new self())->` 即可 以下是修改后的 `Plugin.php`,你可以直接复制以下代码进行替换: ``` finishComment = array('CommentToDingtalk_Plugin', 'send'); return '插件已激活,请设置相关信息'; } /* 禁用插件方法 */ public static function deactivate() { return '插件已禁用'; } /* 插件配置方法 */ public static function config(Typecho_Widget_Helper_Form $form) { $webhook = new Typecho_Widget_Helper_Form_Element_Text('webhook', null, '', 'Webhook地址', '请将钉钉中的webhook地址填到此处'); $secret = new Typecho_Widget_Helper_Form_Element_Text('secret', null, '', 'Secret密钥', '请将钉钉中的Secret密钥填到此处'); $form->addInput($webhook); $form->addInput($secret); } /** * 个人用户的配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form * @return void */ public static function personalConfig(Typecho_Widget_Helper_Form $form) { } /* 插件实现方法 */ public static function render() { } /* 推送通知方法 */ public static function send($post) { //获取系统配置 $options = Helper::options(); //判断是否配置webhook地址 if (is_null($options->plugin('CommentToDingtalk')->webhook)) { throw new Typecho_Plugin_Exception(_t('Webhook地址未配置')); } //判断是否配置secret密钥 if (is_null($options->plugin('CommentToDingtalk')->secret)) { throw new Typecho_Plugin_Exception(_t('Secret密钥未配置')); } $webhook = $options->plugin('CommentToDingtalk')->webhook; $secret = $options->plugin('CommentToDingtalk')->secret; $text = "###您收到了一条新评论\n文章标题:{$post->title}\n评论作者:{$post->author}\n评论内容:{$post->text}"; $data = [ 'msgtype' => 'actionCard', 'actionCard' => [ 'title' => '您收到了一条新评论', 'text' => $text, 'btnOrientation' => 1, 'hideAvatar' => 0, 'singleTitle' => '查看详情', 'singleURL' =>$post->permalink ] ]; //我修改了这里 //我修改了这里 //我修改了这里 $response = (new self())->request((new self())->getWebhook($webhook,$secret), json_encode($data)); //我修改了这里 //我修改了这里 //我修改了这里 if($response['errcode'] !== 0){ //发送失败,记录日志 $log = @file_get_contents('./error.log'); file_put_contents('./error.log','['.date("Y-m-d H:i:s").']'.$response['errmsg']); } } /* Curl请求精简版 */ private function request($url, $postData) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8')); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 线下环境不用开启curl证书验证, 未调通情况可尝试添加该代码 // curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); // curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); $data = curl_exec($ch); curl_close($ch); return json_decode($data, true); } /* webhook地址 */ private function getWebhook($webhook, $secret) { list($msec, $sec) = explode(' ', microtime()); $timestamp = (float) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); $sign = $this->signSecret($timestamp, $secret); $webhook_url = "{$webhook}×tamp={$timestamp}&sign={$sign}"; return $webhook_url; } /* 计算签名 */ private function signSecret($timestamp,$secret){ $stringToSign = $timestamp."\n".$secret; return urlencode(base64_encode(hash_hmac('sha256', $stringToSign, $secret, true))); } } ```
WordPress 设置私人站点,不登陆无法访问 作者: Chuwen 时间: 2020-04-06 分类: PHP 7 条评论 # 前言 我专门搭建了属于 **私人的博客**,不想给没有拥有该站账号的人访问(或许到了某一天我会悄悄地开放) # 开始 打开 `/wp-blog-header.php` 文件,在 `require_once __DIR__ . '/wp-load.php';` 这一行后面加入以下代码: ``` 很抱歉,这是我的私人站点,我不想给任何人查看本站的内容!除非你拥有本站账号如果你要登录请点击:登录"); } // Set up the WordPress query. wp(); // Load the theme template. require_once ABSPATH . WPINC . '/template-loader.php'; } ``` # 效果 未登录显示的页面: ![未登录显示的页面][1] 登录了显示的页面: ![登录了显示的页面][2] [1]: https://cdn.nowtime.cc/2020/04/06/231126751.png [2]: https://cdn.nowtime.cc/2020/04/06/2400331521.png
Nginx/Tengine 添加模块(非覆盖安装) 作者: Chuwen 时间: 2020-04-06 分类: Nginx 评论 > 假设我要添加 [nginx-http-concat][1] 这个模块 # 查看原来的编译参数 ``` nginx -V ``` 返回结果 ``` root@Chuwen:~/tengine-2.3.2# nginx -V Tengine version: Tengine/2.3.2 nginx version: nginx/1.17.3 built by gcc 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) built with OpenSSL 1.1.1b 26 Feb 2019 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module ``` # 添加需要的模块 ``` --add-module=/root/nginx-http-concat-master ``` # 重新编译配置 > 加上之前的参数与新增的参数 ``` # 进入源码目录,假设你没有删除 cd /www/server/nginx ./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/root/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module \ --add-module=/root/nginx-http-concat-master # 添加模块 ``` # 执行编译,但不安装 ``` make ``` # 查看下编译好的二进制文件 ``` ldd objs/nginx |grep lua ``` # 替换 nginx 二进制文件 ``` mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_back_2020.04.06 cp ./objs/nginx /www/server/nginx/sbin/nginx ``` --- 参考自:https://blog.linuxhub.cn/?p=3220 [1]: https://github.com/alibaba/nginx-http-concat
(2019年8月) 第44次《中国互联网络发展状况统计报告》 | 中国(电信、移动、联通等...) IPv4/IPv6 持有量 作者: Chuwen 时间: 2020-03-31 分类: 其他分类 评论 # 第44次《中国互联网络发展状况统计报告》 > 参考数据:[第44次《中国互联网络发展状况统计报告》][1] > 数据来源:[中国互联网络信息中心][2] > > 该报告没有写出 *中国主要骨干网络国际出口带宽数* > 以下是为便于读者阅读,摘要的部分数据,具体以 [第44次《中国互联网络发展状况统计报告》][1] 为准 # 摘要 ## 基础数据 > 仅为粗略摘要,可能有摘抄错误的地方,详细请查阅 [第44次《中国互联网络发展状况统计报告》][3] - 截至2019年6月,我国网民规模达 8.54亿,较2018年底增长 2598万,互联网普及率达 61.2%,较 2018年底提升1.6个百分点。 - 截至2019年6月,我国手机网民规模达8.47亿,较2018年底增长2984万,我国网民使用手机上网的比例达99.1%,较2018年底提升0.5个百分点。 - 截至2019年6月,我国农村网民规模为2.25亿,占网民整体的26.3%,较2018年底增长305万;城镇网民规模为6.30亿,占网民整体的73.7%,较2018年底增长2293万。 - 截至2019年6月,我国网民使用手机上网的比例达99.1%;使用电视上网的比例为33.1%;使用台式电脑上网、笔记本电脑上网、平板电脑上网的比例分别为46.2%、36.1%和28.3%。 - 截至2019年6月,我国IPv6地址数量为50286块/32,较2018年底增长14.3%。 - 截至2019年6月,我国域名总数为4800万个;其中,“.CN”域名总数为2185万个,较2018年底增长2.9%,占我国域名总数的45.5%。 - 截至2019年6月,我国即时通信用户规模达8.25亿,较2018年底增长3298万,占网民整体的96.5%;手机即时通信用户规模达8.21亿,较2018年底增长4040万,占手机网民的96.9%。 - 截至2019年6月,我国网络新闻用户规模达6.86亿,较2018年底增长1114万,占网民整体的80.3%;手机网络新闻用户规模达6.60亿,较2018年底增长734万,占手机网民的78.0%。 - 截至2019年6月,我国网络购物用户规模达6.39亿,较2018年底增长2871万,占网民整体的74.8%;手机网络购物用户规模达6.22亿,较2018年底增长2989万,占手机网民的73.4%。 - 截至2019年6月,我国网上外卖用户规模达4.21亿,较2018年底增长1516万,占网民整体的49.3%;手机网上外卖用户规模达4.17亿,较2018年底增长2037万,占手机网民的49.3%。 - 截至2019年6月,我国网络支付用户规模达6.33亿,较2018年底增长3265万,占网民整体的74.1%;手机网络支付用户规模达6.21亿,较2018年底增长3788万,占手机网民的73.4%。 - 截至2019年6月,我国网络视频用户2规模达7.59亿,较2018年底增长3391万,占网民整体的88.8%;其中,短视频用户规模为6.48亿,占网民整体的75.8%。 - 截至2019年6月,我国网约出租车用户规模达3.37亿,较2018年底增长670万,占网民整体的39.4%;我国网约专车或快车用户规模达3.39亿,较2018年底增长633万,占网民整体的39.7%。 - 截至2019年6月,我国在线政务服务用户规模达5.09亿,占网民整体的59.6%。 ## 趋势特点 > 部分摘要,详细请查阅 [第44次《中国互联网络发展状况统计报告》][4] **IPv6 地址数量全球第一,“.CN”域名数量持续增长** 截至2019年6月,我国 IPv6地址 数量为 `50286块 / 32`,较2018年底增长14.3%,已跃居全球第一位。我国IPv6规模部署不断加速,IPv6 活跃用户数达 1.3 亿,基础电信企业已分配IPv6地址用户数 12.07亿3;域名总数为 4800万个,其中“.CN”域名总数为 2185万个,较2018年底增长 2.9%,占我国域名总数的 45.5%。2019年6月,首届“中国互联网基础资源大会2019”在京召开,大会围绕网络强国战略大局,回顾中国互联网二十五周年发展历程,聚焦互联网基础资源行业发展,展示前沿创新技术,搭建行业交流平台,推动行业规范有序发展。 --- # 互联网基础资源 *(摘要)* ## (1)基础资源概述 > 截至 2019年6月,我国 IPv4 地址数量为 38598万个,IPv6 地址数量为 `50286块/32`。我国域名总数为 4800万个。其中,“.CN”域名总数为2185万个,占我国域名总数的 45.5%。 ### 2018.12- 2019.6 互联网基础资源对比 > **IPv4* ** 2018年12月服2019年6月数据均含港、澳、台地区。 > **IPv6* ** 2018年12月服2019年6月数据均含港、澳、台地区。 > **域名 - 2018年12月* ** 2018年12月统计数据不含新通用顶级域名(New gTLD)数量。 > **域名 - 2019年6月* ** 2019年6月统计数据含新通用顶级域名(NewgTLD)数量。 | |2018年12月 | 2019年6月 | 半年增长量 | 半年增长率 | | -----: | -----: | ----: | ----: | ----: | | IPv4* (个) | 385,843 968 | 385,979,136 | 135,168 | 0.04% | | IPv6* (块/32) | 43,985| 50,286| 6,301| 14.3%| | 域名 (个)| 37,927,527*| 48,001,471*|--|--| | 其中.CN域名 (个)| 21 ,243,478| 21 ,851 ,990| 608,512| 2.9%| --- ## 中国各地区 IPv4 地址数量 |地区|地址量|折合数| |:---:|:---:|:---:| |中国大陆|338,991,360|20A + 52B + 153C| |中国台湾|35,678,976|2A + 32B + 107C| |中国香港|10,972,672|167B + 110C| |中国澳门|336,128|5B + 32C| --- ## 大陆地区按分配单位 IPv4 地址数 |单位名称|地址量|折合数| |:---:|:---:|:---:| |中国电信集团公司|125,763,328|7A+126B+255C| |中国联合网络通信有限公司|69,866,752*|4A+42B+21C| |CNNIC IP 地址分配联盟|61,960,448*|3A+177B+113C| |中国移动通信集团公司|35,294,208|2A+26B+140C| |中国教育和科研计算机网|16,649,728|254B+14C| |中移铁通有限公司|15,796,224*|241B+8C| |其它|13,660,672|208A+114C| |合计|338,991,360|20A+52B+153C| ![大陆地区按分配单位 IPv4 地址数 - nowtime.cc 现在网][6] --- ## 中国大陆地区按分配单位 IPv6 地址数 |单位名称|地址量| |:---:|:---:| |中国电信集团公司|16,387| |CNNIC IP 地址分配联盟|14,025*| |中国教育和科研计算机网|6,162| |中国联合网络通信有限公司|4,097| |中国移动通信集团公司|4,097| |中移铁通有限公司|2,049*| |中国科技网|17*| |其它|481| |合计|47,315| ![中国大陆地区按分配单位 IPv6 地址数][7] --- > ### 以往报告: > - [(2019年2月)中国主要骨干网络国际出口带宽数 | 第43次《中国互联网络发展状况统计报告》][8] > - [(2018年8月)中国主要骨干网络国际出口带宽数 | 第42次《中国互联网络发展状况统计报告》][9] [1]: http://www.cac.gov.cn/pdf/20190829/44.pdf [2]: http://www.cnnic.cn [3]: http://www.cac.gov.cn/pdf/20190829/44.pdf [4]: http://www.cac.gov.cn/pdf/20190829/44.pdf [5]: https://cdn.nowtime.cc/2020/03/31/2504737781.png [6]: https://cdn.nowtime.cc/2020/03/31/466394716.png [7]: https://cdn.nowtime.cc/2020/03/31/276695503.png [8]: https://nowtime.cc/news/757.html [9]: https://nowtime.cc/news/556.html
Ajax 跨域请求 Cookie 无法携带/保存的解决办法 作者: Chuwen 时间: 2020-03-17 分类: JavaScript 评论 # 服务器端设置 ### Nginx 端设置: > `http://192.168.3.4` 是允许跨域的域名,80和443 可以不用加端口号,除此之外的端口号要加 ``` add_header 'Access-Control-Allow-Origin' 'http://192.168.3.4'; add_header 'Access-Control-Allow-Credentials' 'true'; ``` ### PHP 端设置: > 解释同上 ``` header("Access-Control-Allow-Origin: http://192.168.3.4"); header("Access-Control-Allow-Credentials: true"); ``` # 前端设置 ### jQuery Ajax 请求: ``` $.ajax({ url: 'http://nas/api/v2/sync/maindata', xhrFields: { // 允许携带证书 withCredentials: true }, dataType: 'json', success: function (res) { console.log("请求结果:"+res); } }); ```