定制 kazinokib/bdappsapi 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kazinokib/bdappsapi

最新稳定版本:1.0.0

Composer 安装命令:

composer require kazinokib/bdappsapi

包简介

A Laravel package for BDApps API integration

README 文档

README

This Laravel package provides an easy-to-use interface for integrating with the BDApps API, allowing you to send SMS, handle USSD sessions, manage OTP, and perform CAAS operations in your Laravel applications.

Table of Contents

  1. Installation
  2. Configuration
  3. Usage
  4. Error Handling
  5. Contributing
  6. License

Installation

You can install the package via composer:

composer require kazinokib/bdappsapi

Configuration

After installation, publish the configuration file:

php artisan vendor:publish --provider="Kazinokib\BdappsApi\BdappsApiServiceProvider" --tag="config"

This will create a config/bdappsapi.php file in your app's configuration directory. You should configure your BDApps API credentials in your .env file:

BDAPPS_APP_ID=your_app_id
BDAPPS_APP_PASSWORD=your_app_password
BDAPPS_BASE_URL=https://developer.bdapps.com

Usage

SMS Service

To send an SMS:

use Kazinokib\BdappsApi\BdappsApi;

public function sendSms(BdappsApi $bdappsApi)
{
    $result = $bdappsApi->smsService->send('Your message', ['tel:8801812345678']);
    // Handle the result
}

Receive SMS

use Kazinokib\BdappsApi\BdappsApi;

public function receiveSms(BdappsApi $bdappsApi)
{
    $result = $bdappsApi->smsService->receiveSms();
    // Handle the result
}

USSD Service

To send a USSD message:

use Kazinokib\BdappsApi\BdappsApi;

public function sendUssd(BdappsApi $bdappsApi)
{
    $result = $bdappsApi->ussdService->send('Your message', 'session_id', 'tel:8801812345678');
    // Handle the result
}

OTP Service

To request an OTP:

use Kazinokib\BdappsApi\BdappsApi;

public function requestOtp(BdappsApi $bdappsApi)
{
    $result = $bdappsApi->otpService->requestOtp('tel:8801812345678');
    // Handle the result
}

To verify an OTP:

use Kazinokib\BdappsApi\BdappsApi;

public function verifyOtp(BdappsApi $bdappsApi)
{
    $result = $bdappsApi->otpService->verifyOtp('reference_no', 'otp_code');
    // Handle the result
}

CAAS Service

To query balance:

use Kazinokib\BdappsApi\BdappsApi;

public function queryBalance(BdappsApi $bdappsApi)
{
    $result = $bdappsApi->caasService->queryBalance('tel:8801812345678');
    // Handle the result
}

To perform a direct debit:

use Kazinokib\BdappsApi\BdappsApi;

public function directDebit(BdappsApi $bdappsApi)
{
    $result = $bdappsApi->caasService->directDebit('external_tx_id', 'tel:8801812345678', 10.00);
    // Handle the result
}

Error Handling

All services throw a BdappsApiException on error. You should catch this exception and handle it appropriately:

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();
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-14