PHP code example of grantholle / aliyun-sms-notification-channel

1. Go to this page and download the library: Download grantholle/aliyun-sms-notification-channel 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/ */

    

grantholle / aliyun-sms-notification-channel example snippets


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

use GrantHolle\Notifications\Channels\AliyunSmsChannel;

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



namespace App\Notifications;

use Illuminate\Notifications\Notification;
use GrantHolle\Notifications\Messages\AliyunMessage;
use App\Order;

class OrderPaid extends Notification
{
    protected $order;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['aliyun'];
    }

    /**
     * Get the Aliyun SMS representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \GrantHolle\Notifications\Messages\AliyunMessage
     */
    public function toAliyunSms($notifiable)
    {
        return (new AliyunMessage)
            ->template('SMS_XXXXXXX')
            ->data([
                'order_no' => $this->order->order_no,
                'total' => $this->order->total,
            ]);
    }
}



namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the Aliyun SMS channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForAliyun($notification)
    {
        return $this->phone;
    }
}

use App\Notifications\OrderPaid;

$user->notify(new OrderPaid($order));
bash
php artisan make:notification OrderPaid