PHP code example of cncal / getui

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

    

cncal / getui example snippets


    Cncal\Getui\GetuiServiceProvider::class,
    

    'Getui' => Cncal\Getui\Facades\Getui::class,
    

$ php artisan vendor:publish --provider="Cncal\Getui\GetuiServiceProvider"

// 个推基础信息,在平台新建应用的时候生成
'basic' => [
    'host' => "http://sdk.open.api.igexin.com/apiex.htm",
    'app_id' => "",
    'app_key' => "",
    'master_secret' => "",
],

// 推送消息的基础设置
'push' => [
    'is_ring' => true,  //是否响铃
    'is_vibrate' => true,  // 是否振动
    'is_clearable' => true,  // 是否可清除
    'is_offline' => true,  // 是否发送离线消息
    'offline_expire_time' => 2, // 离线消息过期时间,单位为小时(范围:0- 72),该时间段内 cid 在线过的用户均可收到通知
    'network_type' => 0,  // 是否根据网络环境推送消息,0为不限制推送,1为wifi推送,2为4G/3G/2G
],

// 队列配置
'queue' => [
    'is_used' => false, // 是否使用队列
    'connection' => env('QUEUE_DRIVER', 'sync'), // 连接
    'queue' => 'default', // 队列
],

 
use Getui;

/**
 * 推送通知至指定用户
 *
 * @param $data
 *
 * @return $rep
 */
Getui::pushMessageToSingle($data);

/**
 * 推送通知至指定用户列表
 *
 * @param $data
 *
 * @return $rep
 */
Getui::pushMessageToList($data);

/**
 * 推送通知至该应用的所有用户
 *
 * @param $data
 *
 * @return $rep
 */
Getui::pushMessageToApp($data);


       $data = [
           'template_type' => 1,
           'template_data' => [
               'title' => 'Laravel Getui',
               'text' => 'May you succeed.',
               'transmission_type' => 1,
               'transmission_content' => 'It is transmission content',
               'is_ring' => false,
               'is_clearable' => false,
               'begin_at' => date('Y-m-d H:i:s'),
               'end_at' => date('Y-m-d H:i:s', strtotime("+1 day")),
           ],
           'cid' => 'target cid',
       ];
       
 php
    $data = [
        'template_type' => 1,
        'template_data' => [
            'title' => '', // 通知标题,string(40), 必填
            'text'  => '', // 通知内容,string(600), 必填
            'logo'  => '', // 通知图标名称,string(40), 必填
            'logo_url'  => '', // 通知图标url地址,string(100), 必填
            'transmission_type'    => 2, // 是否立即启动应用:1 立即启动 2 等待客户端自启动,必填
            'transmission_content' => '', // 透传内容,不支持转义字符,string(2048), 必填
        ]
        'cid' => 'target cid', // 推送通知至指定用户时填写
        'cid_list' => ['cid1','cid2',...], // 推送通知至指定用户列表时填写
    ];
    
 php
        $data = [
            'template_type' => 2,
            'template_data' => [
                'title' => '', // 通知标题,string(40), 必填
                'text'  => '', // 通知内容,string(600), 必填
                'url'   => '', // 点击通知后打开的网页地址,string(200), 必填
                'logo'  => '', // 通知图标名称,string(40), 必填
                'logo_url'  => '', // 通知图标url地址,string(100), 必填
            ]
            'cid' => 'target cid', // 推送通知至指定用户时填写
            'cid_list' => ['cid1','cid2',...], // 推送通知至指定用户列表时填写
        ];
        
 php
        $data = [
            'template_type' => 3,
            'template_data' => [
                'title' => '', // 通知标题,string(40), 必填
                'text'  => '', // 通知内容,string(600), 必填
                'pop_title'   => '', // 弹出框标题,string(40), 必填
                'pop_content' => '', // 弹出框内容,string(600), 必填
                'pop_image'   => '', // 弹出框图标,string(200), 必填
                'load_icon'   => '', // 下载图标: 本地图标[file://], 网络图标[http:// 或 https://],string(40), 必填
                'load_title'  => '', // 下载标题,string(40), 必填
                'load_url'    => '', // 下载地址,string(200), 必填
                'is_auto_install' => true, // 是否自动安装(默认否),boolean
                'is_actived'  => false, // 安装完成后是否自动启动应用程序(默认否),boolean
            ]
            'cid' => 'target cid', // 推送通知至指定用户时填写
            'cid_list' => ['cid1','cid2',...], // 推送通知至指定用户列表时填写
        ];
        
 php
        $data = [
            'template_type' => 4,
            'template_data' => [
                'transmission_type' => 2, // 是否立即启动应用:1 立即启动 2 等待客户端自启动,必填
                'transmission_content' => '', // 透传内容,不支持转义字符,string(2048), 必填
                'is_ios' => false, // 是否支持 ios (默认不支持),boolean
                'is_content_available' => false, // 推送是否直接带有透传数据(默认否), boolean
                'badge' => '', // 应用icon上显示的数字,int
                'sound' => '', // 通知铃声文件名,string
                'category' => '', // 在客户端通知栏触发特定的action和button显示,string
                'custom_msg' => [
                   'key1' => 'value1',
                   'key2' => 'value2',
                   ...
                ], // 增加自定义的数据
                'title' => '', // 通知标题,string
                'text' => true, // 通知内容,string
            ]
            'cid' => 'target cid', // 推送通知至指定用户时填写
            'cid_list' => ['cid1','cid2',...], // 推送通知至指定用户列表时填写
        ];