友盟推送SDK
如需极光推送 请前往 极光推送
v2.x 推翻重写之前的官方 demo。用法更简单 如需v1.x 请查看 master 分支
$ composer require hedeqiang/umeng -vvv
在使用本扩展之前,你需要去 友盟+ 注册账号,然后创建应用,获取应用的 Key 和秘钥。
require __DIR__ .'/vendor/autoload.php';
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);
params 接受数组,安装官方文档示例,转化为数组格式即可
appkey
和timestamp
可传可不传。以下为示例代码。可供参考
// 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));
php bin/hyperf.php vendor:publish hedeqiang/umeng
<?php
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([]);
}
MIT