softbread/alidayu-php-sdk

Provides an implelmentation of Ali Dayu SMS SDK that uses Guzzle 6 and Composer

1.0.1 2016-09-08 14:43 UTC

This package is not auto-updated.

Last update: 2024-04-13 17:29:56 UTC


README

This is a PHP SDK for Ali Dayu based on Guzzle 6.

This project is inspired by another PHP curl reversion for Ali Dayu -- https://github.com/Verytops/alisms

一个简单的阿里大于短信发送的PHP SDK。如果项目已经有composer, 安装使用就更简单了。 本SDK是因为本人看到 https://github.com/Verytops/alisms 项目而受到启发, 然后决定为composer重写。 写得很赶, 很多东西没有按正规的composer project来写, 欢迎pull 或者 fork

##1. Pre-Request

  • Composer
  • PHP5.5+

##2. Install

composer require softbread/alidayu-php-sdk:dev-master

##3. Typical Usage

###a. Use setters:

$sendSms = new Softbread\AlidayuSdk\AliSms;
$sendSms->setEnv(false); // use sandbox or not
$sendSms->setKey('api_key'); // set API key
$sendSms->setSecret('api_secret'); // set API secret
$sendSms->setSmsSign('sms_free_sign'); // set free sign in SMS content
$sendSms->setTemplateParams([
  'param1' => 'var1',
  'param2' => 'var2',
]); // set template params
$sendSms->setTemplate('template_id'); // set template ID
$sendSms->setSmsMobile('13000000000'); // set mobile number
$sendSms->send();

###b. Use callable function for easier dependency injection

$sendSms = new Softbread\AlidayuSdk\AliSms([
    'env'    => false,
    'key'    => 'api_key',
    'secret' => 'api_secret',
]); // inject config as array

$sendSms->send(
    '13000000000',  // mobile number
    'sms_free_sign' , // free sign in SMS content
    'template_id',  // template ID
    [
      'param1' => 'var1',
      'param2' => 'var2',
    ]  // template params
);

##4. To-do

  • Add Voice-Text message
  • Add unit tests
  • Improve exception detection and handling