PHP code example of goletter / hyperf-sms
1. Go to this page and download the library: Download goletter/hyperf-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/ */
goletter / hyperf-sms example snippets
return [
// 默认驱动
'default' => 'aliyun',
'driver' => [
'aliyun' => [
'name' => '阿里云短信',
'driver' => \Goletter\Sms\Driver\Aliyun::class,
'config' => [
'accessKeyId' => '',
'accessKeySecret' => '',
'regionId' => '',
'signName' => '',
]
],
'qiniu' => [
// 驱动名称
'name' => '七牛云短信',
'driver' => \Goletter\Sms\Driver\Qiniu::class,
// 驱动初始化参数
'config' => [
'access_key' => '',
'secret_key' => '',
]
],
'smschinese' => [
'name' => '中国网建',
'driver' => \Goletter\Sms\Driver\Smschinese::class,
'config' => [
'uid' => '',
'key' => '',
]
],
]
];
use function Goletter\Sms\sms;
sms()->send('18888888888', [
'template' => 'xxx',
'content' => '您的验证码是1234,该验证码1分钟内有效,请勿泄漏于他人!',
'data' => [
'code' => '1234'
]
]);
use Goletter\Sms\Contract\SmsInterface;
$sms = di(SmsInterface::class);
$sms->send('18888888888', [
'template' => 'xxx',
'content' => '您的验证码是1234,该验证码1分钟内有效,请勿泄漏于他人!',
'data' => [
'code' => '1234'
]
]);
use function Goletter\Sms\sms;
sms()->getName();
sms()->getDriver();
$sms = \Goletter\Sms\Facade\Sms::driver('qiniu');
// 或
// $sms = \Webguosai\HyperfSms\Facade\Sms::make('qiniu');
$sms->send('18888888888', [
'template' => 'xxx',
'content' => '您的验证码是1234,该验证码1分钟内有效,请勿泄漏于他人!',
'data' => [
'code' => '1234'
]
]);
use function Goletter\Sms\sms;
sms()->send('18888888888', [
'content' => function($driver){
if ($driver == 'aliyun') {
return '云片专用验证码:1235';
}
return '您的验证码为: 6379';
},
'template' => function($driver){
if ($driver == 'aliyun') {
return '1888883905033940992';
}
return 'SMS_001';
},
'data' => function($driver){
return [
'code' => 6379
];
}
]);
bash
php bin/hyperf.php vendor:publish goletter/hyperf-sms