导语
Typecho的评论模块,可以通知邮件,也可以使用饭碗警告通知。
什么是饭碗警告 (Fw: Alert) ?
饭碗警告 (Fw: Alert) 是一个警告转发系统,该系统可以通过 webhook 或邮件来触发,再将数据经过处理后通过多种方式通知到用户。
计费方式
类型 | 价格 | 适用于 |
---|---|---|
邮箱 | 0.02元/次 | 提醒及时性要求一般 |
短信 | 0.1元/次 | 提醒及时性要求较高 |
电话 | 0.2元/次 | 提醒及时性要求极高 |
Telegram | 免费 | 提醒及时性要求较高 |
「饭碗警告」应用 | 免费 | 提醒及时性要求较高 |
我选择的是「饭碗警告」应用,苹果手机下载,然后打开通知即可。
部署
https://github.com/YianAndCode/Comment2Fanwan,从github上下载源码,解压重名为Comment2Fanwan
,将文件上传到网站目录/usr/plugins
,然后在后台开启插件。
使用
注册饭碗警告帐号,然后在右上角下拉菜单联系方式中,新增联系方式,添加饭碗应用,然后按照引导绑定即可。
在饭碗警告,左下角创建转发规则,填写规则名称、触发方式webhook、通知正文、联系方式等,其中通知正文有固定的模版,填写插件固定的模版内容即可。
{{ author }} 于 {{ created_at }} 在您的文章<a href="{{ url }}">《{{ title }}》</a>发表了评论:
{{ comment }}
转发规则创建完毕后,你会得到一个webhook链接,将这个链接填写到插件配置中。
配置完毕,可以进入测试阶段了。
排错
在测试过程中发现,程序没有走通,但是通过webhook?message=11
的方式测试,发现转发规则是生效的。所以推测是代码的问题。
重写fw
函数即可。
public static function fw($comment, $post){
$options = Typecho_Widget::widget('Widget_Options');
$url = $options->plugin('Comment2Fanwan')->webhook;
$postdata = json_encode(
[
'title' => $post->title,
'comment' => $comment['text'],
'author' => $comment['author'],
'created_at' => date('Y-m-d H:i:s', $comment['created']),
'url' => $post->permalink,
],
JSON_UNESCAPED_UNICODE
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_HTTPHEADER,
[
'Content-Type: application/json',
]
);
$result = curl_exec($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
if($curl_info['http_code'] == 200){
return $comment;;
}
return $comment;
}
本文作者:Fly
版权声明:白嫖注明出处