webservis/goyercin-sms

简单的PHP示例

dev-main 2024-05-16 22:20 UTC

This package is auto-updated.

Last update: 2024-09-16 23:05:44 UTC


README

这是一个用于与PostaGuvercini.com SMS API交互的PHP类。此类允许您通过使用他们的HTTP API通过PostaGuvercini服务发送短信。

特性

  • 轻松集成PostaGuvercini.com SMS API。
  • 支持发送带有自定义文本和接收者号码的短信。
  • 处理API响应,并提供基于错误代码的错误消息。
  • 利用现代PHP 8.0功能,如类型提示和构造函数属性提升。
  • 异常处理,以实现更好的错误管理。

使用方法

  1. 初始化类:首先,您需要在项目中包含GoyercinSMS.php文件。您可以通过将GoyercinSMS.php文件的内容复制到您的项目中,或者使用Composer来实现。

    composer require webservis/goyercin-sms

    #基本使用

    require_once 'vendor/autoload.php'; // Adjust this based on your project's structure
    
    use Webservis\GoyercinSMS;
    
    $user = "YOUR_USERNAME";
    $password = "YOUR_PASSWORD";
    $goyercinSMS = new GoyercinSMS($user, $password);
  2. 发送短信

    $gsm = "5329999999";
    $text = "Test message";
    $result = $goyercinSMS->sendSMS($gsm, $text);
    
    if ((int)$result['errno'] === 0) {
        echo "Message sent successfully.<br>";
        echo "Message ID: " . $result['message_id'] . "<br>";
        echo "Charge: " . $result['charge'] . "<br>";
    } else {
        $errorText = $goyercinSMS->getErrorText((int)$result['errno']);
        echo "Error sending message<br>";
        echo "Error Code: " . $result['errno'] . "<br>";
        echo "Description: " . $errorText . "<br>";
    }

安装

  1. 确保您已安装PHP 8.0或更高版本。
  2. 下载GoyercinSMS类并将其包含到您的项目中。

要求

  • PHP 8.0或更高版本。
  • cURL扩展已启用。

许可

本项目采用GNU通用公共许可证许可。