定制 lessotp/sdk 二次开发

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

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

lessotp/sdk

Composer 安装命令:

composer require lessotp/sdk

包简介

LessOTP Inbound Phone Authentication client SDK for PHP. WhatsApp and Telegram channels.

README 文档

README

Client for the LessOTP Inbound Phone Authentication API (PHP 7.4+).

Supported channels:

  • WhatsApp — inbound /START {code} phone verification.
  • Telegram — bot /start {code} plus the official Share phone number button.

Install

composer require lessotp/sdk

Usage

use LessOTP\Sdk\Client;
use LessOTP\Sdk\VerificationChannel;
use LessOTP\Sdk\VerifyWebhookSignature;

// production (default)
$client = new Client(getenv('LESSOTP_API_KEY'), 'production', 'https://api.lessotp.com');

// staging
$staging = new Client(
    getenv('LESSOTP_STAGING_API_KEY'),
    'staging',
    'https://api.lessotp.com'
);

// WhatsApp strict (legacy-compatible)
$result = $client->authRequest('6281234567890');
echo $result->getChannel()->value(), $result->getWaLink();

// WhatsApp frictionless (legacy-compatible)
$result = $client->authRequest();

// Telegram strict
$result = $client->requestTelegramAuth('6281234567890');
echo $result->getTelegramLink(), PHP_EOL;
echo $result->getTelegramText(), PHP_EOL;

// Telegram frictionless
$result = $client->requestAuth(VerificationChannel::telegram());

// per-call override
$result = $client->requestTelegramAuth('6281234567890', 'staging');

// webhook verification
$raw = file_get_contents('php://input');
$sig = $_SERVER['HTTP_X_SIGNATURE'] ?? '';

if (!VerifyWebhookSignature::hmac($raw, $sig, getenv('LESSOTP_WEBHOOK_SECRET'))) {
    http_response_code(403);
    exit;
}

API

new Client($apiKey, $environment = 'production', $baseUrl = 'https://api.lessotp.com', $timeoutSeconds = 10, $http = null)

Parameters follow the same order as the Go SDK: apiKey → environment → baseUrl → timeout → custom transport.

Parameter Default Description
$apiKey required App API key.
$environment 'production' 'production' or 'staging'.
$baseUrl https://api.lessotp.com API host.
$timeoutSeconds 10 HTTP timeout.
$http null Optional GuzzleHttp\Client.

$client->authRequest($phoneNumber = null, $environment = null): AuthRequestResult

Legacy WhatsApp convenience method. The per-call $environment overrides the client environment.

$client->requestTelegramAuth($phoneNumber = null, $environment = null): AuthRequestResult

Telegram short-hand. Strict when $phoneNumber is supplied; frictionless when omitted.

$client->requestAuth(VerificationChannel $channel, $phoneNumber = null, $environment = null): AuthRequestResult

Multi-channel call. Use VerificationChannel::whatsapp() or VerificationChannel::telegram().

The normalized result includes:

  • getChannel() — the resolved channel.
  • getWaLink() — only when channel is whatsapp.
  • getTelegramLink() / getTelegramText() — only when channel is telegram.

VerificationSuccess::fromArray(array $body): VerificationSuccess

Canonical representation of a verification.success webhook payload. Includes getChannel() and getTelegramUserId() / getTelegramUsername() when channel is telegram.

VerifyWebhookSignature::hmac($rawBody, $signatureHeader, $secret): bool

Constant-time HMAC-SHA256 verification. Accepts raw hex and sha256= prefixed values.

Errors

Throws LessOTP\Sdk\LessOTPException on transport, auth, or payload problems.

Tests

composer install
composer test

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固