acidf0x/laracool

Laravel 的 CoolSMS SDK 包装器

v1.0.0 2018-09-13 05:53 UTC

This package is not auto-updated.

Last update: 2024-09-21 11:17:44 UTC


README

CoolSMS PHP SDK 包装器,适用于 Laravel

安装

使用 composer 进行安装

 composer require acidf0x/laracool

然后使用 Artisan 发布包配置

 php artisan vendor:publish --provider=AcidF0x\LaraCool\CoolSMSServiceProvider

在生成的 app/config/coolsms.php 配置文件中更新您的设置。

return [
    // api_key and api_secret can be obtained from coolsms.co.kr
    'api' => [
        'key' => 'YOUR_API_KEY',
        'secret' => 'YOUR_API_SECRET',
    ],
];

AcidF0x\LaraCool\CoolSMSServiceProvider 默认会自动发现和注册,但如果您想自己注册它:在 config/app.php 中添加 ServiceProvider

'providers' => [
    ...
    ...
    AcidF0x\LaraCool\CoolSMSServiceProvider::class,
]

CoolSMS 门面也会自动发现,但如果您想手动添加它:在 config/app.php 中添加 Facade

'aliases' => [
    ...
    'CoolSMS' => AcidF0x\LaraCool\Facades\CoolSMS::class,
]

基本用法

use AcidF0x\LaraCool\Facades\CoolSMS;
use Nurigo\Exceptions\CoolsmsException;

  try {
      // 4 options(to, from, type, text) are mandatory. must be filled
      $options = new \stdClass();
      $options->to = '01000000000';
      $options->from = '0100000000';
      $options->type = 'SMS';
      $options->text = 'text';
      $result = CoolSMS::message()->send($options);
      dump($result);
  } catch (CoolsmsException $e) {
      dump($e->getMessage()); // get error message
      dump($e->getResponseCode()); // get 'api.coolsms.co.kr' response code
  }

查看详情 CoolSMS SDK 示例

CoolSMS::message() // return \Nurigo\Api\Message
CoolSMS::groupMessage() // return \Nurigo\Api\GroupMessage
CoolSMS::image() // \Nurigo\Api\Image
CoolSMS::senderID() // \Nurigo\Api\SenderID

要求

  • Laravel 5.*
  • PHP 5.5 或更高版本
  • Composer
  • PHP CURL 扩展
  • PHP JSON 扩展