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 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.
}