定制 2indexninja-hub/2index-ninja-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

2indexninja-hub/2index-ninja-sdk

Composer 安装命令:

composer require 2indexninja-hub/2index-ninja-sdk

包简介

A modern PHP SDK for the 2index.ninja API

README 文档

README

Latest Version on Packagist Total Downloads

The official PHP SDK for the 2index.ninja API. A modern, fluent, and fully-typed client for seamless integration into your PHP projects.

Why 2Index.Ninja?

Our service provides powerful tools to manage the indexing of your websites in search engines.

🚀 Google Indexing API

Our service supports the Google Indexing API, allowing you to quickly and safely manage the indexing of your site's pages in the Google search engine. With our help, you can efficiently increase the number of indexed pages on your site, regardless of their quantity.

⚡️ IndexNow

The IndexNow protocol works similarly to the Google Indexing API but extends its reach. While the Indexing API is specific to Google, IndexNow works equally well with search engines like Yandex and Bing. This method is also fast, safe, and efficient.

🔗 Backlinks Indexing

External links are one of the most effective ways to boost your site's visibility in search engines. However, not all backlinks are indexed quickly, and sometimes it can take a very long time. Our service can help speed up the indexing of backlinks, ensuring your SEO efforts pay off sooner. Remember, the success of indexing also depends on the quality of the donor site where the link is placed.

SDK Features

  • A simple, object-oriented interface.
  • Strictly-typed models (DTOs) for all API responses, enabling autocompletion in your IDE and type safety.
  • Robust error handling with custom exceptions: ApiException and NetworkException.
  • "Batteries-included" with a built-in Guzzle HTTP client for zero-config, out-of-the-box usage.
  • Fully documented code with PHPDoc.

Installation

You can install the package via Composer:

composer require 2indexninja-hub/2index-ninja-sdk

Quick Start

To get started, you'll need your API_TOKEN from your 2index.ninja account.

<?php

require 'vendor/autoload.php';

use TwoIndexNinja\Sdk\Client;

$accessToken = 'YOUR_API_ACCESS_TOKEN';
$client = new Client($accessToken);

Usage Examples

Getting Account Information

This is a basic request to check if your token is valid and to get information about your balance and plan.

try {
    $account = $client->getAccount();
    printf(
        "Email: %s, Balance: %.2f, Plan: %s\n",
        $account->email,
        $account->balance,
        $account->tariff
    );
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}

Working with Projects

Get a list of your projects:

$projects = $client->getProjects();

foreach ($projects as $project) {
    printf(
        "Project #%d: %s, Type: %s, Status: %s\n",
        $project->id,
        $project->name,
        $project->type,
        $project->status
    );
}

Create a new indexing project:

try {
    $message = $client->createIndexingProject(
        name: 'My New Website', 
        website: 'https://example.com',
        indexingSpeed: 100
    );
    echo "Success: $message\n";
} catch (\Exception $e) {
    echo "Error creating project: " . $e->getMessage();
}

Working with Links

Add links to an existing project:

$projectId = 123; // Your project's ID
$links = [
    'https://example.com/my-super-page-1',
    'https://example.com/my-super-page-2',
];

try {
    $message = $client->addLinks(
        projectId: $projectId,
        links: $links,
        google: true, // Submit to Google
        yandex: true  // Submit to Yandex
    );
    echo "Success: $message\n";
} catch (\Exception $e) {
    echo "Error adding links: " . $e->getMessage();
}

Add a sitemap:

$projectId = 123;
$sitemapUrl = 'https://example.com/sitemap.xml';

try {
    $message = $client->addSitemap(
        projectId: $projectId,
        sitemapUrl: $sitemapUrl,
        google: true,
        watch: true // Monitor sitemap for changes
    );
    echo "Success: $message\n";
} catch (\Exception $e) {
    echo "Error adding sitemap: " . $e->getMessage();
}

Error Handling

The SDK uses two exception types for predictable error handling:

  • NetworkException: For network-related issues (e.g., timeout, connection refused).
  • ApiException: For errors returned by the API (e.g., invalid data, project not found).
use TwoIndexNinja\Sdk\Exception\ApiException;
use TwoIndexNinja\Sdk\Exception\NetworkException;

$projectId = 123;
$invalidLinks = ['http://invalid-link', 'just-text'];

try {
    $client->addLinks($projectId, $invalidLinks, google: true);
} catch (ApiException $e) {
    // Handle API-level errors
    echo "API Error: " . $e->getMessage() . "\n";
    
    // You can access detailed error information
    if (!empty($e->invalidLinks)) {
        echo "Invalid links found: " . implode(', ', $e->invalidLinks) . "\n";
    }
} catch (NetworkException $e) {
    // Handle network-level errors
    echo "Network Error: " . $e->getMessage() . "\n";
}

Full Demo File

For a complete, ready-to-run example demonstrating all SDK methods, please see the /examples/basic_usage.php file in this repository.

API Reference

  • getAccount(): Account
  • getProjects(): Project[]
  • getProject(int $projectId): Project
  • createIndexingProject(string $name, ...): string
  • createIndexingCheckProject(string $name, ...): string
  • clearQueue(int $projectId): string
  • addLinks(int $projectId, ...): string
  • addLinksSimple(array|string $links, ...): AddedLinksSimpleResponse
  • getLinkSources(int $projectId): LinkSource[]
  • addSitemap(int $projectId, ...): string
  • updateSitemapWatch(int $projectId, int $sitemapId, bool $watch): bool
  • deleteSitemap(int $projectId, int $sitemapId): string

License

This project is licensed under the MIT License. See the LICENSE file for details.

2indexninja-hub/2index-ninja-sdk 适用场景与选型建议

2indexninja-hub/2index-ninja-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 2indexninja-hub/2index-ninja-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 2indexninja-hub/2index-ninja-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 2indexninja-hub/2index-ninja-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-11