PHPackages                             tenko/pospal-helper - 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. [API Development](/categories/api)
4. /
5. tenko/pospal-helper

ActiveLibrary[API Development](/categories/api)

tenko/pospal-helper
===================

Pospal Api Helper

v0.1.7(3y ago)17MITPHPPHP &gt;=7.4

Since Dec 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Tenko-Star/PospalHelper)[ Packagist](https://packagist.org/packages/tenko/pospal-helper)[ RSS](/packages/tenko-pospal-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (8)Used By (0)

银豹收银系统PHP接口助手
=============

[](#银豹收银系统php接口助手)

最低需求
----

[](#最低需求)

- PHP: &gt;=7.4
- guzzlehttp/guzzle: ^6.5

使用方法
----

[](#使用方法)

```
// 适用于API v1
$appV1 = \PospalHelper\Factory::v1([
    'baseUri' => '',
    'appId' => '',
    'appKey' => '',
    // 以上三个配置信息为必填项，缺少会抛出异常

    // 其他配置
    // ...
]);

// 适用于API v2
$appV2 = \PospalHelper\Factory::v2([
    'baseUri' => '',
    'appId' => '',
    'appKey' => '',
    // 以上三个配置信息为必填项，缺少会抛出异常

    // 其他配置
    // ...
]);

// 示例：返回数据的接口-根据会员手机号查询会员
try {
    // 如果成功调用，返回的数据为接口结果，不包含message/status等额外信息
    $data = $appV1->customer->queryByTel("13800008888");
    // $data => [
    //      "customerUid" => "",
    //      "categoryName" => "金卡",
    //      "number" => "银豹收银",
    //      "name" => "OpenApi创建",
    //      ...
    //  ]
} catch (PospalHelper\Core\Exception\RequestException $e) {
    // 打印返回的错误信息（如果有的话）
    echo $e->getMessage();
    // 打印返回的错误码
    echo $e->getCode();
    // 其他处理...
}

// 示例：没有返回数据的接口-修改会员密码
try {
    // 如果成功调用，返回true
    $data = $appV1->customer->updateCustomerPassword("1393920057254848127", "123456");
    // $data => true
} catch (PospalHelper\Core\Exception\RequestException $e) {
    // 打印返回的错误信息（如果有的话）
    echo $e->getMessage();
    // 打印返回的错误码
    echo $e->getCode();
    // 其他处理...
}

// 示例：带分页的接口-分页查询全部会员
try {
    // 如果成功调用，返回一个CustomerIterator对象
    $iter = $appV1->customer->queryCustomerPages();
    // 第一页数据
    $page1 = $iter->current();
    // 第n页数据
    $iter->next();
    $pageN = $iter->current();

    // 回到第一页
    $iter->rewind();
    // 设置最大循环次数
    $iter->setMax(20);

    // 如果需要批量调用可以使用foreach
    $data = [];
    foreach ($iter as $item) {
        $data[] = $item;
    }
} catch (PospalHelper\Core\Exception\RequestException $e) {
    // 打印返回的错误信息（如果有的话）
    echo $e->getMessage();
    // 打印返回的错误码
    echo $e->getCode();
    // 其他处理...
}

// 示例：推送服务
$appV1->push
    // 设置错误处理器，当内层产生错误时，将被全部捕获并且没有任何输出，如果需要记录日志，可以使用错误处理器来处理
    ->setErrorHandler(function ($message, $code) {
        Log::write("推送服务处理错误：$message Code：$code", 'pospal');
    })
    ->handler(function ($cmd, $body, $config) {
        /**
         * $config 为一个数组，其中包含以下信息
         * $config = [
         *      'pushTime' => [timestamp] ?? time(),
         *      'bornTime' => [bornTimeStamp] ?? 0,
         *      'version' => [version] ?? 'unknown',
         *      'appId' => [appId]
         * ];
         */
        $log = "收到一条推送信息：[$cmd] " . json_encode($body) . "\n" . json_encode($config);
        Log::write($log, 'pospal');

        // cmd一般是xxx.xx的形式
        [$cmd, $sub] = explode('.', $cmd, 2);

        // 提供一种处理思路
        // 根据cmd前缀找出对应的processor
        $processor = ProcessorFactory::byCmd($cmd);
        if (is_null($processor)) {
            return null;
        }

        // 交给processor的process函数处理具体的业务
        return $processor->process($sub ?? 'default', $body, $config);
    });
```

*\* v1、v2的区别见[交互格式说明-v1](http://pospal.cn/openplatform/interactiveformatdescription.html)、[交互格式说明-v2](http://pospal.cn/openplatform/interactiveformatdescriptionV2.html)。*

*\* v1、v2使用上并无特别需要注意的点，只是因为文档做了区分才分离出来，使用时根据自己所需使用即可。*

*\* 其他配置见[配置说明](./doc/Config.md)*

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

Total

7

Last Release

1254d ago

### Community

Maintainers

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

---

Top Contributors

[![Tenko-Star](https://avatars.githubusercontent.com/u/87012983?v=4)](https://github.com/Tenko-Star "Tenko-Star (31 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tenko-pospal-helper/health.svg)

```
[![Health](https://phpackages.com/badges/tenko-pospal-helper/health.svg)](https://phpackages.com/packages/tenko-pospal-helper)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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