/** * QQ群推送功能 * 当WordPress内容更新时,自动推送到配置的QQ群 */ // 防止直接访问 if (!defined('ABSPATH')) { die; } /** * 初始化QQ推送功能 */ function zib_qq_push_init() { // 添加文章发布和更新时的钩子 add_action('publish_post', 'zib_handle_post_update', 10, 1); add_action('publish_page', 'zib_handle_post_update', 10, 1); } add_action('init', 'zib_qq_push_init'); /** * 添加QQ推送设置选项 */ function zib_qq_push_options($options) { $options[] = array( 'id' => 'qq_push_options', 'title' => 'QQ群推送设置', 'icon' => 'fa fa-qq', 'fields' => array( array( 'id' => 'qq_push_enable', 'type' => 'switcher', 'title' => '启用QQ群推送', 'default' => false, ), array( 'id' => 'qq_push_api_url', 'type' => 'text', 'title' => 'QQ机器人API地址', 'desc' => '输入QQ机器人API接口地址', 'default' => '', ), array( 'id' => 'qq_push_group_id', 'type' => 'text', 'title' => 'QQ群号', 'desc' => '输入需要推送消息的QQ群号', 'default' => '', ), array( 'id' => 'qq_push_template', 'type' => 'textarea', 'title' => '推送消息模板', 'desc' => '可用变量:{title}, {excerpt}, {url}, {author}', 'default' => '新文章发布:{title}\n作者:{author}\n预览:{excerpt}\n链接:{url}', ), ) ); return $options; } add_filter('zib_options', 'zib_qq_push_options'); /** * 处理文章更新事件 */ function zib_handle_post_update($post_id) { // 检查是否启用了推送功能 if (!_pz('qq_push_enable')) { return; } // 获取文章信息 $post = get_post($post_id); // 如果不是公开发布的文章,不推送 if ($post->post_status !== 'publish') { return; } // 获取文章信息 $title = $post->post_title; $excerpt = wp_trim_words($post->post_content, 100); $url = get_permalink($post_id); $author = get_the_author_meta('display_name', $post->post_author); // 获取消息模板 $template = _pz('qq_push_template'); // 替换模板变量 $message = str_replace( array('{title}', '{excerpt}', '{url}', '{author}'), array($title, $excerpt, $url, $author), $template ); // 推送消息 zib_push_to_qq_group($message); } /** * 推送消息到QQ群 */ function zib_push_to_qq_group($message) { $api_url = _pz('qq_push_api_url'); $group_id = _pz('qq_push_group_id'); if (empty($api_url) || empty($group_id)) { return false; } // 准备请求数据 $data = array( 'group_id' => $group_id, 'message' => $message, ); // 发送请求 $response = wp_remote_post($api_url, array( 'body' => json_encode($data), 'headers' => array('Content-Type' => 'application/json'), 'timeout' => 10, )); // 检查响应 if (is_wp_error($response)) { error_log('QQ群推送失败:' . $response->get_error_message()); return false; } $body = wp_remote_retrieve_body($response); $result = json_decode($body, true); // 记录推送结果 if (!$result || !isset($result['status']) || $result['status'] !== 'ok') { error_log('QQ群推送失败:' . print_r($result, true)); return false; } return true; } [Xiuren秀人网]2022.08.18 NO.5454 陈怡曼 红色紧身吊带连衣裙加黑丝美腿性感私房写真集-秀人网论坛-免费套图-看套图
[Xiuren秀人网]2022.08.18 NO.5454 陈怡曼 红色紧身吊带连衣裙加黑丝美腿性感私房写真集-秀人网论坛-免费套图-看套图