nemorize / indexnow
PHP 库,用于使用 IndexNow 向搜索引擎提交网站 URL。
0.0.1
2023-07-31 17:08 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.7
README
php-indexnow 是一个用于 IndexNow API 的 PHP 库。
使用示例
composer require nemorize/indexnow
$indexnow = new \Nemorize\Indexnow\Indexnow(); $indexnow->setKey('fc1e3ad82010475381daf9846e627fdd'); $indexnow->submit('https://example.com/url-changed'); $indexnow->submit([ 'https://example.com/url-changed', 'https://example.com/url-changed-2' ]);
规范
setHost
Indexnow::setHost (string $host): void;
您可以更改 API 的主机名。如果您不设置主机名,默认主机为 api.indexnow.org
。
getHost
Indexnow::getHost (): string;
返回 API 的主机名。
setKey
Indexnow::setKey (string $key): void;
您可以更改 API 的密钥。
getKey
Indexnow::getKey (): string;
返回 API 的密钥。
setKeyLocation
Indexnow::setKeyLocation (?string $keyLocation): void;
您可以更改 API 的密钥位置。如果您想取消密钥位置,可以将它设置为 null
。
getKeyLocation
Indexnow::getKeyLocation (): ?string;
返回 API 的密钥位置。
submit
Indexnow::submit (string|array $url, array $guzzleOptions = null): void;
您可以向 API 提交一个 URL。如果您使用 $url
作为数组,它将使用 JSON 请求提交多个 URL。 $guzzleOptions
是一个用于 Guzzle 的选项数组。
异常
如果发生错误,submit
方法会抛出异常。如果 API 抛出已知的非 20x 响应代码,它将抛出以下扩展 IndexnowException
的异常。任何其他错误都将抛出 GuzzleException
。
BadRequestException
ForbiddenException
TooManyRequestsException
UnprocessableEntityException
许可
MIT 许可证