PHPackages                             ysnows/unified\_push - 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. ysnows/unified\_push

ActiveLibrary

ysnows/unified\_push
====================

app unified push

1.1.5(5y ago)2333MITPHPPHP &gt;=5.5

Since Jan 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ysnows/php_unified_push)[ Packagist](https://packagist.org/packages/ysnows/unified_push)[ RSS](/packages/ysnows-unified-push/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (15)Used By (0)

php unified push for android of china
=====================================

[](#php-unified-push--for-android-of-china)

此项目基于[push](https://github.com/myappcloud/push)修改而来，适配 [MixPush](https://github.com/taoweiji/MixPush)

以下为[push](https://github.com/myappcloud/push) 的文档:

平台支持
----

[](#平台支持)

- [华为推送](https://developer.huawei.com/consumer/cn/service/hms/catalog/huaweipush_agent.html?page=hmssdk_huaweipush_api_reference_agent_s2)
- [华为新版推送](https://developer.huawei.com/consumer/cn/doc/development/HMS-References/push-sendapi)
- [小米推送](https://dev.mi.com/console/doc/detail?pId=1163)
- [魅族推送](https://github.com/MEIZUPUSH/PushAPI#api_standard_index)
- [Oppo推送](https://storepic.oppomobile.com/openplat/resource/201910/18/OPPO%E6%8E%A8%E9%80%81%E5%B9%B3%E5%8F%B0%E6%9C%8D%E5%8A%A1%E7%AB%AFAPI-V1.9.3.pdf)
- [Vivo推送](https://swsdl.vivo.com.cn/appstore/developer/uploadfile/20191210/we5XL6/PUSH-UPS-API%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3%20-%202.7.0%E7%89%88.pdf)
- [iOS APNs推送](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1)
- [iOS APNs(base on token)推送](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns)

---

环境需求
----

[](#环境需求)

- PHP &gt;= 5.4
- guzzlehttp/guzzle &gt;= 6.0.0
- yunchuang/php-jwt &gt;= 1.0

安装
--

[](#安装)

```
composer require ysnows/unified_push

```

---

使用
--

[](#使用)

```
use MingYuanYun\Push\Push;

$iosCertContent = [
        'appPkgName' => '', // 包名
        'clientId' => '',
        'clientSecret' => ''
    ],
    'huawei-v2' => [
        'appPkgName' => '',
        'clientId' => '',
        'clientSecret' => ''
    ],
    'meizu' => [
        'appPkgName' => '',
        'appId' => '',
        'appSecret' => ''
    ],
    'xiaomi' => [
        'appPkgName' => '',
        'appSecret' => ''
    ],
    'oppo' => [
        'appPkgName' => '',
        'appKey' => '',
        'masterSecret' => ''
    ],
    'vivo' => [
        'appPkgName' => '',
        'appId' => '',
        'appKey' => '',
        'appSecret' => ''
    ],
    'ios' => [
        'isSandBox' => true, // 是否调试包
        'certPath' => '', // pem格式推送证书本地绝对路径
        'password' => '123', // 推送证书密码
    ],
    'ios-token' => [
        'isSandBox' => true,
        'teamId' => 'D4GSYVE6CN', // 开发者帐号teamId
        'keyId' => '99BYW4U4SZ', // token认证keyId
        'secretContent' => $iosCertContent, // 密钥内容，有值时忽略secretFile
        'secretFile' => 'xxx.p8', // token认证密钥文件本地绝对路径
        'bundleId' => 'com.mysoft.mdev' // 应用ID
    ]
];

$push = new Push($config);
$push->setPusher(通道名);
$push->pushNotice(设备token, 推送内容, 附加信息);
```

通道
--

[](#通道)

目前支持以下通道：

- huawei 华为
- huawei-v2 华为新版
- xiaomi 小米
- meizu 魅族
- oppo Oppo
- vivo Vivo
- ios 苹果(基于推送证书认证)
- ios-token 苹果(基于token认证)

设备token
-------

[](#设备token)

通过推送插件获得，支持以数组形式传入多个。

鉴于各厂商对多推的支持不一，建议单次最多100个设备。

推送内容
----

[](#推送内容)

由于各厂商对推送的支持不一，现抽象定义了以下公有属性：

参数类型说明businessIdstring业务ID，相同业务ID只推送一次titlestring标题subTitlestring副标题contentstring内容badgestring角标extraarray服务端传给APP的自定义数据，建议转换为json字符串后长度不超过1024字节callbackstring送达回执地址，供推送厂商调用，最大128个字节，具体请查阅各厂商文档。*华为仅支持在应用管理中心配置；魅族需在管理后台注册回执地址，每次推送时也需指定回执地址；苹果ios-token通道由SDK调用回执*callbackParamstring自定义回执参数notifyIdstring聚合标签，同标签消息在通知栏只显示一条。小米通道支持，字母、数字组合不超过8位gatewayOptionsarray厂商扩展参数### gatewayOptions厂商扩展参数说明

[](#gatewayoptions厂商扩展参数说明)

考虑到各厂商均有自己特有的参数，故提供此扩展参数来提供支持。如果扩展参数与通用参数有冲突，则取扩展参数中值。 参数类型为以厂商通道为键名的数组，格式如下：

```
[
    "huawei": 与华为消息格式一致，下同,
    "xiaomi": xxx,
    "vivo": xxx,
    "oppo": xxx,
    "meizu": xxx,
    "ios-token": xxx
]
```

示例

```
$message = [
    'businessId' => uniqid(),
    'title' => 'This is title',
    'content' => 'This is content',
    'extra' => [
        'key1' => 'v1',
        'key2' => 2
    ],
    'gatewayOptions' => [
        'xiaomi' => [
            'extra.notify_foreground' => '1',
        ],
        'huawei' => [
            'hps' => [
                'ext' => [
                    'badgeAddNum' => '1',
                    'badgeClass' => 'com.mysoft.core.activity.LauncherActivity',
                ]
            ]
        ]
    ],
];
```

附加信息
----

[](#附加信息)

参数类型说明tokenstring认证tokenpushMingYuanYun\\Push\\Support\\ApnsPushiOS证书推送实例，考虑到文件I/O问题，故此设计标题等长度限制说明
---------

[](#标题等长度限制说明)

> 当前库将根据以下厂商限制进行处理，请调用方根据实际情况设置标题等内容

厂商标题副标题描述回执地址回执参数华为未说明-未说明--小米未说明-未说明未说明64OPPO501020020050VIVO20-5012864魅族32-10012864苹果未说明未说明未说明--角标说明
----

[](#角标说明)

目前仅华为、华为新版、ios、ios-token通道支持角标。其中华为新版支持角标累加，格式为`+1`，其他通道将只取数字值。

---

推送
--

[](#推送)

```
// 华为推送
$push->setPusher('huawei');
print $push->pushNotice(
    '0864113036098917300002377300CN01',
    $message,
    ['token' => 'CFx88jTVr6adjsh6eVOLvhtqnDlhLxb7CljykbXxu7vLsnexatUJZM1lqXHPzfnurD0gknQnIu7SRvWhAPx/zQ==']
);

// 魅族推送
$push->setPusher('meizu');
print $push->pushNotice(
    ['ULY6c596e6a7d5b714a475a60527c6b5f7f655a6d6370'],
    $message
);

// 小米推送
$push->setPusher('xiaomi');
print $push->pushNotice(
    [
        'hncl+mMTtpA8BQZ66k7Fgpwa+ezlSL8AN/g8HKzTfg64GcTeTjY1C9bdrUcs2vR+',
        '0VcFXBPNTLifGLIYK+GdDAiOFJQ+uWAzkfs7QYtfszBgqFV720C8zli7mce1mHj6'
    ],
    $message
);

// Oppo推送
$push->setPusher('oppo');
$tokenInfo = $push->getAuthToken();
$options = [
    'token' => $tokenInfo['token']
];
print $push->pushNotice(
    'CN_40557c137ac2b5c68cbb8ac52616fefd',
    $message,
    $options
);

// Vivo推送
$push->setPusher('vivo');
print $push->pushNotice(
    [
        '15513410784181118114099',
    ],
    $message
);

// 苹果基于证书推送
$push->setPusher('ios');

$apnsPush = new ApnsPush();
$isSandBox = true;
$certPath = '/cert/path';
$password = 'cert_pwd';
$apnsPush->setIsSandBox($isSandBox)
    ->setLocalCert($certPath)
    ->setPassphrase($password);
$options = [
    'push' => $apnsPush
];

print $push->pushNotice(
    [
        '7438f5ba512cba4dcd1613e530a960cb862bd1c7ca70eae3cfe73137583c3c0d',
        '720772a4df1938b14d2b732ee62ce4e157577f8453d6021f81156aaeca7032ae',
    ],
    $message,
    $options
);

// 苹果基于token推送
$push->setPusher('ios-token');
print $push->pushNotice(
    [
        '7438f5ba512cba4dcd1613e530a960cb862bd1c7ca70eae3cfe73137583c3c0d',
        '720772a4df1938b14d2b732ee62ce4e157577f8453d6021f81156aaeca7032ae',
    ],
    $message
);
```

认证
--

[](#认证)

目前`华为`、`华为新版`、`Oppo`、`Vivo`、`ios-token`推送前需要获取先获取认证token，且对获取频次均有限制，故统一提供了获取token方法`getAuthToken`，建议缓存认证token，过期时间较返回的有效时间短，比如2小时。

此方法返回格式如下：

```
[
    'token' => 认证token,
    'expires' => 有效时间，单位为秒
];
```

其余通道将返回`null`。

缓存的认证token请以[附加信息](#%E9%99%84%E5%8A%A0%E4%BF%A1%E6%81%AF)传入。

推送角标
----

[](#推送角标)

目前仅`ios` `ios-token` `华为` `华为新版`支持推送角标

其中`华为新版`支持角标累加，`badge`格式为`+ 5`

返回值
---

[](#返回值)

除苹果通道外，其余通道推送成功时均将返回推送任务ID。

调用过程中有可能抛出以下异常，请注意捕获。

- `MingYuanYun\Push\Exceptions\GatewayErrorException`
- `MingYuanYun\Push\Exceptions\InvalidArgumentException`
- `MingYuanYun\Push\Exceptions\ResponseException`

也可捕获上述异常的父类`MingYuanYun\Push\Exceptions\Exception`

自定义通道
-----

[](#自定义通道)

本扩展支持自定义通道。

```
use MingYuanYun\Push\Gateways\Gateway;

class MyGateway extends Gateway
{
    // ...
}

// 注册
$push->extend('custom', function ($config) {
    return new MyGateway($config);
}

// config中添加通道配置
$config['custom'] = [];

// 调用
$push->setPusher('custom');
print $push->pushNotice(
    '0864113036098917300002377300CN01',
    $message
);
```

各通道配置参照[$config](#%E4%BD%BF%E7%94%A8)
-------------------------------------

[](#各通道配置参照config)

---

各通道回执示例
-------

[](#各通道回执示例)

> 建议判断如果是字符串，则进行json\_decode

- ios-token

```
# 成功
{
    "businessId": "5cc55570a9faf",
    "deviceToken": "7438f5ba512cba4dcd1613e530a960cb862bd1c7ca70eae3cfe73137583c3c0d",
    "taskId": "3FC1E078-93CA-33BA-EC52-8E8A70AA0EB1",
    "status": "success"
}

# 失败
{
    "businessId": "5cc550a6d05ad",
    "deviceToken": "7438f5ba512cba4dcd1613e530a960cb862bd1c7ca70eae3cfe73137583c3c0d",
    "reason": "403 Forbidden for ExpiredProviderToken",
    "status": "fail"
}

```

- huawei

```
{
    "statuses": [
        {
            "timestamp": 1552459811754,
            "token": "0864113036098917300002377300CN01",
            "appid": "100405075",
            "biTag": "",
            "status": 0,
            "requestId": "155245981150032647501"
        }
    ]
}

```

- meizu

```
{
    "cb": "{\"NS20190313171303747_0_11579902_1_3-1\":{\"param\":\"\",\"type\":1,\"targets\":[\"S5Q4b726f7b466c797c584d54000503555c427160754b\"]}}",
    "access_token": "c68b05216e54409d95573912fad9c0de"
}

```

- xiaomi

```
{
    "data": "{\"scm527795524699919378t\":{\"barStatus\":\"Enable\",\"type\":1,\"targets\":\"0VcFXBPNTLifGLIYK+GdDAiOFJQ+uWAzkfs7QYtfszBgqFV720C8zli7mce1mHj6\",\"timestamp\":1552470320982},\"scm52278552470202304Mq\":{\"barStatus\":\"Enable\",\"type\":1,\"targets\":\"0VcFXBPNTLifGLIYK+GdDAiOFJQ+uWAzkfs7QYtfszBgqFV720C8zli7mce1mHj6\",\"timestamp\":1552470321182}}"
}

```

- vivo

```
{
    "555758542050050048": {
        "param": null,
        "targets": "15513410784181118114099"
    }
}

```

- oppo

```
[
    {
        "registrationIds": "CN_768799ad17f2b564707db038dabb14b6",
        "messageId": "5c89f5d30980ff58c6ff9914",
        "taskId": "0000",
        "eventType": "push_arrive",
        "appId": "3000604"
    }
]

```

---

[推送限额说明](/docs/push_limit.md)
-----------------------------

[](#推送限额说明)

---

Oppo、Vivo推送服务开通答疑
-----------------

[](#oppovivo推送服务开通答疑)

[![oppo](/docs/oppo_push.png)](/docs/oppo_push.png)[![vivo](/docs/vivo_push.png)](/docs/vivo_push.png)

---

注意
--

[](#注意)

- 各厂商设备token长度不一致，目前识别出华为最长为130个字符
- 如果项目中使用了`firebase/php-jwt`，需要将此库移除。由于此库不支持ios-token要求的`ES256`算法，故从其PR中拉取出一个新的库`yunchuang/php-jwt`，对应官方的`5.0.0`版本，用法与官方一致
- ios-token推送要求支持HTTP/2协议，另见 [参照](/docs/ios_token_http_2.md)
- [iOS两种推送形式比较](/docs/ios_push_compare.md)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

14

Last Release

1871d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.4

1.0.6PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/c696ff0859f8d5d4ce9999bf43f4c844cc7f512c40cf60ddb7e0bef25ead9a43?d=identicon)[ysnows](/maintainers/ysnows)

---

Top Contributors

[![yong531315](https://avatars.githubusercontent.com/u/8914325?v=4)](https://github.com/yong531315 "yong531315 (29 commits)")

---

Tags

pushAndroid push

### Embed Badge

![Health badge](/badges/ysnows-unified-push/health.svg)

```
[![Health](https://phpackages.com/badges/ysnows-unified-push/health.svg)](https://phpackages.com/packages/ysnows-unified-push)
```

###  Alternatives

[minishlink/web-push

Web Push library for PHP

1.9k12.0M52](/packages/minishlink-web-push)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M292](/packages/pusher-pusher-php-server)[berkayk/onesignal-laravel

OneSignal Push Wrapper Laravel

5295.9M12](/packages/berkayk-onesignal-laravel)[guanguans/notify

Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

682104.9k7](/packages/guanguans-notify)[edujugon/push-notification

Laravel Package to send push notifications to Android and IOS devices. (GCM,FCM,APN)

4891.4M1](/packages/edujugon-push-notification)[pubnub/pubnub

This is the official PubNub PHP SDK repository.

1314.6M17](/packages/pubnub-pubnub)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
