PHPackages                             hedeqiang/umeng - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. hedeqiang/umeng

ActiveLibrary[HTTP &amp; Networking](/categories/http)

hedeqiang/umeng
===============

友盟推送

v2.1.6(3y ago)3424.9k↓21.6%15MITPHPPHP &gt;=7.0CI failing

Since Dec 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hedeqiang/UMeng-Push)[ Packagist](https://packagist.org/packages/hedeqiang/umeng)[ RSS](/packages/hedeqiang-umeng/feed)WikiDiscussions v2.x Synced 3w ago

READMEChangelog (10)Dependencies (2)Versions (21)Used By (0)

 umeng
=======

[](#-umeng-)

 友盟推送SDK

[![StyleCI build status](https://camo.githubusercontent.com/501b50da51bf133b82086293b21ffc8307a610c8488cba7e202688f888fcfbc5/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136303534343536332f736869656c64)](https://camo.githubusercontent.com/501b50da51bf133b82086293b21ffc8307a610c8488cba7e202688f888fcfbc5/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136303534343536332f736869656c64) [![FOSSA Status](https://camo.githubusercontent.com/f144dccdb8b14d679cae5eb7947b30bdd7ff85232cd20b2a0493f6b6a6deae76/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246686564657169616e67253246554d656e672d507573682e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2Fhedeqiang%2FUMeng-Push?ref=badge_shield)[![996.icu](https://camo.githubusercontent.com/ac8f294a80f65338db545230f1a881b9a382204a1f187c6ff40ee679d42d40ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c696e6b2d3939362e6963752d7265642e737667)](https://996.icu)[![LICENSE](https://camo.githubusercontent.com/be80b8cb211ceb2263744e99fdb161a40124901906fd7c7f47d6361760dd7e8b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d416e74692532303939362d626c75652e737667)](https://github.com/996icu/996.ICU/blob/master/LICENSE)[![HitCount](https://camo.githubusercontent.com/2663b52e90c7cd134a35203703b1c4d7771af657479f28cf8140cd0ddbca1f41/687474703a2f2f686974732e6477796c2e696f2f686564657169616e672f756d656e672e737667)](http://hits.dwyl.io/hedeqiang/umeng)[![PHPUnit](https://github.com/hedeqiang/UMeng-Push/actions/workflows/test.yml/badge.svg)](https://github.com/hedeqiang/UMeng-Push/actions/workflows/test.yml)

> 如需极光推送 请前往 [极光推送](https://github.com/hedeqiang/JPush)

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

Installing
----------

[](#installing)

```
$ composer require hedeqiang/umeng -vvv
```

配置
--

[](#配置)

在使用本扩展之前，你需要去 [友盟+](https://message.umeng.com) 注册账号，然后创建应用，获取应用的 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` 可传可不传。以下为示例代码。可供参考

消息发送
----

[](#消息发送)

### unicast 消息发送示例

[](#unicast-消息发送示例)

```
// 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));
```

在 Hyperf 中使用
------------

[](#在-hyperf-中使用)

### 发布配置文件

[](#发布配置文件)

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

### 发送

[](#发送)

```
