PHP code example of medz / laravel-jpush-notification-channel

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

    

medz / laravel-jpush-notification-channel example snippets


return [
    'jpush' => [
        'app_key' => env('JPUSH_APP_KEY', ''),
        'master_secret' => env('JPUSH_MASTER_SECRET', ''),
        'apns_production' => env('JPUSH_APNS_PRODUCTION', false),
    ],
]

use Illuminate\Foundation\Auth\User as Authenticatable;
use Medz\Laravel\Notifications\JPush\Sender as JPushSender;

class User extends Authenticatable
{
    /**
     * Get Notification for JPush sender.
     * @return \Medz\Laravel\Notifications\JPush\Sender
     */
    protected function routeNotificationForJpush()
    {
        return new JPushSender([
            'platform' => 'all',
            'audience' => [
                'alias' => sprintf('user_%d', $this->id),
            ],
        ]);
    }
}



namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Medz\Laravel\Notifications\JPush\Message as JPushMessage;

class CommentNotification extends Notification
{
    public function toJpush($notifiable)
    {
        $message = new JPushMessage();
        // TODO

        /*
            ====== 把所有的配置都进行配置 ===
            $message->setAlert('Alert.'); // 简单地给所有平台推送相同的 alert 消息

            // 自定义消息
            $message->setMessage('Message', [
                'title' => '', // 通知标题,会填充到 toast 类型 text1 字段上
                '_open_page' => '', 点击打开的页面名称
                'extras' => [], // 自定义的数据内容
            ]);

            // iOS 通知
            $message->setNotification(JPushMessage::IOS, 'Alert 内容', [
                'alert' => '', // 覆盖第二个参数的 Alert 内,推荐不传,
                'sound' => '', // 表示通知提示声音,默认填充为空字符串
                'badge' => '', // 表示应用角标,把角标数字改为指定的数字;为 0 表示清除,支持 '+1','-1' 这样的字符串,表示在原有的 badge 基础上进行增减,默认填充为 '+1'
                /// ...
            ])

            // 更多通知请参考 https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#notification 官方文档
            // 使用 `setNotification` 方法第一个常量有三个: IOS/ANDROID/WP

            // 可选参数
            $message->setOptions([]); // 参考 https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#options
        */

        return $message
    }
}

public function via()
{
    return ['database', 'jpush'];
}