项目作者: hedeqiang

项目描述 :
友盟推送 、php-sdk
高级语言: PHP
项目地址: git://github.com/hedeqiang/UMeng-Push.git
创建时间: 2018-12-05T16:09:57Z
项目社区:https://github.com/hedeqiang/UMeng-Push

开源协议:MIT License

下载


umeng

友盟推送SDK

StyleCI build status FOSSA Status
996.icu
LICENSE
HitCount
PHPUnit

如需极光推送 请前往 极光推送

v2.x 推翻重写之前的官方 demo。用法更简单 如需v1.x 请查看 master 分支

Installing

  1. $ composer require hedeqiang/umeng -vvv

配置

在使用本扩展之前,你需要去 友盟+ 注册账号,然后创建应用,获取应用的 Key 和秘钥。

使用

  1. require __DIR__ .'/vendor/autoload.php';
  2. use Hedeqiang\UMeng\Android;
  3. use Hedeqiang\UMeng\IOS;
  4. $config = [
  5. 'Android' => [
  6. 'appKey' => '***********',
  7. 'appMasterSecret' => '***********',
  8. 'production_mode' => true,
  9. ],
  10. 'iOS' => [
  11. 'appKey' => '***********',
  12. 'appMasterSecret' => '***********',
  13. 'production_mode' => true,
  14. ]
  15. ];
  16. $android = new Android($config);
  17. $ios = new IOS($config);

params 接受数组,安装官方文档示例,转化为数组格式即可 appkeytimestamp 可传可不传。以下为示例代码。可供参考

消息发送

unicast 消息发送示例

  1. // Android
  2. $params = [
  3. 'type' => 'unicast',
  4. 'device_tokens' => 'xx(Android为44位)',
  5. 'payload' => [
  6. 'display_type' => 'message',
  7. 'body' => [
  8. 'custom' => '自定义custom',
  9. ],
  10. ],
  11. 'policy' => [
  12. 'expire_time' => '2013-10-30 12:00:00',
  13. ],
  14. 'description' => '测试单播消息-Android',
  15. ];
  16. print_r($android->send($params));
  17. // iOS
  18. $params = [
  19. 'type' => 'unicast',
  20. 'device_tokens' => 'xx(iOS为64位)',
  21. 'payload' => [
  22. 'aps' => [
  23. 'alert' => [
  24. 'title' => 'title',
  25. 'subtitle' => 'subtitle',
  26. 'body' => 'body',
  27. ]
  28. ],
  29. ],
  30. 'policy' => [
  31. 'expire_time' => '2021-04-09 10:23:24',
  32. ],
  33. 'description' => '测试单播消息-iOS',
  34. ];
  35. print_r($push->send($params));

任务类消息状态查询

  1. $params = [
  2. 'task_id' => 'xx'
  3. ];
  4. print_r($push->status($params));

任务类消息取消

  1. $params = [
  2. 'task_id' => 'xx'
  3. ];
  4. print_r($push->cancel($params));

文件上传

  1. $params = [
  2. 'content' => 'xx'
  3. ];
  4. print_r($push->upload($params));

在 Hyperf 中使用

发布配置文件

  1. php bin/hyperf.php vendor:publish hedeqiang/umeng

发送

  1. <?php
  2. use Hedeqiang\UMeng\IOS;
  3. use Hyperf\Utils\ApplicationContext;
  4. ApplicationContext::getContainer()->get(IOS::class)->send([]);

在 Laravel 中使用

发布配置文件

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

编写配置文件

  1. ANDROID_PUSH_APP_KEY=
  2. ANDROID_PUSH_APP_MASTER_SECRET=
  3. ANDROID_PUSH_PRODUCTION_MODE=
  4. IOS_PUSH_APP_KEY=
  5. IOS_PUSH_APP_MASTER_SECRET=
  6. IOS_PUSH_PRODUCTION_MODE=

使用

服务名访问

  1. public function index()
  2. {
  3. return app('push.android')->send([]);
  4. return app('push.android')->status([]);
  5. return app('push.android')->cancel([]);
  6. return app('push.android')->upload([]);
  7. return app('push.ios')->send([]);
  8. }

Facades 门面使用(可以提示)

  1. use Hedeqiang\UMeng\Facades\Push;
  2. public function index()
  3. {
  4. Push::android()->send([]);
  5. Push::android()->status([]);
  6. Push::android()->cancel([]);
  7. Push::android()->upload([]);
  8. Push::ios()->send([]);
  9. }

参考

工具

License

MIT

FOSSA Status