PHPackages                             higreen/php-api - 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. higreen/php-api

ActiveLibrary[API Development](/categories/api)

higreen/php-api
===============

第三方服务，接口封装。

v1.0.1(3y ago)1221MITPHPPHP ^7.0|^8.0

Since Apr 11Pushed 3y agoCompare

[ Source](https://github.com/higreen/php-api)[ Packagist](https://packagist.org/packages/higreen/php-api)[ RSS](/packages/higreen-php-api/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP Api
=======

[](#php-api)

[![php-badge](https://camo.githubusercontent.com/7d2f3b731fb51d68db9a5ca588b49dc915591452de065b1bb936ab8e05a3b345/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372d3838393242462e737667)](https://camo.githubusercontent.com/7d2f3b731fb51d68db9a5ca588b49dc915591452de065b1bb936ab8e05a3b345/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372d3838393242462e737667)[![packagist-badge](https://camo.githubusercontent.com/75ad139f82e58eb22307ad624becb24fc92a9c568d4d1134e45722ac52c10712/687474703a2f2f696d672e6869677265656e2e746f702f7068706170692e737667)](https://packagist.org/packages/higreen/php-api)[![Total Downloads](https://camo.githubusercontent.com/3338effa13edfe377f013aefec6cac8e28b940bde0fed7f31c1254d4e179e19d/68747470733a2f2f706f7365722e707567782e6f72672f6869677265656e2f7068702d6170692f646f776e6c6f616473)](https://packagist.org/packages/higreen/php-api)
第三方服务，接口封装。

Installation
------------

[](#installation)

```
composer require higreen/php-api
```

Features
--------

[](#features)

- [微信](#%E5%BE%AE%E4%BF%A1)
    - [小程序](#weixin-mini)
        - 登录凭证校验
        - 获取接口调用凭证
        - 获取小程序码
        - 下发小程序和公众号统一的服务消息
        - 解密数据
    - [小程序-内容安全](#weixin-mini-security)
        - 校验一张图片
        - 校验一段文本
    - [小程序-图片识别](#weixin-mini-ocr)
        - 银行卡
        - 营业执照
        - 驾驶证
        - 身份证
        - 通用印刷体
        - 行驶证
    - [公众号](#weixin-offi)
        - 登录凭证校验
        - 获取接口调用凭据
        - 获取微信JS接口的临时票据
        - 获取微信JS接口的权限验证配置
        - 获取用户信息
        - 是否关注公众号
        - 发送模板消息
    - [支付](#weixin-pay)
        - 下单
        - 查询订单
        - 退款
        - 回调报文解密
    - [企业付款](#weixin-transfer)
- [支付宝](#%E6%94%AF%E4%BB%98%E5%AE%9D)
    - [小程序](#alipay-mini)
        - 获取支付宝user\_id
    - [支付](#alipay-pay)
        - APP支付
        - 小程序支付
        - 扫码支付
        - 回调数据验证签名
- [阿里云](#%E9%98%BF%E9%87%8C%E4%BA%91)
    - [短信](#aliyun-sms)
- [百度云](#%E7%99%BE%E5%BA%A6%E4%BA%91)
    - [语音](#baidu-speech)
- [腾讯云](#%E8%85%BE%E8%AE%AF%E4%BA%91)
    - [地图](#tencent-map)
    - [短信](#tencent-sms)
    - [人脸核身](#tencent-faceid)
- [移动](#%E7%A7%BB%E5%8A%A8)
    - [号码认证](#yidong-identify)
- 快递100
- 极光推送

---

Usage
-----

[](#usage)

### 微信

[](#微信)

 **小程序**```
use Higreen\Api\Weixin\Mini;

$Mini = new Mini([
    'app_id' => '小程序ID',
    'app_secret' => '小程序密钥',
]);
```

1. 登录凭证校验 ```
    $session = $Mini->code2session($code);
    ```

```
2. 获取接口调用凭证
    ```php
    $access_token = $Mini->getAccessToken();

```

3. 获取小程序码 ```
    $res = Mini::getWXACodeUnlimit($access_token, [
        'scene'      => '[str] [必填] [最大32个可见字符]',
        'page'       => '[str] [可选] [已经发布的小程序存在的页面]',
        'width'      => '[int] [可选] [二维码的宽度，单位 px，最小 280px，最大 1280px]',
        'auto_color' => '[bol] [可选] [自动配置线条颜色]',
        'line_color' => '[arr] [可选] [auto_color 为 false 时生效，使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示]',
        'is_hyaline' => '[bol] [可选] [是否需要透明底色]',
    ]);
    ```
4. 下发小程序和公众号统一的服务消息 ```
    $res = Mini::sendUniformMessage($access_token, [
        'touser'      => '[必填] [str] [用户openid，可以是小程序的openid，也可以是mp_template_msg.appid对应的公众号的openid]',
        'appid'       => '[必填] [str] [公众号appid，要求与小程序有绑定且同主体]',
        'template_id' => '[必填] [str] [公众号模板id]',
        'url'         => '[必填] [str] [公众号模板消息所要跳转的url]',
        'data'        => '[必填] [arr] [模板内容，格式形如 { "key1": { "value": any }, "key2": { "value": any } }]',
        'pagepath'    => '[可选] [str] [点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,（示例index?foo=bar）。该字段不填则模板无跳转。]',
    ]);
    ```
5. 解密数据 ```
    $data = Mini::decryptData($encryptedData, $session_key, $iv);
    ```

 **小程序-内容安全**```
use Higreen\Api\Weixin\MiniSecurity;
```

1. 校验一张图片 ```
    $bool = MiniSecurity::checkImg($access_token, '图片链接');
    ```
2. 检查一段文本 ```
    $bool = MiniSecurity::checkText($access_token, '文字内容');
    ```

 **小程序-图片识别**```
use Higreen\Api\Weixin\MiniOcr;
```

1. 银行卡 ```
    $res = MiniOcr::bankcard($access_token, '图片链接');
    ```
2. 营业执照 ```
    $res = MiniOcr::businessLicense($access_token, '图片链接');
    ```
3. 驾驶证 ```
    $res = MiniOcr::driverLicense($access_token, '图片链接');
    ```
4. 身份证 ```
    $res = MiniOcr::idcard($access_token, '图片链接');
    ```
5. 通用印刷体 ```
    $res = MiniOcr::printedText($access_token, '图片链接');
    ```
6. 行驶证 ```
    $res = MiniOcr::vehicleLicense($access_token, '图片链接');
    ```

 **公众号**```
use Higreen\Api\Weixin\Offi;

$Offi = new Offi([
    'app_id' => '公众号ID',
    'app_secret' => '公众号密钥',
]);
```

1. 登录凭证校验

    ```
    $session = $Offi->code2session($code);
    ```
2. 获取接口调用凭据

    ```
    $access_token = $Offi->getAccessToken();
    ```
3. 获取用户信息

    ```
    $userinfo = Offi::getUserinfo($access_token, 'openid');
    ```
4. 获取微信JS接口的临时票据

    ```
    $ticket = Offi::getJsapiTicket($access_token);
    ```
5. 获取微信JS接口的权限配置

    ```
    $config = Offi::getJsapiConfig($ticket, '网页的URL(可选)')
    ```
6. 发送模板消息

    ```
    $res = Offi::sendMessage($access_token, [
        'touser'      => '[str] [必填] [接收者openid]',
        'template_id' => '[str] [必填] [模板ID]',
        'data'        => '[arr] [必填] [模板数据]',
    ]);
    ```
7. 是否关注公众号

    ```
    $bool = Offi::isFollow($access_token, 'openid');
    ```

 **支付**```
use Higreen\Api\Weixin\Pay;

$Pay = new Pay([
    'mch_id'     => '商户ID',
    'mch_key_v3' => '商户密钥V3',
    'sslcert'    => '证书路径',
    'sslkey'     => '证书密钥路径',
]);
```

1. 下单

    ```
    $res = $Pay->order('交易类型(大小写不限)：JSAPI,APP,H5,Native', [
        'appid'        => '[str] [必填] [微信生成的应用ID]',
        'description'  => '[str] [必填] [商品描述]',
        'out_trade_no' => '[str] [必填] [商户系统内部订单号，同一个商户号下唯一]',
        'total'        => '[int] [必填] [订单总金额，单位为分]',
        'notify_url'   => '[int] [必填] [直接可访问的URL，不允许携带查询串，要求必须为https]',
        'attach'       => '[str] [可选] [附加数据，在查询API和支付通知中原样返回]',
        'openid'       => '[str] [可选] [JSAPI交易类型必传，用户在商户appid下的唯一标识]',
        'type'         => '[str] [可选] [H5交易类型必传，场景类型 示例值：iOS, Android, Wap]',
    ]);
    ```
2. 查询订单

    ```
    $res = $Pay->orderResult('商户系统内部订单号');
    ```
3. 退款

    ```
    $res = $Pay->refund([
        'out_trade_no'  => '[str] [必填] [原支付交易对应的商户订单号]',
        'out_refund_no' => '[str] [必填] [商户系统内部的退款单号，商户系统内部唯一]',
        'total'         => '[int] [必填] [原支付交易的订单总金额，币种的最小单位]',
        'refund'        => '[int] [必填] [退款金额，币种的最小单位]',
        'reason'        => '[str] [可选] [退款原因]',
        'notify_url'    => '[str] [可选] [异步接收微信支付退款结果通知的回调地址]',
    ]);
    ```
4. 解密回调报文

    ```
    $res = Pay::decryptResource('商户号APIV3密钥', '加密报文');
    ```

 **企业付款**```
use Higreen\Api\Weixin\Transfer;

$Transfer = new Transfer([
    'mch_id'     => '商户ID',
    'mch_key'    => '商户密钥',
    'sslcert'    => '证书路径',
    'sslkey'     => '证书密钥路径',
]);
```

1. 到零钱 ```
    $res = $Transfer->balance([
        'partner_trade_no' => '[str] [必填] [商户订单号]',
        'mch_appid'        => '[str] [必填] [商户账号appid]',
        'openid'           => '[str] [必填] [用户openid]',
        'amount'           => '[int] [必填] [企业付款金额，单位为分]',
        'desc'             => '[str] [必填] [企业付款备注]',
        're_user_name'     => '[str] [可选] [收款用户姓名]',
    ]);
    ```

### 支付宝

[](#支付宝)

 **小程序**```
use Higreen\Api\Alipay\Mini;

$Mini = new Mini($init);
```

1. 获取支付宝user\_id `$user_id = $Mini->getUserId($code);`

 **支付**```
use Higreen\Api\Alipay\Pay;
$Pay = new Pay($init);
```

1. APP支付 ```
    $res = $Pay->app([
        'subject'      => '交易标题',
        'out_trade_no' => '商户订单号',
        'total_amount' => '订单总金额，单位为人民币（元）',
    ]);
    ```
2. 小程序支付 ```
    $res = $Pay->mini([
        'subject'      => '交易标题',
        'out_trade_no' => '商户订单号',
        'total_amount' => '订单总金额，单位为人民币（元）',
        'buyer_id'     => '支付宝用户的唯一userId',
    ]);
    ```
3. 扫码支付 ```
    $res = $Pay->qrcode([
        'subject'      => '交易标题',
        'out_trade_no' => '商户订单号',
        'total_amount' => '订单总金额，单位为人民币（元）',
    ]);
    ```
4. 支付回调数据验证签名，验证成功返回请求参数 `$res = Pay::checkSignature('支付宝公钥');`

### 阿里云

[](#阿里云)

 **短信**```
use Higreen\Api\Aliyun\Sms;

$init = [
    'id' => '应用Access Key ID',
    'secret' => '应用Access Key Secret',
    'sign' => '短信签名',
];
$Sms = new Aliyun($init);
$res = $Sms->send($phones, $template, $params);
```

### 百度云

[](#百度云)

 **语音**```
use Higreen\Api\Baidu\Speech;

$init = [
    'api_key'    => '[str] [必填] [应用公钥]',
    'secret_key' => '[str] [必填] [应用密钥]',
];
$Speech = new Speech($init);
```

1. 获取接口调用凭证

    ```
    $access_token = $Speech->getAccessToken();
    ```
2. 文字转语音

    ```
    $res = $Speech->text2audio($access_token, [
        'text' => '[str] [必填] [文字]',
    ]);
    ```

### 腾讯云

[](#腾讯云)

 **短信**```
use Higreen\Api\Tencent\Sms;

$init = [
    'id' => '密钥 ID',
    'key' => '密钥 KEY',
    'app_id' => '短信应用 SDKAppID',
    'sign' => '短信签名',
];
$Sms = new Sms($init);

# 发送单个手机号
$res = $Sms->sendSingle($template, $phone, $params);

# 发送多个手机号
$res = $Sms->sendMulti($template, $phones, $params);
```

 **地图**```
use Higreen\Api\Tencent\Map;

$Map = new Map('key');
```

1. 地址定位 ```
    $res = $Map->locateByAddress($address);
    ```
2. IP定位 ```
    $res = $Map->locateByIp($ip);
    ```
3. 坐标定位 ```
    $res = $Map->locateByCoordinate($longitude, $latitude);
    ```
4. 查询行政区域 ```
    $res = $Map->getDistrict($id = 0);// 子级行政区划
    ```

 **人脸核身**```
use Higreen\Api\Tencent\Faceid;

$Faceid = new Faceid([
    'id'  => '密钥 ID',
    'key' => '秘钥 KEY',
]);
```

1. 身份信息认证 ```
    $bool = $Faceid->verifyNameNumber('姓名', '身份证号码');
    ```

### 移动

[](#移动)

 **号码认证**```
use Higreen\Api\Yidong\NumIdentify;

$init = [
    'app_id' => 'APPID',
    'app_key' => 'APPKEY',
    'public_key' => '平台公钥',
    'private_key' => '应用私钥.创建应用时,请使用同一对密钥',
];
$NumIdentify = new NumIdentify($init);
```

1. 获取手机号

    ```
    $phone = $NumIdentify->getPhoneNumber('token 业务凭证');

    ```
2. 本机号码校验

    ```
    $bool = $NumIdentify->isDevicePhone('未实现');

    ```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

1133d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/33834535?v=4)[Green](/maintainers/higreen)[@higreen](https://github.com/higreen)

---

Top Contributors

[![higreen](https://avatars.githubusercontent.com/u/33834535?v=4)](https://github.com/higreen "higreen (37 commits)")

---

Tags

green

### Embed Badge

![Health badge](/badges/higreen-php-api/health.svg)

```
[![Health](https://phpackages.com/badges/higreen-php-api/health.svg)](https://phpackages.com/packages/higreen-php-api)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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