Require this package with composer:
composer require songshenzong/aliyun-dysms
/**
* If Laravel, Please write these fields in the `env` file
*/
ALIYUN_DYSMS_KEY=yourAccessKeyId
ALIYUN_DYSMS_SECRET=yourAccessKeySecret
ALIYUN_DYSMS_SIGN=yourSignName
/**
* If not Laravel, You have to run these methods first.
*/
AliyunSms::setAccessKeyId('yourAccessKeyId');
AliyunSms::setAccessKeySecret('yourAccessKeySecret');
AliyunSms::setSignName('yourSignName');
// Send SMS without `SignName` if used `setSignName`.
$response = AliyunSms::sendSms('18888888888', 'SMS_12345678', ['code' => 12345]);
// Send in bulk, no more than 1000 phone numbers.
$response = AliyunSms::sendSms('18888888888,17777777777', 'SMS_12345678', ['code' => 12345]);
$response = AliyunSms::sendBatchSms(['1500000000', '1500000001'], ['云通信', '云通信'], 'SMS_12345678', [['code' => '123'], ['code' => '456']]);
// Get Result
if (AliyunSms::ok($response)) {
echo 'OK';
} else {
echo 'Failed';
}
Publish configuration files. If not, They can not be serialized correctly when you execute the config:cache
Artisan command.
php artisan vendor:publish --provider="Songshenzong\AliyunSms\ServiceProvider"
AliyunSendSmsJob::dispatch('18888888888', "SMS_12345678", ['code' => 520])->onQueue('sms');
AliyunSendSmsJob::dispatchNow('18888888888', "SMS_12345678", ['code' => 520]);
/**
* Get the notification's delivery channels.
*
* @param $notifiable
*
* @return array
*/
public function via($notifiable): array
{
return [AliyunBatchSmsChannel::class, AliyunSmsChannel::class];
}
/**
* @param $notifiable
*
* @return mixed
*/
public function toAliyunSMS($notifiable)
{
return AliyunSms::sendSms('18888888888', 'SMS_12345678', ['code' => 12345]);
}
/**
* @param $notifiable
*
* @return mixed
*/
public function toAliyunBatchSMS($notifiable)
{
return AliyunSms::sendBatchSms(['1500000000', '1500000001'], ['云通信', '云通信'], 'SMS_12345678', [['code' => '123'], ['code' => '456']]);
}
See: https://help.aliyun.com/document_detail/55359.html
Please refer to our extensive Wiki documentation for more information.
For answers you may not find in the Wiki, avoid posting issues. Feel free to ask for support on Songshenzong.com
This package is licensed under the BSD 3-Clause license.