ahmedghanem00 / tempnumber-api-client
Temp-Number服务的API客户端 (https://temp-number.org/ )
1.1.10
2024-05-18 07:20 UTC
Requires
- php: ^8.2
- doctrine/collections: ^2.0
- symfony/http-client: ^6.0 || ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.54
- phpstan/phpstan: 1.10.x-dev
- phpunit/phpunit: dev-main
This package is auto-updated.
Last update: 2024-09-15 14:40:39 UTC
README
PHP编写的Temp-Number服务的API客户端 ( https://temp-number.org/ )。
如果您遇到错误或想改进代码,请随意打开问题或提交拉取请求。
安装
$ composer require ahmedghanem00/tempnumber-api-client
使用方法
客户端初始化
use ahmedghanem00\TempNumberClient\Client; $client = new Client('YOUR_API_TOKEN');
检索余额
try { echo $client->retrieveBalance(); // float "3.15" } catch (Exception $e) { echo $e->getMessage(); }
请求新的激活
use ahmedghanem00\TempNumberClient\Enum\Country; use ahmedghanem00\TempNumberClient\Enum\Service; try { # You can either use Service & Country enums as arguments or use the ids directly ( 'facebook', 'us' ) # If the activation price is higher than the given expected, the 'ExpectedPriceException' will be thrown $newActivation = $client->requestNewActivation(Service::Facebook, Country::United_States, $expectedPrice = 2.5); [$countryCode, $numberOnly, $formattedPhoneNumberWithCountryCode] = [ $newActivation->getPhoneNumberCountryCode(), $newActivation->getPhoneNumberWithoutCountryCode(), $newActivation->getFormattedPhoneNumberWithCountryCode() ]; # Will continuously polling the activation data from server until the specified condition is met. # Otherwise, the appropriate exception will be thrown $fulfilledActivationWithSmsMessage = $client->waitForActivationStatus($newActivation->getId(), ActivationStatus::SMS_RECEIVED, $pollingInterval = 2, $maxDuration = 100); echo $fulfilledActivationWithSmsMessage->getReceivedSMS(); ## "Thanks for activation. Your activation code is: 5678" echo $fulfilledActivationWithSmsMessage->getDetectedOtpCodeFromReceivedSMS(); ## "5678" } catch (Exception $e) { echo $e->getMessage(); }
重试激活
如果您有需要重试的特定激活
try { $client->retryActivation(181822); } catch (Exception $e) { echo $e->getMessage(); }
检索特定激活数据
try { $activationData = $client->retrieveActivationData(181822); echo $activationData->getStatus(); // string "smsRequested" echo $activationData->getCreationTimestamp(); // int "1681333257" echo $activationData->getRemainingSecondsToExpire(); // int "300" echo $activationData->isRetryable(); // bool "false" echo $activationData->getPhoneNumberWithoutCountryCode(); // string "(555) 555-1234" catch (Exception $e) { echo $e->getMessage(); }
检索特定服务和国家信息
use ahmedghanem00\TempNumberClient\Enum\Country; use ahmedghanem00\TempNumberClient\Enum\Service; try { $info = $client->retrieveCountryServiceInfo(Service::Instagram, Country::Russia) echo $info->hasNumbers(); // bool "true" echo $info->getPrice(); // float "2.15" } catch (Exception $e) { echo $e->getMessage(); }
检索所有服务和国家信息
# Grouped by service $infoGroupedByService = $client->retrievePriceListByService(); # OR by country $infoGroupedByCountry = $client->retrievePriceListByCountry(); foreach ($infoGroupedByCountry as $country) { echo $country->getName(); // 'uk' foreach ($country->services() as $countryService) { echo $countryService->getName(); // string "facebook" echo $countryService->getPrice(); // float "1.25" } }
检索所有以前的激活数据
$result = $client->retrieveActivationHistory($page = 2, $limit = 5); echo $result->getPageIndex(); // 2 echo $result->getPagesCount(); // 30 echo $result->getActivationsCount(); // 200 foreach ($result->activations() as $activation) { echo $activation->getId(); echo $activation->getStatus(); echo $activation->getPrice(); echo $activation->getFormattedPhoneNumberWithCountryCode(); echo $activation->getReceivedSMS(); }
LICENSE
此包受MIT许可证的许可。