这篇文章上次修改于 772 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

2020年4月15日,机器人被腾讯回收,教程无效

今天在群里发现了一个qq机器人非公开版的,应该只属于邀请使用的机器人
Screenshot_20200411-012456_QQ.jpg
利用这个机器人我们可以做很多事情
ps:更新机器人添加方法,添加qq好友2854196399即可找到机器人

魔改插件法

开始

1.新建推送群,添加机器人为群机器人

2.开启消息推送开关,生成webhook地址并复制
Screenshot_20200411-012642_QQ_Mosaic_1_27_21.jpg

  1. 在typecho网站目录/usr/plugins下新建文件夹目录名Comment2IFTTT
    里面新建文件Plugin.php

填写Plugin.php

<?php
/**
 * 评论通知推送至 IFTTT Webhooks
 *
 * @package Comment2IFTTT
 * @author 神代綺凜
 * @version 1.0.0
 * @link https://moe.best
 */
class Comment2IFTTT_Plugin implements Typecho_Plugin_Interface
{
    /**
     * 激活插件方法,如果激活失败,直接抛出异常
     *
     * @access public
     * @return void
     * @throws Typecho_Plugin_Exception
     */
    public static function activate() {
        Typecho_Plugin::factory('Widget_Feedback')->comment = array('Comment2IFTTT_Plugin', 'whSend');
        return _t('请记得进入插件配置 IFTTT Webhooks key');
    }

    /**
     * 禁用插件方法,如果禁用失败,直接抛出异常
     *
     * @static
     * @access public
     * @return void
     * @throws Typecho_Plugin_Exception
     */
    public static function deactivate() {}

    /**
     * 获取插件配置面板
     *
     * @access public
     * @param Typecho_Widget_Helper_Form $form 配置面板
     * @return void
     */
    public static function config(Typecho_Widget_Helper_Form $form) {
        $key = new Typecho_Widget_Helper_Form_Element_Text('whKey', NULL, NULL, _t('Webhooks Key'), _t('想要获取 Webhooks key 则需要启用 <a href="https://ifttt.com/maker_webhooks" target="_blank">IFTTT 的 Webhooks 服务</a>,然后点击右上角的“Documentation”来查看'));
        $form->addInput($key->addRule('required', _t('您必须填写 Webhooks key')));

        $event = new Typecho_Widget_Helper_Form_Element_Text('evName', NULL, NULL, _t('Event Name'), _t('Webhooks 事件名'));
        $form->addInput($event->addRule('required', _t('您必须填写 Event Name')));

        $excludeBlogger = new Typecho_Widget_Helper_Form_Element_Radio('excludeBlogger',
            array(
                '1' => '是',
                '0' => '否'
            ),'1', _t('当评论者为博主时不推送'), _t('启用后,若评论者为博主,则不会推送至 IFTTT Webhooks'));
        $form->addInput($excludeBlogger);
    }

    /**
     * 个人用户的配置面板
     *
     * @access public
     * @param Typecho_Widget_Helper_Form $form
     * @return void
     */
    public static function personalConfig(Typecho_Widget_Helper_Form $form) {}

    /**
     * 推送至 IFTTT Webhooks
     *
     * @access public
     * @param array $comment 评论结构
     * @param Typecho_Widget $post 被评论的文章
     * @return $comment
     */
    public static function whSend($comment, $post) {
        $options = Typecho_Widget::widget('Widget_Options')->plugin('Comment2IFTTT');

        $whKey = $options->whKey;
        $evName = $options->evName;
        $excludeBlogger = $options->excludeBlogger;

        if ($comment['authorId'] == 1 && $excludeBlogger == '1') {
            return $comment;
        }

        
function http_post_json($url, $jsonStr)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($jsonStr)
        )
    );
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
 
    return array($httpCode, $response);
}
 
$url = "https://app.qun.qq.com/cgi-bin/api/hookrobot_send?key=fb41c74bd2dff125b3c27688671e11605e31ea69";
$jsonStr = '{"content": [ {"type":0,"data":"您的博客《 '.$post->title.' 》有新评论啦! \n '.$comment['author'].' 同学说:\n「 '.$comment['text'].' 」"}]}';
http_post_json($url, $jsonStr);
        

        return $comment;
    }
}

4.在typecho后台启用插件Comment2IFTTT
并在插件设置中填写webhook

5.大功告成
效果图
Screenshot_20200411-012302_QQ.jpg

ps:感谢网友:OkYes! 技术博客提供魔改方法和插件原作者神代綺凜