hskyzhou/umeng

laravel 的 umeng

1.2 2017-08-24 05:53 UTC

This package is auto-updated.

Last update: 2024-08-29 04:14:40 UTC


README

##安装 composer require hskyzhou/umeng

配置

将此包添加到你的应用服务提供者中,在 config/app.php 文件中。

'providers' => [
    
    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    ...
    
    /**
     * Third Party Service Providers...
     */
    HskyZhou\Umeng\ServiceProvider::class,

],

将此包添加到你的别名中,在 config/app.php 文件中。

'aliases' => [
    
    /**
     * Third Party Service Providers...
     */
    'AppNotification' => HskyZhou\Umeng\Facades\AppNotificationFacade::class

],

使用

    //调用ios
    $ios = AppNotification::ios();
    $android = AppNotification::android();
    
    //必要参数
    $predefined = [];
    //额外字段
    $extraField = [];
    
    //单播
    $iosUnicast = AppNotification::ios()->unicast($predefined, extraField);
    $androidUnicast = AppNotification::android()->unicast($predefined, extraField);

    //列播
    $iosUnicast = AppNotification::ios()->listcast($predefined, extraField);
    $androidUnicast = AppNotification::android()->listcast($predefined, extraField);

    //组播
    $iosUnicast = AppNotification::ios()->groupcast($predefined, extraField);
    $androidUnicast = AppNotification::android()->groupcast($predefined, extraField);

    //文件播
    $iosUnicast = AppNotification::ios()->filecast($predefined, extraField);
    $androidUnicast = AppNotification::android()->filecast($predefined, extraField);

    //广播
    $iosUnicast = AppNotification::ios()->broadcast($predefined, extraField);
    $androidUnicast = AppNotification::android()->broadcast($predefined, extraField);

    //自定义播
    $iosUnicast = AppNotification::ios()->customizedcast($predefined, extraField);
    $androidUnicast = AppNotification::android()->customizedcast($predefined, extraField);
    
    //ios可以重新设置值
    $iosUnicast = AppNotification::ios()->unicast();
    //设置值
    $iosUnicast->setPredefinedKeyValue('name', 'hsky');
    //设置额外值
    $iosUnicast->setCustomizedField('name', 'hsky');
    
    //android重新设置值
    $androidUnicast = AppNotification::android()->unicast();
    //设置值
    $iosUnicast->setPredefinedKeyValue('name', 'hsky');
    //设置额外值
    $iosUnicast->setExtraField('name', 'hsky');
    

示例

  1. 向iOS用户单独发送一条消息
    $predefined = [
        "device_tokens" =>  "d14f29e47c098fd9429fdc56d4da2d3cef69914db7da179419f17188e3a7e80d",
        "alert" => "IOS 单播测试", 
        "badge" => 0,
        "sound" => "chime",
        "production_mode" => "false",
    ];

    $extraField = [
        "url" => "http://www.baidu.com",
        "isapp" => "true",
    ];

    AppNotification::ios()->unicast($predefined, $extraField)->send();