gladdle/nexah-sms 问题修复 & 功能扩展

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

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

gladdle/nexah-sms

最新稳定版本:1.0.0

Composer 安装命令:

composer require gladdle/nexah-sms

包简介

A php library for sending SMS to one or more phone numbers using the Nexah API

关键字:

README 文档

README

This PHP library lets you communicate with the Nexah API. You can send SMS messages and check your SMS balance. The library gives developers the flexibility to manage their interaction with the API. To use the API, you need an account. Visit the official website https://nexah.net/ to get one.

Requirements

Installation

Via composer

$ composer require gladdle/nexah-sms

Basic Usage

<?php

require "./vendor/autoload.php";

use Gladdle\NexahSms\Configuration;
use Gladdle\NexahSms\SmsClient;

$client = new SmsClient(
    new Configuration(
        "username",
        "password",
        "senderId"
    )
);

// Multiple numbers
// formats: 6xxxxxxxx or 2376xxxxxxxx
$client->send("6xxxxxxxx, 2376xxxxxxxx", "Message to be sent"); // returns true

// One number
$client->send("6xxxxxxxx", "Message to be sent"); // returns true

// Get SMS balance
$client->getBalance() // returns number, eg 10000

Catching errors

When you try to communicate with the API, errors may occur:

  • Incorrect username and/or password,
  • Invalid phone numbers

You can adapt your codes according to the error encountered

use Gladdle\NexahSms\Exception\AuthException;
use Gladdle\NexahSms\Exception\SendingFailureException;

try {

    $client->send("6xxxxxxxx, 2376xxxxxxxx", "Message to be sent");
    $client->getBalance();

} catch (AuthException $e) {
    // Wrong username and/or password 
    // do stoff...
} catch (SendingFailureException $e) {
    // Incorrect numbers. Message not sent
    // Retrieve them
    $numbers = $client->getInvalidNumbers(); // ['6xxxxxxxxx', 'xxxxxxxxx'];
}

Testing

Immediately after installation, you can test the library without writing a line of code. Make sure you have a valid username and password.

$ NX_BAD_USER=username NX_GOOD_USER=username NX_PWD=password NX_GOOD_NUM=677777777 NX_BAD_NUM=6777777771 NX_SENDERID=senderId  php vendor/bin/phpunit tests/

NX_BAD_USER and the others are environment variables. You can define them according to your operating system

  • NX_BAD_USER invalid username
  • NX_GOOD_USER valid username
  • NX_PWD good password
  • NX_GOOD_NUM good number
  • NX_BAD_NUM invalid number like 10 digits

Logs

You can stream logs messages by defining file path

$client = new SmsClient(
    new Configuration(
        "username",
        "password",
        "senderId"
        __DIR__ . '/var/logs.log'
    )
);

Author

Koumé KOUMGANG - https://www.linkedin.com/in/etiennekoumgang/

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-09