phpjuice/wati-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

phpjuice/wati-sdk

最新稳定版本:v1.0.1

Composer 安装命令:

composer require phpjuice/wati-sdk

包简介

PHP SDK for Wati.io REST APIs

README 文档

README

CI PHP Version Latest Stable Version Total Downloads License PRs Welcome

A PHP SDK for the Wati.io WhatsApp API. Provides pre-built API classes for common operations.

Installation

This package requires PHP 8.3 or higher.

composer require "phpjuice/wati-sdk"

Setup

Get Your Credentials

  1. Log in to your Wati Account
  2. Navigate to API Docs in the top menu
  3. Copy your API Endpoint URL and Bearer Token

Create a Client

<?php

use Wati\Http\WatiClient;
use Wati\Http\WatiEnvironment;
use Wati\Api\GetContacts;

// Get this URL from your Wati Dashboard (API Docs section)
// It includes your tenant ID: https://your-instance.wati.io/{tenantId}
$endpoint = "https://your-instance.wati.io/123456";
$bearerToken = "your-bearer-token";

// Create environment and client
$environment = new WatiEnvironment($endpoint, $bearerToken);
$client = new WatiClient($environment);

// Use pre-built API classes
$response = $client->send(new GetContacts());
$contacts = json_decode($response->getBody()->getContents(), true);

Usage with Laravel

The SDK includes a Laravel service provider for easy integration.

Configuration

Add the following to your config/services.php:

'wati' => [
    'endpoint' => env('WATI_ENDPOINT'),
    'token' => env('WATI_TOKEN'),
],

Add to your .env file:

WATI_ENDPOINT=https://your-instance.wati.io/123456
WATI_TOKEN=your-bearer-token

Usage in Laravel

The service provider is auto-discovered. Simply inject or resolve WatiClient:

use Wati\Http\WatiClient;
use Wati\Api\GetContacts;

class ContactController
{
    public function __construct(
        private readonly WatiClient $wati
    ) {}

    public function index()
    {
        $response = $this->wati->send(new GetContacts());
        return json_decode($response->getBody()->getContents(), true);
    }
}

Available API Classes

Contacts

Class Method Endpoint
GetContacts GET /api/v1/getContacts

Templates

Class Method Endpoint
GetMessageTemplates GET /api/v1/getMessageTemplates
SendTemplateMessage POST /api/v1/sendTemplateMessage

Usage

Get Contacts

<?php

use Wati\Api\GetContacts;

// Get the first page with 50 contacts (default)
$response = $client->send(new GetContacts());

// Get a specific page with a custom page size
$response = $client->send(new GetContacts(pageNumber: 2, pageSize: 100));

Error Handling

<?php

use Wati\Http\Exceptions\AuthenticationException;
use Wati\Http\Exceptions\RateLimitException;
use Wati\Http\Exceptions\ValidationException;
use Wati\Http\Exceptions\WatiApiException;
use Wati\Http\Exceptions\WatiException;

try {
    $response = $client->send(new GetContacts());
} catch (AuthenticationException $e) {
    // Invalid bearer token - check credentials
} catch (RateLimitException $e) {
    // Rate limited - wait and retry
    $retryAfter = $e->getRetryAfter();
} catch (ValidationException $e) {
    // Invalid request parameters
    $errors = $e->getResponseData();
} catch (WatiApiException $e) {
    // Other API errors (4xx, 5xx)
    $statusCode = $e->getStatusCode();
} catch (WatiException $e) {
    // Connection or other HTTP errors
}

API Reference

For full API documentation, visit Wati API Docs.

Changelog

Please see the CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email the author instead of using the issue tracker.

License

Please see the License file.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固