serverclub/serverclub-sms-api

ServerClub SMS PHP SDK 使您轻松地从 PHP 应用程序与 SMS API 交互。

dev-master 2021-05-25 12:39 UTC

This package is auto-updated.

Last update: 2024-09-25 19:50:00 UTC


README

ServerClub SMS PHP SDK 使您轻松地从 PHP 应用程序与 SMS API 交互。

安装

通过 Composer

composer require serverclub/serverclub-sms-api

通过 Bash

git clone https://github.com/ServerClub-Digital/ServerClub-SMS-API.git

用法

步骤 1

如果使用 Git Clone 安装 ServerClub SMS API,则加载您的 ServerClub SMS API 类文件并使用命名空间。

require_once 'src/Class_ServerClub_SMS_API.php';
use ServerClubSMS\ServerClubSMSAPI;

如果使用 Composer 安装 ServerClub SMS API,则在项目的 index.php 文件或您需要使用 ServerClub SMS API 类的任何文件中需要/包含 autoload.php 文件:

require 'vendor/autoload.php';
use ServerClubSMS\ServerClubSMSAPI;

步骤 2

https://sms.serverclub.digital/sms/api(您的应用程序安装 URL)设置您的 API_KEY。

$api_key = 'YWRtaW46YWRtaW4ucGFFDzc3dvcmQ=';

步骤 3

更改下面的发送者 ID。

$from = 'Test';

步骤 4

我们要发送到的号码 - 任何电话号码

$destination = '94771234567';

您必须在电话号码的开头包含国家代码。

步骤 5

将您的安装 URL(如 https://sms.serverclub.digital/sms/api)替换为 https://sms.serverclub.digital,在安装 URL 中 sms/api 是强制性的。

$url = 'https://sms.serverclub.digital/sms/api';

// SMS 正文

$sms = 'test message from ServerClub SMS';

// Unicode SMS

$unicode = '1'; //For Unicode message

// 语音 SMS

$voice = '1'; //For voice message

// MMS SMS

$mms = '1'; //For mms message
$media_url = 'https://yourmediaurl.com'; //Insert your media url

// 定时 SMS

$schedule_date = '09/17/2018 10:20 AM'; //Date like this format: m/d/Y h:i A

// 为请求创建纯文本 SMS 正文

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms
);

// 为请求创建 Unicode SMS 正文

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'unicode' => $unicode,
);

// 为请求创建语音 SMS 正文

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'voice' => $voice,
);

// 为请求创建 MMS SMS 正文

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms, //optional
    'mms' => $mms,
    'media_url' => $media_url,
);

// 为请求创建定时 SMS 正文

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'schedule' => $schedule_date,
);

步骤 6

实例化一个新的 ServerClub SMS API 请求

$client = new ServerClubSMSAPI();

发送 SMS

最后,通过 ServerClub SMS API 发送您的短信

$response = $client->send_sms($sms_body, $url);

获取收件箱

获取您的所有消息

$get_inbox=$client->get_inbox($api_key,$url);

获取余额

获取您的账户余额

$get_balance=$client->check_balance($api_key,$url);

响应

ServerClub SMS API 以 json 格式返回响应,例如

{"code":"ok","message":"Successfully Send"}

状态码

作者