phpjuice/wati-http-client
Composer 安装命令:
composer require phpjuice/wati-http-client
包简介
PHP Http Client for Wati.io WhatsApp API
README 文档
README
A PHP HTTP Client for the Wati.io WhatsApp API. Provides a simple, fluent API to interact with Wati's REST API.
Related Packages
For a higher-level, feature-rich integration, consider using wati-sdk. It provides ready-to-use request classes, response DTOs, and additional convenience features built on top of this HTTP client.
Installation
This package requires PHP 8.3 or higher (8.3, 8.4, and 8.5 are supported).
composer require "phpjuice/wati-http-client"
Setup
Get Your Credentials
- Log in to your Wati Account
- Navigate to API Docs in the top menu
- Copy your API Endpoint URL and Bearer Token
Create a Client
<?php use Wati\Http\WatiClient; use Wati\Http\WatiEnvironment; // 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 $environment = new WatiEnvironment($endpoint, $bearerToken); // Create client $client = new WatiClient($environment);
With Custom Options
<?php $client = new WatiClient($environment, [ 'timeout' => 60, // Request timeout in seconds (default: 30) 'connect_timeout' => 15, // Connection timeout in seconds (default: 10) 'verify' => true, // Verify SSL certificate (default: true) 'proxy' => 'tcp://localhost:8080', // Proxy URL (default: null) 'debug' => false, // Enable debug mode (default: false) ]);
Usage
Making Requests
Extend WatiRequest to create your API requests:
<?php use Wati\Http\WatiRequest; use GuzzleHttp\Psr7\Utils; class GetContactsRequest extends WatiRequest { public function __construct(int $page = 1, int $pageSize = 50) { parent::__construct( 'GET', "/api/v1/getContacts?page={$page}&pageSize={$pageSize}", ['Accept' => 'application/json'] ); } } class SendTemplateMessageRequest extends WatiRequest { public function __construct(string $phoneNumber, string $templateName, array $parameters = []) { $body = json_encode([ 'template_name' => $templateName, 'broadcast_name' => $templateName, 'parameters' => $parameters, ]); parent::__construct( 'POST', "/api/v1/sendTemplateMessage?whatsappNumber={$phoneNumber}", [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', ], Utils::streamFor($body) ); } }
Execute Requests
<?php use GuzzleHttp\Utils; // Get contacts $response = $client->send(new GetContactsRequest()); $data = Utils::jsonDecode($response->getBody()->getContents(), true); // Send a template message $response = $client->send(new SendTemplateMessageRequest( '1234567890', 'hello_world', ['name' => 'John'] ));
API Reference
For full API documentation, visit Wati API Docs.
Available Endpoints
- Messaging: Send templates, session messages, interactive messages
- Contacts: Get, add, update contacts
- Conversations: Messages, status updates
- Templates: Get and send message templates
- Campaigns: Manage broadcasts
Error Handling
The client throws specific exceptions for different error scenarios:
<?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 GetContactsRequest()); } catch (AuthenticationException $e) { // Invalid bearer token - check credentials echo "Auth failed: " . $e->getMessage(); } catch (RateLimitException $e) { // Rate limited - wait and retry $retryAfter = $e->getRetryAfter(); // seconds to wait } catch (ValidationException $e) { // Invalid request parameters $errors = $e->getResponseData(); } catch (WatiApiException $e) { // Other API errors (4xx, 5xx) $statusCode = $e->getStatusCode(); $data = $e->getResponseData(); } catch (WatiException $e) { // Connection or other HTTP errors echo "Request failed: " . $e->getMessage(); }
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.
phpjuice/wati-http-client 适用场景与选型建议
phpjuice/wati-http-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 118 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「client」 「whatsapp」 「phpjuice」 「wati」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phpjuice/wati-http-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpjuice/wati-http-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phpjuice/wati-http-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
WhatsApp Latest CLoud API Wrapper for PHP
http客户端
Easily add Excepct-CT header to your project
统计信息
- 总下载量: 118
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-20