olusegun171 / laravel-termii
Termii Laravel包
Requires
- php: >=8.0
Requires (Dev)
- laravel/pint: dev-main
- orchestra/testbench: 5.x-dev
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-03 17:50:48 UTC
README
这是一个用于Termii API的laravel包
要求
- Php >= 8.0
- Laravel 9.0 or higher
安装
composer require olusegun171/laravel-termii
安装Laravel包后,打开您的.env文件并添加以下变量。从https://accounts.termii.com/获取您的API密钥
TERMII_SENDER_ID="N-Alert"
TERMII_API_KEY=""
TERMII_BASE_URL = "https://api.ng.termii.com"
用法
要使用Termii的任何API,首先添加LaravelTermii\Termii类
use LaravelTermii\Termii;
1. 消息API
要使用Termii的Messaging API,首先创建一个实例
$messaging = Termii::messaging();
使用默认的senderID 'N-Alert'发送消息。
$channel = 'generic'; //default is 'generic' or pass 'dnd' to send dnd message $response = $messaging->sendMessage(string $to, string $message, string $channel); $response->json();
使用默认的senderID 'N-Alert'批量发送消息。
$channel = 'generic'; //default is 'generic' or pass 'dnd' to send dnd message $messaging->sendBulkMessage($to, string $mesage);
使用Termii自动生成的适应客户位置的短信号码向客户发送消息。更多信息请访问https://developer.termii.com/number
$response = $messaging->sendNumber(string $to, string $message); $response->json();
使用默认设备名称'N-Alert'发送WhatsApp消息
//The url to the file resource and caption that should be added to the image, $media = ['url' => '','caption' => '' ]; $device_name = 'N-Alert'; // you can pass another approved device name. $response = $messaging->sendWhatapps(string $to, string $device_name, array $media); $response->json();
为通过WhatsApp或短信发送到客户的一次性密码(pins)设置模板。更多信息请访问https://developer.termii.com/templates
/* $data = [ "product_name": "Termii", "otp" : 120435, "expiry_time": "10 minutes" ] */ $response = $messaging->sendTemplate(string $to, string $template_id, string $device_id, array $data); $response->json();
使用这些方法创建、查看和管理电话簿。每个电话簿都可以通过唯一的ID识别,这使得编辑或删除电话簿更容易。
//get all phonebooks $response = $messaging->phonebooks(); $response->json(); //create phonebook $response = $messaging->createPhoneBook(string $phonebook_name, string $desc = ''); $response->json(); //update phonebook $response = $messaging->updatePhoneBook(string $phonebook_id, string $phonebook_name); $response->json(); //Delete phonebook $response = $messaging->deletePhoneBook(string $phonebook_id); $response->json();
管理电话簿中的联系人。
//Fetch contacts by phonebook ID $response = $messaging->PhonebookContacts(string $phonebook_id); $response->json(); //Add single contact to a phonebook /* $contact = [ "phone_number" => "8123696237", "email_address" => "test@gmail.com", "first_name" => "test", "last_name" => "contact", "company" => "Termii", "country_code" => "234" ]; */ $response = $messaging->addContact(string $phonebook_id, array $contact); $response->json(); //Add multiple contacts to a phonebook /* file containing the list of contacts. Supported files include : 'txt', 'xlsx', and 'csv'. $contact_file = 'test_names.csv"; $country_code = "234"; */ $response = $messaging->addMutipleContacts(string $phonebook_id, string $contact_file, string $country_code); $response->json(); //Delete a contact $response = $messaging->deleteContact(string $contact_id); $response->json();
查看、管理并向电话簿发送活动
//Fetch campaigns $response = $messaging->campaigns(); $response->json(); //Fetch campaign history $response = $messaging->campaignHistory(string $campaign_id); $response->json(); //Send a campaign with default senderID 'N-Alert' /* $channel = 'generic'; $schedule = [ "schedule_sms_status" => "scheduled" // To send a scheduled campaign, pass scheduled as the value "schedule_time" => "30-06-2021 6:00", //The date time to send scheduled campaign ]; */ $response = $messaging->sendCampaign(string $phonebook_id, string $message, string $channel, array $schedule = []); $response->json();
使用此方法从您的Termii账户请求新的发送者ID
$response = $messaging->requestSenderID(string $sender_id, string $usecase, string $company); $response->json();
使用此方法获取您的Termii账户中所有发送者ID
$response = $messaging->fetchSenderID(); $response->json();
2. 令牌API
要使用Termii的Token API,首先创建一个实例
$token = Termii::token(["pin_attempts" => 10, "pin_time_to_live" => 30, "pin_length" => 6, "pin_placeholder" => '< 123 >', 'pin_type' => 'ALPHANUMERIC', 'message_type' => 'ALPHANUMERIC', ]);
在Termii的任何可用消息通道上触发一次性密码(OTP)。创建的OTP是随机生成的,并且可以选择设置过期时间。
$response = $token->sendToken(string $to, string $from, string $mesage, string $channel = 'generic'); $response->json();
通过语音通道生成并触发一次性密码(OTP)到电话号码。OTP生成并发送到电话号码,可以通过调用wverifyToken方法进行验证
$response = $token->voiceToken(string $phone_number); $response->json();
通过我们的语音通道将消息从您的应用程序发送到电话号码。目前只允许发送一次性密码(OTP),并且这些OTP不能被验证
$response = $token->voiceCall(string $phone_number, string $code); $response->json();
通过我们的电子邮件通道从您的应用程序发送一次性密码到电子邮件地址。目前只允许发送一次性密码(OTP),并且这些OTP不能被验证
$response = $token->emailToken(string $email, string $code, $config_id); $response->json();
检查发送给客户的令牌,并返回一个响应,确认令牌的状态。根据为令牌设置的计时器,令牌可以是已验证或已过期。
$response = $token->verifyToken(string $pin_id, string $pin); $response->json();
以JSON格式返回OTP代码,这些代码可以在任何Web或移动应用程序中使用。令牌是用于验证登录请求和验证客户交易的数字或字母数字代码。
$response = $token->inAppToken(string $phone_number); $response->json();
3. 洞察API
要使用Termii的Insight API,首先创建一个实例
$insight = Termii::insights();
返回您的总余额和钱包的余额信息,例如货币。
$response = $insight->balance(); $response->json();
用于验证电话号码,并自动检测它们的状态以及当前网络。它还指示该号码是否已激活勿扰设置。
$response = $insight->search(string $phone_number); $response->json();
检查一个号码是否是虚假的或已转移到新的网络。
$response = $insight->status(string $phone_number, string $country_code = 'NG'); $response->json();
返回通过短信、语音和WhatsApp渠道发送的消息的报告。报告可以显示Termii上的所有消息或单条消息。这将返回您的总余额和钱包中的余额信息,例如货币。
$response = $insight->history(); $response->json();
其他响应方法
$response->body() : string; $response->json($key = null, $default = null) : mixed; $response->object() : object; // Returns http status code $response->status() : int; // Determine if the status code is >= 200 and < 300... $response->successful(); // Determine if the status code is >= 400... $response->failed(); // Determine if the response has a 400 level status code... $response->clientError(); // Determine if the response has a 500 level status code... $response->serverError();
许可协议
本项目受MIT许可协议许可。更多信息,请参阅许可协议文件。