PHP code example of wantp / laravel-dingtalk-notification-channel

1. Go to this page and download the library: Download wantp/laravel-dingtalk-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/ */

    

wantp / laravel-dingtalk-notification-channel example snippets




namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Wantp\Notifications\Messages\DingTalkMessage;
use Wantp\Notifications\Messages\Message;

class YourNotification extends Notification
{
    use Queueable;

    public function via()
    {
        return ['dingtalk'];
    }

    public function toDingTalk($notifiable)
    {
        return (new DingTalkMessage())
            ->title('研发部测试通知')
            ->body('研发部测试通知,收到请忽略');

    }
}




namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notification;

class User extends Authenticatable
{
    use Notifiable;

    ...

    public function dingTalkUser()
    {
        return $this->hasOne(DingTalkUser::class);
    }

    public function routeNotificationForDingTalk(Notification $notification)
    {
        return $this->dingTalkUser->ding_talk_user_id;
    }
}



$users = User::find(1);

$users->notify(new YourNotificationNotification());

$users = User::take(2)->get();

Notification::send($users, new ApplicationApproveNotification());


Notification::route('dingtalk', ['user_id_1', 'user_id_2'])->notify(new ApplicationApproveNotification());



namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Wantp\Notifications\Messages\DingTalkMessage;
use Wantp\Notifications\Messages\Message;

class YourNotification extends Notification
{
    use Queueable;

    public function via()
    {
        return ['dingtalk'];
    }

    public function toDingTalk($notifiable)
    {
        return (new DingTalkMessage())
            ->link()
            ->title('研发部测试通知')
            ->body('研发部测试通知,收到请忽略')
            ->msgUrl('http://laravel.test/messages/1')
            ->msgPicUrl('http://laravel.test/message/pictures/1');

    }
}
shell script
$ php artisan vendor:publish