checkmobi / checkmobi-php
CheckMobi SDK for PHP
1.4
2024-02-04 16:01 UTC
Requires
- php: >=5.5
- ext-json: *
README
CheckMobi API 集成官方 SDK。CheckMobi 是一个提供性价比高的服务的平台,如:
- 通过短信、未接来电和 IVR 实现的两因素认证
- 用于营销和交易通知的短信 API。
- 用于创建自定义 IVR 的语音 API。
此 PHP SDK 使开发者能够轻松地将 CheckMobi 的 SMS 和 Voice 功能添加到他们的 PHP 应用程序中,无需太多麻烦。
要求
为了使用此库,您需要安装 CURL
或 HTTP_Request2
扩展之一。
使用 CURL
php-curl
php-openssl
使用 HTTP_Request2
pear install HTTP_Request2
SDK 首先检查 CURL
扩展,并在必要时回退到 HTTP_Request2
。您可以使用构造函数的 options
参数设置传输方法。
安装
SDK 可以使用 Composer
安装。
composer require checkmobi/checkmobi-php
开始使用
创建 CheckMobiRest 客户端
use checkmobi\CheckMobiRest; $client = new CheckMobiRest("secret key here");
如果您想更改库的默认行为,可以使用 options
数组属性。
示例
$client = new CheckMobiRest("secret key here", [ "net.timeout" => 10, "net.ssl_verify_peer" => false ]);
资源
SDK 是描述在此的 REST API 的包装器。有关以下方法接受的全部属性,请查看文档。
// get list of countries & flags $response = $client->GetCountriesList(); // get account details $response = $client->GetAccountDetails(); // get prefixes $response = $client->GetPrefixes(); // checking a number for being valid $response = $client->CheckNumber(array("number" => "+number_here")); // validate a number using "Missed call method". (type can be : sms, ivr, reverse_cli) $response = $client->RequestValidation(array("type" => "reverse_cli", "number" => "+number_here")); // verify a pin for a certain request $response = $client->VerifyPin(array("id" => "request id here", "pin" => "5659")); // check validation status for a certain request $response = $client->ValidationStatus(array("id" => "request id here")); // get remote config profile $response = $client->GetRemoteConfigProfile(array("number" => "+number_here", "platform" => "android")); // send a custom sms $response = $client->SendSMS(array("to" => "+number_here", "text" => "message here")); // get sms details $response = $client->GetSmsDetails(array("id" => "sms id here")); // place call $params = [ "from" => "+source_number_here", "to" => "+destination_number_here", "events" => [ ["action" => "speak", "text" => "Hello world", "loop" => 2, "language" => "en-US"] ] ]; $response = $client->PlaceCall($params); // get call details $response = $client->GetCallDetails(array("id" => "call id here")); // hangup call $response = $client->HangUpCall(array("id" => "call id here")); // perform HLR Lookup $response = $client->HLRLookup(["number"=> "+number here"]); // perform MNP Lookup $response = $client->MNPLookup(["number"=> "+number here"]); // perform number verification $response = $client->VerifyLookup(["number"=> "+number here"]);
响应处理
响应是一个 CheckMobiResponse
类型的对象,它公开以下方法:
示例
if($response->is_success()) { // success print_r($response->payload()); } else { // failure print "error code: ".$response->payload()["code"]." error message: ".$response->payload()["error"]; }