kozino / bdappsapi
Laravel 的 BDApps API 集成包
1.0.0
2024-09-15 09:04 UTC
Requires
- php: ^7.3|^8.0|^8.1|^8.2
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0
This package is auto-updated.
Last update: 2024-09-15 09:08:28 UTC
README
此 Laravel 包提供了一个易于使用的接口,用于集成 BDApps API,使您能够在 Laravel 应用程序中发送短信、处理 USSD 会话、管理 OTP 以及执行 CAAS 操作。
目录
安装
您可以通过 composer 安装此包
composer require kazinokib/bdappsapi
配置
安装后,发布配置文件
php artisan vendor:publish --provider="Kazinokib\BdappsApi\BdappsApiServiceProvider" --tag="config"
这将在您的应用程序配置目录中创建一个 config/bdappsapi.php
文件。您应该在 .env
文件中配置您的 BDApps API 凭据
BDAPPS_APP_ID=your_app_id
BDAPPS_APP_PASSWORD=your_app_password
BDAPPS_BASE_URL=https://developer.bdapps.com
使用
短信服务
发送短信
use Kazinokib\BdappsApi\BdappsApi; public function sendSms(BdappsApi $bdappsApi) { $result = $bdappsApi->smsService->send('Your message', ['tel:8801812345678']); // Handle the result }
接收短信
use Kazinokib\BdappsApi\BdappsApi; public function receiveSms(BdappsApi $bdappsApi) { $result = $bdappsApi->smsService->receiveSms(); // Handle the result }
USSD 服务
发送 USSD 消息
use Kazinokib\BdappsApi\BdappsApi; public function sendUssd(BdappsApi $bdappsApi) { $result = $bdappsApi->ussdService->send('Your message', 'session_id', 'tel:8801812345678'); // Handle the result }
OTP 服务
请求 OTP
use Kazinokib\BdappsApi\BdappsApi; public function requestOtp(BdappsApi $bdappsApi) { $result = $bdappsApi->otpService->requestOtp('tel:8801812345678'); // Handle the result }
验证 OTP
use Kazinokib\BdappsApi\BdappsApi; public function verifyOtp(BdappsApi $bdappsApi) { $result = $bdappsApi->otpService->verifyOtp('reference_no', 'otp_code'); // Handle the result }
CAAS 服务
查询余额
use Kazinokib\BdappsApi\BdappsApi; public function queryBalance(BdappsApi $bdappsApi) { $result = $bdappsApi->caasService->queryBalance('tel:8801812345678'); // Handle the result }
执行直接借记
use Kazinokib\BdappsApi\BdappsApi; public function directDebit(BdappsApi $bdappsApi) { $result = $bdappsApi->caasService->directDebit('external_tx_id', 'tel:8801812345678', 10.00); // Handle the result }
错误处理
所有服务在出错时都会抛出 BdappsApiException
。您应该捕获此异常并适当处理
use Kazinokib\BdappsApi\Exceptions\BdappsApiException; try { $result = $bdappsApi->smsService->send('Your message', ['tel:8801812345678']); } catch (BdappsApiException $e) { // Handle the exception $errorCode = $e->getErrorCode(); $errorDetail = $e->getErrorDetail(); }
贡献
欢迎贡献!请随意提交 Pull Request。
许可证
此软件包是开源软件,受 MIT 许可证 许可。