songshenzong/aliyun-dysms

阿里云短信SDK扩展

该包的规范仓库似乎已消失,因此该包已被冻结。

v1.0.0 2018-03-28 05:03 UTC

This package is not auto-updated.

Last update: 2019-02-28 08:27:21 UTC


README

Songshenzong

Build Status Total Downloads Latest Stable Version License PHP Version

安装

使用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';
}
 

Laravel Artisan

发布配置文件。如果不这样做,当您执行config:cache Artisan命令时,它们可能无法正确序列化。

php artisan vendor:publish --provider="Songshenzong\AliyunSms\ServiceProvider"

Laravel队列

 
AliyunSendSmsJob::dispatch('18888888888', "SMS_12345678", ['code' => 520])->onQueue('sms');
  
AliyunSendSmsJob::dispatchNow('18888888888', "SMS_12345678", ['code' => 520]);
 

Laravel通知


/**
 * 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']]);
}
 

更多用法

见:https://help.aliyun.com/document_detail/55359.html

文档

请参阅我们详尽的Wiki文档以获取更多信息。

支持

如果您在Wiki中找不到答案,请避免发布问题。您可以在Songshenzong.com上免费寻求支持。

许可证

此包根据BSD 3-Clause许可证授权。