PHP code example of moocky / aliyunsms

1. Go to this page and download the library: Download moocky/aliyunsms library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moocky / aliyunsms example snippets


namespace App\Http\Controllers;

use Moocky\Aliyunsms\Contracts\Aliyunsms;
....

class IndexController extends Controller
{
  /**
   * Show the application dashboard.
   * 
   * @param \Moocky\Aliyunsms\Contracts\Aliyunsms $aliyunsms 注入
   */
  public function index(Aliyunsms $aliyunsms)
  {
    # 发送普通短信
    #
    # $phone 手机号
    # $templateCode 短信模板
    # $templateParam 短信参数
    # $type 短信类型,默认为normal

    $aliyunsms->send('13888888888','SMS_112233445566',['rand' => 123456],'normal');
    $aliyunsms->send('13888888888','SMS_556677889900');
  }
  public function send()
  {
    # 发送普通短信
    #
    # $phone 手机号
    # $templateCode 短信模板
    # $templateParam 短信参数
    # $type 短信类型,默认为normal

    app('aliyunsms')->send('13888888888','SMS_112233445566',['rand' => 123456],'normal');
    app('aliyunsms')->send('13888888888','SMS_556677889900');
  }
  public function verification()
  {
    # 发送验证码
    #
    # $phone 手机号
    # $type 验证码类型,默认为verification
    app('aliyunsms')->verification('13888888888','verification');
    app('aliyunsms')->verification('13888888888');
  }
  public function verify()
  {
    # 校验验证码
    #
    # $phone 手机号
    # $rand 验证码
    # $type 验证码类型,默认为verification
    # $expires 验证码有效时间,默认为600秒
    app('aliyunsms')->verify('13888888888','123456','verification',1200);
    app('aliyunsms')->verify('13888888888','123456');
  }
}

use Moocky\Aliyunsms\Aliyunsms;

$config = [
	'access_key_id' => 'your access key',
	'access_key_secret' => 'your access secret',
	'sign_name' => 'your sign name',
	'endpoint' => 'endpoint',
	'template_code' => 'SMS_112233445566',
	'sms_log_table' => 'sms_log',
];

# 发送普通短信
#
# $phone 手机号
# $templateCode 短信模板
# $templateParam 短信参数
# $type 短信类型,默认为normal
$aliyunsms = new Aliyunsms($config);
$aliyunsms->send('13888888888','SMS_112233445566',['rand' => 123456],'normal');
$aliyunsms->send('13888888888','SMS_556677889900');

# 发送验证码
#
# $phone 手机号
# $type 验证码类型,默认为verification
$aliyunsms = new Aliyunsms($config);
$aliyunsms->verification('13888888888','verification');
$aliyunsms->verification('13888888888');

# 校验验证码
#
# $phone 手机号
# $rand 验证码
# $type 验证码类型,默认为verification
# $expires 验证码有效时间,默认为600秒
$aliyunsms = new Aliyunsms($config);
$aliyunsms->verify('13888888888','123456','verification',1200);
$aliyunsms->verify('13888888888','123456');
BASH
php artisan vendor:publish --provider=Moocky\Aliyunsms\Providers\LaravelServiceProvider
BASH
php artisan aliyunsms:table
php artisan migrate:install