avraapi/laravel-sdk
Composer 安装命令:
composer require avraapi/laravel-sdk
包简介
Official Laravel integration package for the AvraAPI (APIX) enterprise API gateway. Provides a Service Provider, Facade, and config file for seamless Laravel 10/11/12 integration.
README 文档
README
Official Laravel integration package for the AvraAPI (APIX) enterprise API gateway.
Provides a Service Provider, Facade, and config file for seamless Laravel 10/11/12 integration. Built on top of avraapi/php-sdk.
Full documentation & guides: https://avraapi.com/developers/sdks
composer require avraapi/laravel-sdk
Quick Start
The package auto-discovers via extra.laravel in composer.json — no manual registration needed.
Publish Config
php artisan vendor:publish --tag=avraapi-config
Set Credentials
Add to your .env:
AVRAAPI_API_KEY=your-api-key AVRAAPI_API_SECRET=your-api-secret AVRAAPI_ENV=dev
Use the Facade
use Avraapi\Laravel\Facades\AvraAPI; // IP geolocation $geo = AvraAPI::location()->lookupIp('112.134.205.126'); echo $geo->data['country']; // 'Sri Lanka' // SMS AvraAPI::sms()->sendSingle('0771234567', 'Hello from AvraAPI!'); // QR code AvraAPI::utilities()->generateQr('https://avraapi.com')->saveAs('/tmp/qr.png');
Services
| Service | Accessor | Endpoints |
|---|---|---|
| Location | AvraAPI::location() |
IP geolocation lookups |
| SMS | AvraAPI::sms() |
Single, bulk-same, bulk-different, balance |
| Utilities | AvraAPI::utilities() |
QR codes, barcodes, PDF generation |
| Security | AvraAPI::security() |
VPN & Proxy Shield, Burner Email Detection |
| Currency | AvraAPI::currency() |
Currency codes, live rates, pair rates, conversion |
PDF Generation
Basic HTML to PDF
$html = '<h1>Invoice #001</h1><p>Total: $99.00</p>'; $response = AvraAPI::utilities()->generatePdf($html); $response->saveAs(storage_path('app/invoices/invoice.pdf'));
Landscape with Custom Margins
$response = AvraAPI::utilities()->generatePdf( html: $html, pageSize: 'A4', orientation: 'landscape', margins: ['top' => 20, 'right' => 25, 'bottom' => 20, 'left' => 25], ); $response->saveAs(storage_path('app/reports/landscape.pdf'));
Base64 JSON Response
$response = AvraAPI::utilities()->generatePdf($html, responseType: 'base64'); $base64Pdf = $response->data['data']; file_put_contents(storage_path('app/invoice.pdf'), base64_decode($base64Pdf));
Generating PDFs from Complex Templates (Base64 Mode)
When your HTML contains quotes, newlines, inline CSS, or special characters, JSON escaping can cause issues. Base64 mode solves this by encoding the HTML before transport.
Option A: Use the generatePdfFromBase64() Helper (Recommended)
The helper accepts raw HTML and encodes it automatically:
// Load a complex Blade-rendered template $html = view('invoices.pdf-template', [ 'invoice' => $invoice, 'items' => $items, ])->render(); // The SDK Base64-encodes internally — no manual encoding needed $response = AvraAPI::utilities()->generatePdfFromBase64($html); $response->saveAs(storage_path('app/invoices/inv-' . $invoice->id . '.pdf')); // With full options: $response = AvraAPI::utilities()->generatePdfFromBase64( html: $html, responseType: 'binary', pageSize: 'Letter', orientation: 'landscape', margins: ['top' => 15, 'right' => 20, 'bottom' => 15, 'left' => 20], privacyMode: true, ); $response->saveAs(storage_path('app/invoices/inv-' . $invoice->id . '.pdf'));
Option B: Manual Base64 Encoding
If you need full control, encode the HTML yourself and set isBase64: true:
$html = view('invoices.pdf-template', $data)->render(); $response = AvraAPI::utilities()->generatePdf( html: base64_encode($html), isBase64: true, ); $response->saveAs(storage_path('app/invoices/invoice.pdf'));
How It Works
- The SDK sends the Base64 string in the
htmlfield withis_base64: true. - The server decodes the Base64 content before validation and rendering.
- The 512 KB size limit applies to the decoded HTML, not the encoded payload.
Saving Files to Disk
BinaryResponse has a built-in saveAs() that creates directories automatically:
// Save with Laravel's storage_path helper: $response = AvraAPI::utilities()->generatePdf($html); $savedPath = $response->saveAs(storage_path('app/invoices/invoice.pdf')); echo "Saved to: {$savedPath}"; // BinaryResponse also provides: $response->body; // Raw binary string $response->contentType; // 'application/pdf' $response->size; // Size in bytes $response->isPdf(); // true $response->toDataUri(); // 'data:application/pdf;base64,...' // Stream in a controller response: return response($response->body, 200, [ 'Content-Type' => $response->contentType, 'Content-Disposition' => 'attachment; filename="invoice.pdf"', ]);
VPN & Proxy Shield
Detect VPNs, proxies, Tor exit nodes, iCloud Private Relay, and hosting/datacenter IPs.
use Avraapi\Laravel\Facades\AvraAPI; $result = AvraAPI::security()->checkVpn('8.8.8.8'); echo $result->data['ip_address']; // '8.8.8.8' echo $result->data['is_vpn']; // false echo $result->data['is_proxy']; // false echo $result->data['is_tor']; // false echo $result->data['is_relay']; // false echo $result->data['is_hosting']; // false echo $result->data['country_code']; // 'US' echo $result->data['city']; // 'Mountain View' echo $result->data['network_name']; // 'Google LLC' echo $result->data['provider_name']; // 'vpnapi' or 'iplocate' // Use in a middleware or controller: $d = $result->data; if ($d['is_vpn'] || $d['is_proxy'] || $d['is_tor']) { abort(403, 'VPN/Proxy access is not permitted.'); }
Burner Email Shield
Detect temporary and disposable email addresses using a dual-list Redis lookup (7,000+ domains).
$result = AvraAPI::security()->checkBurnerEmail('user@mailinator.com'); echo $result->data['email']; // 'user@mailinator.com' echo $result->data['domain']; // 'mailinator.com' echo $result->data['is_valid_syntax']; // true echo $result->data['is_disposable']; // true echo $result->data['source']; // 'global', 'custom', or 'none' echo $result->data['execution_time_ms']; // 0.42 // Guard a registration form in a controller: if ($result->data['is_disposable']) { return back()->withErrors(['email' => 'Disposable emails are not allowed.']); }
Multi-Currency Rates & Conversion
Free currency exchange rate API — 160+ currencies, 2-hour cached rates, zero credit cost.
Get All Currency Codes
$result = AvraAPI::currency()->getCodes(); echo $result->data['count']; // 161 foreach ($result->data['codes'] as $c) { echo "{$c['code']} — {$c['name']}\n"; // 'USD — United States Dollar' }
Get Latest Rates from a Base Currency
$result = AvraAPI::currency()->getLatestRates('USD'); echo $result->data['base']; // 'USD' echo $result->data['last_updated']; // '2025-05-10T...' echo $result->data['rates']['EUR']; // 0.89123456 echo $result->data['rates']['LKR']; // 298.50000000
Get Pair Rate
$result = AvraAPI::currency()->getPairRate('USD', 'EUR'); echo $result->data['rate']; // 0.89123456 echo $result->data['last_updated']; // '2025-05-10T...'
Convert an Amount
$result = AvraAPI::currency()->convert('USD', 'LKR', 100.00); $d = $result->data; echo "{$d['amount']} {$d['base']} = {$d['conversion_result']} {$d['target']}"; // "100 USD = 29850.000000 LKR"
Privacy Mode
For sensitive documents (invoices, contracts, PII), enable privacy mode to exclude HTML content from observability logs:
$response = AvraAPI::utilities()->generatePdf($html, privacyMode: true); $response->saveAs(storage_path('app/confidential/report.pdf'));
Error Handling
All SDK exceptions propagate through the Facade and can be caught in controllers or registered in Laravel's exception handler:
use Avraapi\Apix\Exceptions\ApixAuthenticationException; use Avraapi\Apix\Exceptions\ApixInsufficientFundsException; use Avraapi\Apix\Exceptions\ApixRateLimitException; use Avraapi\Apix\Exceptions\ApixValidationException; use Avraapi\Apix\Exceptions\ApixException; try { $response = AvraAPI::utilities()->generatePdf($html); $response->saveAs(storage_path('app/invoice.pdf')); } catch (ApixRateLimitException $e) { // HTTP 429 — retry later return back()->with('error', 'Rate limited. Please try again shortly.'); } catch (ApixInsufficientFundsException $e) { // HTTP 402 — top up wallet return back()->with('error', 'Insufficient balance.'); } catch (ApixValidationException $e) { // HTTP 422 — bad input return back()->withErrors($e->getValidationErrors()); } catch (ApixException $e) { // Catch-all report($e); return back()->with('error', 'PDF generation failed.'); }
Registering in Laravel's Exception Handler
// bootstrap/app.php (Laravel 11+) or app/Exceptions/Handler.php use Avraapi\Apix\Exceptions\ApixValidationException; use Avraapi\Apix\Exceptions\ApixException; $exceptions->render(function (ApixValidationException $e) { return response()->json([ 'error' => $e->getErrorCode(), 'message' => $e->getMessage(), 'fields' => $e->getValidationErrors(), ], 422); }); $exceptions->render(function (ApixException $e) { return response()->json([ 'error' => $e->getErrorCode(), 'message' => $e->getMessage(), 'request_id' => $e->getRequestId(), ], $e->getHttpStatus() ?: 500); });
Documentation
For full API reference, usage guides, and interactive examples, visit:
https://avraapi.com/developers/sdks
License
avraapi/laravel-sdk 适用场景与选型建议
avraapi/laravel-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「pdf」 「sdk」 「barcode」 「laravel」 「facade」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 avraapi/laravel-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 avraapi/laravel-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 avraapi/laravel-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
Provides TCPDF integration for Symfony
A adapter for the mPDF print library
A PDF builder using HTML or DOCX templates.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 43
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-04