PHP code example of rstacode / otpiq
1. Go to this page and download the library: Download rstacode/otpiq library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rstacode / otpiq example snippets
use Rstacode\Otpiq\Facades\Otpiq;
use Rstacode\Otpiq\DTOs\SmsData;
// Send verification code
$response = Otpiq::sendSms(new SmsData(
phoneNumber: '9647501234567',
smsType: 'verification',
verificationCode: '123456'
));
// Response
[
'message' => 'SMS task created successfully',
'smsId' => 'sms-1234567890',
'remainingCredit' => 920,
'provider' => 'telegram',
'status' => 'pending'
]
// Send custom message with sender ID
$response = Otpiq::sendSms(new SmsData(
phoneNumber: '9647501234567',
smsType: 'custom',
customMessage: 'Your custom message here',
senderId: 'YourBrand'
));
// Track SMS delivery status
$status = Otpiq::trackSms('sms-1234567890');
// Response
[
'status' => 'delivered',
'phoneNumber' => '964750000000',
'smsId' => 'sms-1234567890',
'cost' => 80
]
// Get project info and remaining credits
$projectInfo = Otpiq::getProjectInfo();
// Access project info
echo $projectInfo->projectName; // "My Project"
echo $projectInfo->credit; // 1000
// Get all sender IDs
$senderIds = Otpiq::getSenderIds();
// Response
[
'senderIds' => [
[
'id' => 'sender-123',
'senderId' => 'MyBrand',
'status' => 'accepted',
'createdAt' => '2024-01-01T00:00:00.000Z'
]
]
]
use Rstacode\Otpiq\Exceptions\OtpiqException;
use Rstacode\Otpiq\Exceptions\InvalidConfigurationException;
try {
$response = Otpiq::sendSms($smsData);
} catch (InvalidConfigurationException $e) {
// Handle invalid API key or configuration issues
echo $e->getMessage();
} catch (OtpiqException $e) {
// Handle API errors, insufficient credit, etc.
echo $e->getMessage();
$errors = $e->getErrors(); // Get detailed error information
}
bash
php artisan vendor:publish --provider="Rstacode\Otpiq\OtpiqServiceProvider" --tag="otpiq-config"
bash
./vendor/bin/phpunit tests/Unit/OtpiqTest.php