-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
123 lines (105 loc) · 4.12 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* CommentGOcqhttp
*
* @package CommentGOcqhttp
* @author CatiZ
* @version 1.0.0
* @link https://wcnmb.cn
*/
class CommentGOcqhttp_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Feedback')->finishComment = array('CommentGOcqhttp_Plugin', 'post');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @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)
{
/** 分类名称 */
$url = new Typecho_Widget_Helper_Form_Element_Text('url', NULL, NULL, _t('Go-cqhttp 地址'));
$wid = new Typecho_Widget_Helper_Form_Element_Radio('wid',array('1' => _t('私聊'),'2' => _t('群聊')),'1',_t('发送对象'));
$qid = new Typecho_Widget_Helper_Form_Element_Text('qid', NULL, NULL, _t('对象ID'));
$token = new Typecho_Widget_Helper_Form_Element_Text('token', NULL, NULL, _t('token'));
$url->description(_t('填写Go-cqhttp的HTTP地址'));
$wid->description(_t('发送到QQ号选私聊,发送到QQ群选群聊'));
$qid->description(_t('选择私聊填QQ号,选择群聊填群号'));
$token->description(_t('输入Go-Cqhttp中设置的Token'));
$form->addInput($url->addRule('required', _t('您必须填写一个正确的 URL地址')));
$form->addInput($wid->addRule('required', _t('您必须选择私聊还是群聊')));
$form->addInput($qid->addRule('required', _t('您必须填写一个正确的 QID')));
$form->addInput($token->addRule('required', _t('您必须填写一个正确的 Token')));
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 插件实现方法
*
* @access public
* @return void
*/
public static function post($comment)
{
if($comment->authorId != $comment->ownerId){
$options = Typecho_Widget::widget('Widget_Options');
$url = $options->plugin('CommentGOcqhttp')->url;
$qid = $options->plugin('CommentGOcqhttp')->qid;
$token = $options->plugin('CommentGOcqhttp')->token;
$wid = $options->plugin('CommentGOcqhttp')->wid;
// Generated by ApiPost: https://www.apipost.cn/
$ch = curl_init();
if($wid == "1"){
$url = $url."/send_private_msg";
$jd = "user_id";
}
if($wid == "2"){
$url = $url."/send_group_msg";
$jd = "group_id";
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"'.$jd.'": "'.$qid.'","message": "评论提醒\n文章:'.$comment->title.'\n'.$comment->author.':'.$comment->text.'\n查看评论:'.$comment->permalink.'"}');
$headers = array();
$headers[] = 'User-Agent: Apipost client Runtime/+https://www.apipost.cn/';
$headers[] = 'Authorization: Bearer '.$token;
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
}
return $comment;
}
}