Configure and use Easy SMS
masterInitialize EasySms with a configuration array. The configuration includes a timeout for HTTP requests, a default section to define the gateway calling strategy and the list of gateways to use, and a gateways section containing the specific credentials for each provider.
To send a message, use the send method with the recipient's phone number and an array containing content, template, and data.
use Overtrue//EasySms\EasySms;
$config = [
// HTTP request timeout in seconds
'timeout' => 5.0,
// Default sending configuration
'default' => [
// Gateway calling strategy, default: OrderStrategy
'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,
// Default available gateways
'gateways' => [
'yunpian', 'aliyun',
],
],
// Configuration for available gateways
'gateways' => [
'errorlog' => [
'file' => '/tmp/easy-sms.log',
],
'yunpian' => [
'api_key' => '824f0ff2f71cab52936axxxxxxxxxx',
],
'aliyun' => [
'access_key_id' => '',
'access_key_secret' => '',
'sign_name' => '',
],
//...
],
];
$easySms = new EasySms($config);
$easySms->send(13188888888, [
'content' => '您的验证码为: 6379',
'template' => 'SMS_001',
'data' => [
'code' => 6379
],
]);