PHPackages                             yungangunite/websocket-server-sdk - 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. yungangunite/websocket-server-sdk

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

yungangunite/websocket-server-sdk
=================================

PHP SDK for WebSocket service integration

v1.1.4(2mo ago)063MITPHPPHP &gt;=7.4

Since Mar 31Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/mnzone/WebsocketServerSDK)[ Packagist](https://packagist.org/packages/yungangunite/websocket-server-sdk)[ Docs](https://github.com/mnzone/WebsocketServerSDK)[ RSS](/packages/yungangunite-websocket-server-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (11)Used By (0)

YG WebSocket Server SDK
=======================

[](#yg-websocket-server-sdk)

这是一个用于快速接入YG WebSocket服务的PHP SDK。

安装
--

[](#安装)

使用Composer安装：

```
composer require yungangunite/websocket-server-sdk
```

系统要求
----

[](#系统要求)

- PHP &gt;= 7.4
- Composer
- PHP JSON扩展
- PHP OpenSSL扩展

使用方法
----

[](#使用方法)

### 1. 创建客户端实例

[](#1-创建客户端实例)

```
use YG\WSServer\YGWSClient;

$client = new YGWSClient(
    'your_app_id',
    'your_app_secret',
    'http://your-server'  // 可选，默认为 http://your-server
);
```

### 2. 注册用户

[](#2-注册用户)

```
try {
    $userData = $client->registerUser(
        'username',
        'password',
        'email@example.com',  // 可选
        [                     // 可选
            'phone' => '13800138000',
            'other_info' => '其他信息'
        ]
    );

    print_r($userData);
} catch (Exception $e) {
    echo "错误：" . $e->getMessage();
}
```

### 3. 获取WebSocket令牌

[](#3-获取websocket令牌)

```
try {
    $wsToken = $client->getWsToken($userData['user_id']);
    print_r($wsToken);
} catch (Exception $e) {
    echo "错误：" . $e->getMessage();
}
```

完整示例
----

[](#完整示例)

查看 `examples/example.php` 文件获取完整的使用示例。

注意事项
----

[](#注意事项)

1. 安全性

    - 请妥善保管 `app_secret`
    - 使用HTTPS进行API调用
    - 定期更新服务器令牌
    - 及时处理过期的WebSocket令牌
    - 密码使用SHA256加密存储
2. 错误处理

    - 处理网络异常情况
    - 记录关键错误日志
    - 处理用户状态检查（如用户被禁用）
3. 性能优化

    - 避免频繁获取WebSocket令牌
    - 及时关闭不需要的连接

错误码说明
-----

[](#错误码说明)

错误码说明400请求参数错误（如用户名已存在、邮箱已被使用）401未授权或令牌无效（如服务器令牌无效、用户被禁用）403权限不足404资源不存在（如应用不存在或未激活）500服务器内部错误技术支持
----

[](#技术支持)

如有问题，请联系技术支持：

- 邮箱：
- 电话：400-xxx-xxxx

###  Health Score

40

—

FairBetter than 87% of packages

Maintenance94

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

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 ~38 days

Recently: every ~33 days

Total

10

Last Release

63d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dbe9c6f4932cc5adfe996c1fdc0c20e2d948864cadb300fe3d1b8038c3ceaa0?d=identicon)[mnzone](/maintainers/mnzone)

---

Tags

phpsdkwebsocketyg

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yungangunite-websocket-server-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/yungangunite-websocket-server-sdk/health.svg)](https://phpackages.com/packages/yungangunite-websocket-server-sdk)
```

###  Alternatives

[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.3M14](/packages/xeroapi-xero-php-oauth2)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34170.2k2](/packages/onesignal-onesignal-php-api)[ory/hydra-client

Documentation for all of Ory Hydra's APIs.

17435.9k](/packages/ory-hydra-client)[zenditplatform/zendit-php-sdk

PHP client for Zendit API

1204.3k](/packages/zenditplatform-zendit-php-sdk)[ory/hydra-client-php

Documentation for all of Ory Hydra's APIs.

1710.8k](/packages/ory-hydra-client-php)

PHPackages © 2026

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