impact-seo/killduplicate-api-php

PHP示例库,用于使用KillDuplicate API

dev-master 2021-08-26 14:00 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:25:30 UTC


README

PHP示例库,用于使用KillDuplicate API

安装此库

composer require impact-seo/killduplicate-api-php=dev-master

或下载并解压缩归档文件

设置config.php

API规范

获取您的剩余信用额

GET /api/public/credits/api_key

参数

api_key = Your Private API Key # required

返回值

credits

获取扫描成本(在运行之前)

POST /api/public/price

参数

api_key = Your Private API Key # required
text = Your Text (UTF-8 encoded) # required

扫描文本

POST /api/public/scan

参数

api_key = Your Private API Key # required
text = Your Text (UTF-8 encoded) # required
exclude_domains = Array of excluded domain names from duplicate search # optional
callback = Your callback url # required
format = desired return format # optional - possible values : json|xml - default : json 

返回即时响应

text_id : store this id for retrieving result in callback
credits : how much credits this scan has cost

回调响应

{
    "id": "82",
    "resume": "Demain, d\u00e8s l'aube, \u00e0 l'heure o\u00f9 blanchit la ca",
    "filename": null,
    "credits": "1",
    "date": "2016-04-01 16:41:43",
    "callback": "http:\/\/www.your-website.com\/vendor\/impact-seo\/killduplicate-api-php\/api_callback.php",
    "format": "json",
    "result": "long",
    "duplicate": "0",
    "dup_percentage": "0",
    "text": null,
    "exclude_domains": {},
    "search_dupes": {
        "1692": {
            "id": "1692",
            "text_id": "82",
            "phrase": "Demain, d\u00e8s l'aube, \u00e0 l'heure o\u00f9 blanchit la",
            "search_dupe_results": []
        },
        ...
    },
    "search_dupe_results": [],
    "phrases_to_check": "11",
    "phrases_checked": 11,
    "results": []
}

获取扫描

如果由于某种原因,之前的回调函数未从我们的服务器发送或未收到您的反馈,您可以强制调用以检索特定的扫描状态。要确定扫描是否完成,您必须比较phrases_to_check和phrases_checked参数。我们强烈建议您设置一个回调函数,并仅使用此调用来检索丢失的结果。

GET /api/public/scan/API_KEY/SCAN_ID

参数

API_KEY = Your Private API Key # required
SCAN_ID = Your scan id # required

返回与回调响应类似的即时响应

错误

可能的错误消息

UNKWONW_API_KEY : check your API key is corectly set in config.php ([Get your API Key](https://www.killduplicate.com/en/user/api))
UNAUTHORIZED_IP : check IP where script is run from is added to whitelist ([Chech Authorized IPs](https://www.killduplicate.com/en/user/api))
TOO_MANY_REQUESTS : only one request per second is allowed
NO_MORE_CREDITS : you dont' have enough credits to run this scan
EMPTY_TEXT_AND_URL : neither text nor url were provided
INTERNAL_ERROR : internal server error (please contact admin)
UNKNOWN_FORMAT : can only be json|xml
INVALID_CALLBACK_URL : invalid callback URL 

UTF-8编码

所有文本都必须以有效的UTF-8编码。如果您加载一些旧的Microsoft Word文档,可能会出现无效的UTF-8字符,如奇怪的引号。为了确保您有有效的UTF-8编码的文本,您可以进行检查

$validUTF8 = ! (false === mb_detect_encoding($text, 'UTF-8', true));

如果您的文本具有无效的UTF-8字符,您可以使用一些自定义函数来转换无效的编码(问题是某些编码中的某些字符可以转换为多个UTF-8字符,您必须单方面决定将其转换为哪个字符……这就是为什么您在使用API时负责进行UTF-8转换):Gist Clean UTF-8,或者您可以自己创建。

HTML实体

您的文本必须发送而不包含HTML实体(您可以使用PHP函数html_entity_decode

故障排除

确保您的回调可以通过网络访问。

对于文件权限问题(将www-data替换为您的Web服务器用户名)

chown -R www-data:www-data vendor/impact-seo/killduplicate-api-php/results
chmod -R 775 vendor/impact-seo/killduplicate-api-php/results