PHP code example of hedeqiang / jpush

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

    

hedeqiang / jpush example snippets





$config = [
    'appKey'       => 'XXX',
    'masterSecret' => 'XXX',

    'groupKey'    => 'XXX',
    'groupSecret' => 'XXX',

    'devKey'        => 'XXX',
    'devSecret'     => 'XXX',

    /*
     * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
     */
    'response_type' => 'array',


    /**
     * 日志配置
     *
     * level: 日志级别, 可选为:
     *         debug/info/notice/warning/error/critical/alert/emergency
     * path:日志文件位置(绝对路径!!!),要求可写权限
     */
    'log'           => [
        'default'  => env('APP_DEBUG', false) ? 'dev' : 'prod', // 默认使用的 channel,生产环境可以改为下面的 prod
        'channels' => [
            // 测试环境
            'dev'  => [
                'driver' => 'single',
                'path'   => '/tmp/push.log',
                'level'  => 'debug',
            ],
            // 生产环境
            'prod' => [
                'driver' => 'daily',
                'path'   => '/tmp/push.log',
                'level'  => 'info',
            ],
        ],
    ],
];
$app = \EasyJiGuang\Factory::JPush($config);


$options = [
    'platform' => 'all',
    'audience' => ['registration_id' => ['1']],
    'notification' => [
        'alert' => 'Hello',
        'android' => [],
        'ios' => [
            'extras' => ['newsid' => '123']
        ]
    ],
    ...
];
return $app->push->message($options);

$options = [
   'count' => 1,
   'type'  => 'push',
];
return $app->push->getCid($options);

$options = [
    ...
    // 该 API 只用于验证推送调用是否能够成功,
    // 与推送 API 的区别在于:不向用户发送任何消息。 其他字段说明:同推送 API
];
return $app->push->validate($options);

$options = [
    ...
];
return $app->push->batchRegidSingle($options);

$options = [
    ...
];
return $app->push->batchAliasSingle($options);

return $app->push->revoke($msgid);

$options = [
    ...
    'audience' => [
        'file' => ['file_id' => 'xxxx']
    ]
];
return $app->push->file($options);

$options = [
    ...
];
return $app->push->groupPush($options);

$options = [
    ...
];
return $app->push->groupPushFile($options);

$type = 'registration_id'; //type 文件类型,当前可取值为: alias、registration_id,不能为空。
return $app->file->files($type,['filename' => 'xxx.txt']);

return $app->file->getFiles();

return $app->file->deleteFiles($file_id);

return $app->file->getFilesById($file_id);

$query = [
    'msg_ids' => '1613113584,1229760629'
];
return $app->report->received($query);

$options = [
    'msg_id' => '',
    'registration_ids' => '',
    'date' => '' //可选
];
return $app->report->status($options);

$query = [
    'msg_ids' => '1613113584,1229760629'
];
return $app->report->detail($query);

$options = [
    'time_unit' => '',
    'start' => '',
    'duration' => ''
];
return $app->report->users($options);

$query = [
    'group_msgids' => '1613113584,1229760629'
];
return $app->report->groupUsers($query);

$options = [
    'time_unit' => '',
    'start' => '',
    'duration' => ''
];
return $app->report->groupUsers($options);

return $app->device->getDevices($registration_id);

$options = [
    'tags'   => [
        'add'    => ['tag1', 'tag2'],
        'remove' => ['tag3', 'tag4']
    ],
    'alias'  => 'alias1',
    'mobile' => '13012345678'
];
return $app->device->updateDevices($registration_id,$options);

return $app->device->getAliases($alias_value, $platform = ['platform ' => 'all']);

return $app->device->deleteAliases($alias_value, $platform = ['platform ' => 'all']);

$options = [
    'registration_ids' => [
        'remove' => ['registration_id1','registration_id2']
    ]
];
return $app->device->removeAliases($alias_value, $options);

return $app->device->getTags();

return $app->device->isDeviceInTag($tag_value,$registration_id);

$options = [
    'registration_ids' => [
        'add' => ['registration_id1','registration_id2'],
        'remove' => ['registration_id1','registration_id2']
    ]
];
return $app->device->updateTag($tag_value,$options);

return $app->device->deleteTag($tag_value,$platform = ['platform ' => 'all']);

$options = [
    'registration_ids' => ['010b81b3582','0207870f1b8','0207870f9b8']
];
return $app->device->status($options);

$app = \EasyJiGuang\Factory::JVerify($config);

$options = [
    'token' => 'xxx',
    'phone' => 'xxx',
    'exID'  => 'xxx',
];
// 号码认证 提交手机号码和token,验证是否一致
$app->verify->verify($options);
// 一键登录 提交loginToken,验证后返回手机号码
$app->verify->loginTokenVerify('xxx','xxx');

php artisan vendor:publish --tag=jiguang
or 
php artisan vendor:publish --provider="EasyJiGuang\Providers\JiGuangServiceProvider"

public function index()
{
    return app('push')->push->message($options);
}

use EasyJiGuang\Facades\EasyJiGuang;

public function index()
{
    return EasyJiGuang::JPush()->push->message($options);
}

EasyJiGuang::JVerify()->verify->verify();
.
.
.