基於umeng官方phpsdkv1.4,支援Laravel5以及Lumen5

shadowalker_wei發表於2018-05-05

安裝

    composer require zzl/umeng   

Laravel 5.* 配置

開啟config目錄下的app.php檔案,找到provider,新增如下程式碼:

    `provider` => [
       ZzlUmengUmengServiceProvider::class, 
    ],

配置alias:

    `aliases` => [
        `Umeng` => ZzlUmengFacadesUmeng::class,
    ],

生成配置檔案:

    php artisan vendor:publish   

在配置檔案umeng.php中填入appkey以及master_secret既可完成配置

在Lumen 5.*中配置

開啟bootstrap目錄下的app.php檔案,註冊provider:

    $app->register(ZzlUmengUmengServiceProvider::class);

配置alias:

    class_alias(`ZzlUmengFacadesUmeng`,`Umeng`);

生成配置檔案:

    php artisan vendor:publish 

在配置檔案umeng.php中填入appkey以及master_secret既可完成配置

用法

Android用法:


    use Umeng;

    $device_token = `xxxx`;
    $predefined = array(`ticker` => `android ticker` ,...);
    $extraField = array(); //other extra filed
    Umeng::android()->sendUnicast($device_token,$predefined,$extraField); //單播

IOS用法:


    use Umeng;

    $device_token = `xxxx`;
    $predefined = array(`alert` => `ios alert` ,...);
    $customField = array(); //other custom filed
    Umeng::ios()->sendUnicast($device_token,$predefined,$customField); //單播

Api

說明: Android API跟 IOS一樣


    sendBroadcast($predefined = [], $extraField = []); //廣播
    sendUnicast($device_tokens = ``, $predefined= [], $extraField = []); //單播
    sendListcast($device_tokens = ``, $predefined= [], $extraField = []); //列播
    sendFilecast($fileContents = ``, $predefined= [],$extraField = []); //檔案播
    sendGroupcast($filter = [], $predefined= [], $extraField = []); //組播
    sendCustomizedcast($alias = ``, $alias_type = ``, $predefined= [], $extraField = []); //自定義播,通過alias
    sendCustomizedcastFileId($file_contents = ``, $predefined= [], $extraField = []); //自定義播,通過file_id

Exception

程式不處理異常,可根據業務情況自行處理, 若丟擲異常,可通過 e->getHttpCode() 獲取http狀態碼, 通過 e->getErrCode()獲取umeng返回的錯誤碼. 使用過程中若出錯,可自行檢視Laravel或Lumen的Log日誌


相關文章