ding-live/ding-php

v0.11.1 2024-08-28 00:25 UTC

This package is auto-updated.

Last update: 2024-10-03 00:28:54 UTC


README

Ding PHP 库提供了从 PHP 语言编写的应用程序中方便访问 Ding API 的功能。

SDK 安装

Composer

composer require "ding/sdk"

SDK 示例用法

SDK 示例用法

发送代码

将 OTP 代码发送到用户的手机号码。

declare(strict_types=1);

require 'vendor/autoload.php';

use Ding\DingSDK;
use Ding\DingSDK\Models\Shared;

$security = new Shared\Security();
$security->apiKey = 'YOUR_API_KEY';

$sdk = DingSDK\Ding::builder()->setSecurity($security)->build();

try {
    $request = new Shared\CreateAuthenticationRequest(
        customerUuid: 'c9f826e0-deca-41ec-871f-ecd6e8efeb46',
        phoneNumber: '+1234567890',
        appRealm: '<value>',
        appVersion: '<value>',
        callbackUrl: 'https://thin-television.name',
        correlationId: '<value>',
        deviceId: '<value>',
        deviceModel: '<value>',
        deviceType: Shared\DeviceType::Android,
        ip: '176.157.112.67',
        isReturningUser: false,
        osVersion: '<value>',
        templateId: '<value>',
    );
    $response = $sdk->otp->createAuthentication($request);

    if ($response->createAuthenticationResponse !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

检查代码

检查用户输入的代码是否有效。

declare(strict_types=1);

require 'vendor/autoload.php';

use Ding\DingSDK;
use Ding\DingSDK\Models\Shared;

$security = new Shared\Security();
$security->apiKey = 'YOUR_API_KEY';

$sdk = DingSDK\Ding::builder()->setSecurity($security)->build();

try {
    $request = new Shared\CreateCheckRequest(
        authenticationUuid: 'e0e7b0e9-739d-424b-922f-1c2cb48ab077',
        checkCode: '123456',
        customerUuid: '8f1196d5-806e-4b71-9b24-5f96ec052808',
    );
    $response = $sdk->otp->check($request);

    if ($response->createCheckResponse !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

执行重试

如果用户未收到代码,则执行重试。

declare(strict_types=1);

require 'vendor/autoload.php';

use Ding\DingSDK;
use Ding\DingSDK\Models\Shared;

$security = new Shared\Security();
$security->apiKey = 'YOUR_API_KEY';

$sdk = DingSDK\Ding::builder()->setSecurity($security)->build();

try {
    $request = new Shared\RetryAuthenticationRequest(
        authenticationUuid: 'a74ee547-564d-487a-91df-37fb25413a91',
        customerUuid: '3c8b3a46-881e-4cdd-93a6-f7f238bf020a',
    );
    $response = $sdk->otp->retry($request);

    if ($response->retryAuthenticationResponse !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

可用资源和操作

Otp

查找

  • lookup - 执行电话号码查找

SDK 安装

Composer

composer require "ding-live/ding-php"

服务器选择

服务器选择

通过索引选择服务器

您可以通过在初始化 SDK 客户端实例时传递一个服务器索引到 server_idx: int 可选参数来全局覆盖默认服务器。然后,所选服务器将被用作使用它的操作的默认服务器。此表列出了与可用服务器关联的索引

按客户端覆盖服务器 URL

默认服务器还可以通过在初始化 SDK 客户端实例时传递一个 URL 到 server_url: str 可选参数来全局覆盖。例如

开发

成熟度

此 SDK 处于测试阶段,版本之间可能存在破坏性更改,而没有进行主要版本更新。因此,我们建议将使用固定到特定包版本。这样,您可以每次安装相同的版本,除非您有意寻找最新版本,否则不会发生破坏性更改。

贡献

虽然我们重视对 SDK 的开源贡献,但此库是通过程序生成的。请随意打开一个 PR 或一个 Github 问题作为概念证明,我们将尽力将其包括在未来版本中!