abdallahmohammed / alsaad-php
Alsaad API 的 PHP 客户端。
v1.0.0
2020-05-12 10:00 UTC
Requires
- php: >=7.1
- php-http/guzzle6-adapter: ^1.0
- zendframework/zend-diactoros: ^2.2
Requires (Dev)
- estahn/phpunit-json-assertions: ^3.0.0
- php-http/mock-client: ^0.3.0
- phpunit/phpunit: ^7.4
- squizlabs/php_codesniffer: ^3.1
This package is auto-updated.
Last update: 2024-09-12 19:45:13 UTC
README
此库需要至少 PHP 版本 7.1
这是用于使用 Alsaad2 API 的 PHP 客户端库。要使用此库,您需要一个 Alsaad2 账户。
安装
要将 PHP 客户端库安装到项目中,我们建议使用 Composer。
composer install abdallahmohammed/alsaad-php
用法
如果您正在使用 Composer,请确保自动加载器已包含在项目引导文件中
require_once "vendor/autoload.php";
使用用户名和密码创建客户端
$client = new Alsaad\Client([ 'username' => ALSAAD2_USERNAME, 'password' => ALSAAD2_PASSWORD, ]);
示例
发送消息
要使用 Alsaad2 的 SMS API 发送短信,请调用 $client->message()->send()
方法。
$message = $client->message()->send([ 'to' => ALSAAD2_TO, //can be array of numbers or string 'from' => ALSAAD2_SENDER, 'message' => 'Hello World' ]);
API 响应数据可以作为消息的数组属性访问。
访问响应数据
当出现问题时,您将收到一个异常。异常类 Alsaad\Client\Exception\Request
支持一个额外的 getEntity()
方法,您可以使用它以及 getCode()
和 getMessage()
来获取更多关于出错的信息。返回的实体通常是与操作相关的对象,或 API 调用的响应对象。