PHP code example of hedeqiang / umeng

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




use Hedeqiang\UMeng\Android;
use Hedeqiang\UMeng\IOS;

$config = [
    'Android' => [
        'appKey' => '***********',
        'appMasterSecret' => '***********',
        'production_mode' => true,
    ],
    'iOS' => [
        'appKey' => '***********',
        'appMasterSecret' => '***********',
        'production_mode' => true,
    ]
];

$android = new Android($config);
$ios = new IOS($config);

// Android
$params = [
    'type' => 'unicast',
    'device_tokens' => 'xx(Android为44位)',
    'payload' => [
        'display_type' => 'message',
        'body' => [
            'custom' => '自定义custom',
        ],
    ],
    'policy' => [
        'expire_time' => '2013-10-30 12:00:00',
    ],
    'description' => '测试单播消息-Android',
];

print_r($android->send($params));

// iOS
$params = [
    'type' => 'unicast',
    'device_tokens' => 'xx(iOS为64位)',
    'payload' => [
        'aps' => [
            'alert' => [
                'title' => 'title',
                'subtitle' => 'subtitle',
                'body' => 'body',
            ]
        ],
    ],
    'policy' => [
        'expire_time' => '2021-04-09 10:23:24',
    ],
    'description' => '测试单播消息-iOS',
];
print_r($push->send($params));

$params = [
    'task_id' => 'xx'
];
print_r($push->status($params));

$params = [
    'task_id' => 'xx'
];
print_r($push->cancel($params));

$params = [
    'content' => 'xx'
];
print_r($push->upload($params));



use Hedeqiang\UMeng\IOS;
use Hyperf\Utils\ApplicationContext;

ApplicationContext::getContainer()->get(IOS::class)->send([]);

php artisan vendor:publish --tag=push
or 
php artisan vendor:publish --provider="Hedeqiang\UMeng\PushServiceProvider"

ANDROID_PUSH_APP_KEY=
ANDROID_PUSH_APP_MASTER_SECRET=
ANDROID_PUSH_PRODUCTION_MODE=

IOS_PUSH_APP_KEY=
IOS_PUSH_APP_MASTER_SECRET=
IOS_PUSH_PRODUCTION_MODE=

public function index()
{
    return app('push.android')->send([]);
    return app('push.android')->status([]);
    return app('push.android')->cancel([]);
    return app('push.android')->upload([]);
    
    return app('push.ios')->send([]);
}

use Hedeqiang\UMeng\Facades\Push;

public function index()
{
    Push::android()->send([]);
    Push::android()->status([]);
    Push::android()->cancel([]);
    Push::android()->upload([]);
    
    Push::ios()->send([]);
}
shell
php bin/hyperf.php vendor:publish hedeqiang/umeng