PHP code example of papayacloud / laravel-sms

1. Go to this page and download the library: Download papayacloud/laravel-sms 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/ */

    

papayacloud / laravel-sms example snippets


composer 

iBrand\Sms\ServiceProvider::class

'Sms'=> iBrand\Sms\Facade::class

use iBrand\Sms\Facade as Sms;

Sms::send(request('mobile'));

use iBrand\Sms\Facade as Sms;

Sms::send(request('mobile'), [
    'content'  => '您的验证码为: 83115',
    'template' => 'SMS_001',
    'data' => [
        'code' => 83115
    ],
]);

use iBrand\Sms\Facade as Sms;

Sms::send((request('mobile'), [
    'content'  => '您的验证码为: 83115',
    'template' => 'SMS_001',
    'data' => [
        'code' => 83115
    ],
], ['aliyun']); // 这里的网关配置将会覆盖全局默认


    
use Overtrue\EasySms\Message;
use Overtrue\EasySms\Contracts\GatewayInterface;

class CustomMessage extends Message
{
    protected $code;
    protected $gateways = ['yuntongxun']; //在sms.php配置文件中添加gateways选项: yuntongxun
    //...

    public function __construct($code)
    {
        $this->code = $code;
    }

    // 定义直接使用内容发送平台的内容
    public function getContent(GatewayInterface $gateway = null)
    {
    	
    }

    // 定义使用模板发送方式平台所需要的模板 ID
    public function getTemplate(GatewayInterface $gateway = null)
    {
        return 'templateId';
    }

    // 模板参数
    public function getData(GatewayInterface $gateway = null)
    {
        return [
            $this->code,
            //...
        ];    
    }
}

use iBrand\Sms\Facade as Sms;
$code = Sms::getNewCode(request('mobile'));
$message = new CustomMessage($code->code);

Sms::send(request('mobile'), $message, ['yuntongxun']);

use iBrand\Sms\Facade as Sms;

if (!Sms::checkCode(\request('mobile'), \request('code'))) {
    //Add you code.
}

    // 可用的网关配置
        'gateways' => [

            'errorlog' => [
                'file' => '/tmp/easy-sms.log',
            ],

            'yunpian' => [
                'api_key' => '824f0ff2f71cab52936axxxxxxxxxx',
            ],

            'aliyun' => [
                'access_key_id' => 'dalvTXXX',
                'access_key_secret' => 'XXXX',
                'sign_name' => '阿里云短信测试专用',
                'code_template_id' => 'SMS_80215252'
            ],

            'alidayu' => 
                //...
            ],
        ],