承接 tarwege/sms-whatsapp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tarwege/sms-whatsapp

Composer 安装命令:

composer require tarwege/sms-whatsapp

包简介

A PHP package to interact with Tarwege SMS, WhatsApp, and USSD endpoints.

README 文档

README

Below is an updated version of the README that reflects usage based on the provided class structure and the Guzzle-based API client implementation.

Tarwege SMS & WhatsApp API Client

Official PHP client for Tarwege's SMS & WhatsApp API with first-class Laravel support. Use your SIM to send SMS as a provider.

Latest Version Total Downloads License PHP Version

Features ✨

Tarwege SMS & WhatsApp API Client provides extensive API coverage including messaging, contact management, campaign management, OTP services, USSD, notifications, and more.

Core Messaging Features

  • SMS Operations

    • Send Single SMS
    • Send Bulk SMS
    • Scheduled SMS Campaigns
    • SMS Delivery Status Tracking
    • SMS Message History
    • SMS Auto-Reply System
    • SMS Forwarding
    • SMS Number Validation
  • WhatsApp Operations

    • Send Text Messages
    • Send Media Messages (Images/Video/Audio)
    • Send Documents (PDF, DOC, XLS)
    • Send Location Sharing
    • Send Contact Cards
    • Bulk WhatsApp Campaigns
    • WhatsApp Template Messages
    • WhatsApp Group Management

Contact & Campaign Management

  • Contact System

    • Create & Manage Contacts and Groups
    • CSV Contact Upload
    • Contact Import/Export and Deduplication
    • Unsubscribe Management
  • Campaign Engine

    • Create and Schedule SMS/WhatsApp Campaigns
    • Analytics, A/B Testing, and Personalized Messaging
    • Click Tracking and Campaign Pause/Resume

OTP & Security

  • OTP Services
    • OTP Generation, Sending & Verification
    • OTP Expiry and Rate Limiting

Advanced & Enterprise Features

  • Automation, USSD Services, Notifications, API Enhancements, and more

Installation 🚀

Install via Composer:

composer require tarwege/sms-whatsapp

For Laravel projects, publish the configuration file:

php artisan vendor:publish --provider="Tarwege\SmsWhatsapp\Providers\TarwegeServiceProvider" --tag="tarwege-config"

Then, add your API credentials to your .env file:

TARWEGE_API_SECRET=your_api_secret_here
TARWEGE_BASE_URL=https://api.tarwege.com

Usage Examples 📖

This package uses a dedicated API client (TarwegeClient) and multiple service classes for specific endpoints. When using Laravel, you can access the client via the provided facade (Tarwege). Otherwise, instantiate the classes directly by passing a configured client instance.

1. Initializing the API Client

You can either use the facade in Laravel:

use Tarwege\SmsWhatsapp\Facades\Tarwege;

// Get the underlying TarwegeClient instance
$tarwegeClient = Tarwege::getFacadeRoot();

Or create a new client instance manually:

use Tarwege\SmsWhatsapp\Services\TarwegeClient;

$tarwegeClient = new TarwegeClient('your_api_secret_here', 'https://api.tarwege.com');

2. Account Management

use Tarwege\SmsWhatsapp\Services\AccountService;

// Instantiate AccountService with the client
$accountService = new AccountService($tarwegeClient);

// Example: Get partner earnings and remaining credits
$partnerEarnings = $accountService->getPartnerEarnings();
$remainingCredits = $accountService->getRemainingCredits();

// Example: Get subscription package details
$subscription = $accountService->getSubscriptionPackage();

3. SMS Operations

use Tarwege\SmsWhatsapp\Services\SmsService;

// Instantiate SmsService with the client
$smsService = new SmsService($tarwegeClient);

// Send a single SMS
$response = $smsService->sendSingleMessage([
    'mode'    => 'credits',
    'phone'   => '+967781606026',
    'message' => 'Your OTP is {{otp}}',
    'gateway' => 'partner_device_id'
]);

// Send bulk SMS messages
$bulkResponse = $smsService->sendBulkMessages([
    'campaign' => 'Holiday Sale',
    'groups'   => '1,2,5',
    'message'  => 'Special discounts inside!'
]);

4. WhatsApp Integration

use Tarwege\SmsWhatsapp\Services\WhatsAppService;

// Instantiate WhatsAppService with the client
$waService = new WhatsAppService($tarwegeClient);

// Send a single WhatsApp chat message
$response = $waService->sendSingleChat([
    'account'   => 'wa_account_id',
    'recipient' => '+967781606026',
    'type'      => 'text',
    'message'   => 'Hello from Tarwege!'
]);

// Validate a WhatsApp phone number
$validation = $waService->validateWhatsAppPhoneNumber([
    'unique' => 'wa_account_id',
    'phone'  => '+967781606026'
]);

5. OTP Services

use Tarwege\SmsWhatsapp\Services\OTPService;

// Instantiate OTPService with the client
$otpService = new OTPService($tarwegeClient);

// Send an OTP (with a 5-minute expiration)
$sendResponse = $otpService->sendOTP([
    'phone'   => '+967781606026',
    'message' => 'Your verification code: {{otp}}',
    'expire'  => 300
]);

// Verify an OTP
try {
    $verifyResponse = $otpService->verifyOTP([
        'phone' => '+967781606026',
        'otp'   => '123456'
    ]);
} catch (\Tarwege\SmsWhatsapp\Exceptions\TarwegeApiException $e) {
    // Handle error, e.g., invalid OTP or API error
    logger()->error("OTP Verification failed: {$e->getMessage()}");
}

6. Additional Services

Similarly, you can use the other provided services by instantiating them with the API client:

  • ContactService: Manage contacts and groups

    use Tarwege\SmsWhatsapp\Services\ContactService;
    
    $contactService = new ContactService($tarwegeClient);
    $contacts = $contactService->getContacts();
  • NotificationService: Manage notifications

    use Tarwege\SmsWhatsapp\Services\NotificationService;
    
    $notificationService = new NotificationService($tarwegeClient);
    $notifications = $notificationService->getNotifications();
  • SystemService: Get system-related data (gateway rates, shorteners)

    use Tarwege\SmsWhatsapp\Services\SystemService;
    
    $systemService = new SystemService($tarwegeClient);
    $gatewayRates = $systemService->getGatewayRates();
  • UssdService: Handle USSD requests

    use Tarwege\SmsWhatsapp\Services\UssdService;
    
    $ussdService = new UssdService($tarwegeClient);
    $ussdRequests = $ussdService->getUssdRequests();

Advanced Configuration ⚙️

Customize settings in config/tarwege.php (published for Laravel or manually created for non-Laravel usage):

return [
    'secret' => env('TARWEGE_API_SECRET'),
    
    // Request timeout in seconds
    'timeout' => 15,
    
    // Automatic retry configuration
    'retries' => [
        'attempts'   => 3,
        'sleep_ms'   => 1000,
        'http_codes' => [500, 502, 503, 504]
    ],
    
    // Default SMS settings
    'sms_defaults' => [
        'mode'     => 'credits',
        'sim'      => 1,
        'priority' => 1
    ]
];

API Method Reference 📚

Category Methods
Account getPartnerEarnings(), getRemainingCredits(), getSubscriptionPackage()
Contacts createContact(), getContacts(), deleteContact(), getGroups()
SMS sendSingleMessage(), sendBulkMessages(), getSentMessages(), deleteReceivedMessage(), etc.
WhatsApp sendSingleChat(), sendBulkChats(), getAccounts(), validateWhatsAppPhoneNumber(), etc.
USSD sendUssdRequest(), getUssdRequests(), clearPendingUssd()
Notifications getNotifications(), deleteNotification()

Testing 🧪

Run the test suite using:

composer test

Tests cover:

  • API request validation
  • Error handling and retry logic
  • File uploads and response parsing

Security 🔒

Please report security vulnerabilities to security@tarwege.com – do NOT use the public issue tracker.

Support & Contributing 🤝

Official Support:

Contributing Guidelines:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push your branch: git push origin feature/amazing-feature
  5. Open a Pull Request

License 📄

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

📄 Full API Documentation: Tarwege API Docs
🐛 Issue Tracker: GitHub Issues
💡 Changelog: Releases Page

tarwege/sms-whatsapp 适用场景与选型建议

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

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

围绕 tarwege/sms-whatsapp 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-21