此篇我们开始调用接口,我们在插件类中新定义一个方法,起名为send_post,在方法中我们通过系统配置获取接口调用地址。
百度给的例子中使用了php的CURL,更高级的使用方法可以学习PHP_cURL初始化和执行方法
下面我们结合一下百度站长提供的代码。
/** * 发送数据 * @param $url 准备发送的url * @param $options 系统配置 */ public static function send_post($url, $options){ //获取API $api = $options->plugin('BaiduSubmitTest')->api; //准备数据 if( is_array($url) ){ $urls = $url; }else{ $urls = array($url); } $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); //记录日志 file_put_contents('/tmp/send_log', date('H:i:s') . $result . "\n"); }
由于我们还没有建立日志系统,所以我们将日志先写入文件,先看效果吧!
返回值:
{"remain":48,"success":1}
Good!看来没有什么问题!不过为了保险起见,我还是用typecho自带的http类重写了此方法。
public static function send_post($url, $options){ //获取API $api = $options->plugin('BaiduSubmitTest')->api; //准备数据 if( is_array($url) ){ $urls = $url; }else{ $urls = array($url); } //为了保证成功调用,老高先做了判断 if (false == Typecho_Http_Client::get()) { throw new Typecho_Plugin_Exception(_t('对不起, 您的主机不支持 php-curl 扩展而且没有打开 allow_url_fopen 功能, 无法正常使用此功能')); } //发送请求 $http = Typecho_Http_Client::get(); $http->setData(implode("\n", $urls)); $http->setHeader('Content-Type','text/plain'); $result = $http->send($api); //记录日志 file_put_contents('/tmp/send_log', date('H:i:s') . $result . "\n"); } }
现在我们的插件基本能够运行了,但是在结构上还可以进一步优化!

本篇文章给大家分享40+ 个atom常用插件,并附上在atom中安装插件的方法,希望对大家有所帮助!

本篇文章给大家整理分享 6 个 Vue3 开发必备的 VSCode 插件,可以直接用过 VSCode 的插件中心直接安装使用,希望对大家有所帮助!

这篇文章主要介绍了这么多年来我在使用 VSCode 过程中用到的一些不错的插件。这些VSCode插件,帮你打造地表最强IDE!

本篇文章给大家总结了23个各种功能的VSCode 插件,可以帮助开发者提高开发效率和美观性,希望对大家有所帮助!

如何利用PHP和Typecho构建社交媒体网站随着社交媒体的兴起,越来越多的人希望拥有一个属于自己的社交媒体网站。而搭建一个社交媒体网站的其中一种方式是使用PHP和Typecho这两个开源工具。PHP是一种被广泛应用于Web开发的脚本语言,而Typecho是一个小巧、易用、安全的博客系统,不仅功能强大,而且可以方便的进行二次开发。下面我将介绍如何使用PHP和

如何使用PHP和Typecho打造多语言支持的网站导语:随着全球化的发展,构建一个多语言支持的网站逐渐成为企业和个人所追求的目标。而PHP作为一种流行的编程语言,结合Typecho这一优秀的PHP开源博客程序,可以轻松实现多语言网站的搭建。本文将介绍如何使用PHP和Typecho来打造一个多语言支持的网站,并提供相关的代码示例。一、安装和配置Typecho首

提起Monica,你会想到什么?是老友记里的主角之一Monica·Geller,一个热心肠的女主人形象;还是心跳文学部里的疯疯癫癫的Monika?或者,最近爆火的Chrome插件——Monica。它的功能实在是太强大了,用完一次保你爱不释手。毕竟,搭载了ChatGPT的网页助手,能是俗物吗?Monica功能大赏首先明确一点,Monica是ChatGPT在网页上的应用,换句话说,Monica就是靠着ChatGPTAPI的强大功能才厉害。而仔细看看Chrome商店中的介绍,我们就会发现Monica真


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version
