PHPackages                             grantholle/aliyun-sms-notification-channel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. grantholle/aliyun-sms-notification-channel

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

grantholle/aliyun-sms-notification-channel
==========================================

Aliyun SMS Notification Channel for Laravel.

2.5.0(3mo ago)913.9k↓33.3%2MITPHPPHP ^7.1|^8.0|^8.1|^8.2|^8.3|^8.4CI failing

Since Jan 28Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/grantholle/aliyun-sms-notification-channel)[ Packagist](https://packagist.org/packages/grantholle/aliyun-sms-notification-channel)[ RSS](/packages/grantholle-aliyun-sms-notification-channel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (15)Used By (0)

Aliyun SMS Notification Channel
===============================

[](#aliyun-sms-notification-channel)

A Laravel notification channel for Aliyun's SMS product.

Installation
------------

[](#installation)

```
composer require grantholle/aliyun-sms-notification-channel
```

Configuration
-------------

[](#configuration)

It's preferred to include sensitive keys and secrets in the `.env` file so that the information is not included in source control.

In your `.env` file, add some keys:

```
ALIYUN_SMS_AK=XXXXXXXXXX
ALIYUN_SMS_AS=XXXXXXXXXX
ALIYUN_SMS_SIGN_NAME=名字

```

In `config/services.php`, add the following:

```
'aliyun_sms' => [
    'key' => env('ALIYUN_SMS_AK'),
    'secret' => env('ALIYUN_SMS_AS'),
    'sign' => env('ALIYUN_SMS_SIGN_NAME'),
],
```

Usage
-----

[](#usage)

### During Development

[](#during-development)

When developing your application, it may be a good idea to prevent accidentally sending SMS messages to real phone numbers. To safeguard against this, you can use the `alwaysTo` function for non-production environments.

Add this snippet in your `AppServiceProvider` to prevent spamming real people.

```
use GrantHolle\Notifications\Channels\AliyunSmsChannel;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        if (!app()->environment('production')) {
            AliyunSmsChannel::alwaysTo('your-phone-number');
        }
    }
}
```

### Create the Notification

[](#create-the-notification)

Generate a new notification for your application.

```
php artisan make:notification OrderPaid
```

Add the `aliyun` channel and the `toAliyunSms()` function to generate the Aliyun message. There is the `template()` function to set the template ID of this message, as well as a `data()` function to set the placeholders in the template.

```
