PHPackages                             chinayin/restapi-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. [API Development](/categories/api)
4. /
5. chinayin/restapi-sdk

ActiveLibrary[API Development](/categories/api)

chinayin/restapi-sdk
====================

restapi sdk

v1.4.2(8mo ago)09.9k↓20.5%1[2 PRs](https://github.com/chinayin/restapi-sdk/pulls)1Apache-2.0PHPPHP &gt;=7.2

Since Nov 16Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/chinayin/restapi-sdk)[ Packagist](https://packagist.org/packages/chinayin/restapi-sdk)[ Docs](http://github.com/chinayin/restapi-sdk)[ RSS](/packages/chinayin-restapi-sdk/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (55)Used By (1)

RestAPI PHP SDK
===============

[](#restapi-php-sdk)

[![Author](https://camo.githubusercontent.com/c81fe059489a5ff135b4a16cb4193135426863c4e0f69d804fde4244b5d306eb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406368696e6179696e2d626c75652e737667)](https://github.com/chinayin)[![Software License](https://camo.githubusercontent.com/1a71f03cc9974f9d8ffd61fe4a80db97f4b1ce333478e07c6b7c85f44d804609/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4170616368652d2d322e302d627269676874677265656e2e737667)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/1e8e0e154362ba6be46e9b0c3d3c88bc1b31fb384b9275c492e6bfdafdfa4ccc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696e6179696e2f726573746170692d73646b2e737667)](https://packagist.org/packages/chinayin/restapi-sdk)[![Build Status](https://camo.githubusercontent.com/bb21b4ba8555e00b7f4dc58a3fc11f6366ec7fca44ea48169e556d1ab7dbad50/68747470733a2f2f7472617669732d63692e6f72672f6368696e6179696e2f726573746170692d73646b2e7376673f6272616e63683d302e34)](https://travis-ci.org/chinayin/restapi-sdk)[![Total Downloads](https://camo.githubusercontent.com/90b92cb0e15458dad32e7df4729764924ed9bbbf370e46038cd0f2aad23eb8cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368696e6179696e2f726573746170692d73646b2e737667)](https://packagist.org/packages/chinayin/restapi-sdk)[![php 7.2+](https://camo.githubusercontent.com/2376755214318dbed6b54c54d063cd49a92f9116f93a173fca1952d529376fd6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d6d696e253230372e322d7265642e737667)](https://camo.githubusercontent.com/2376755214318dbed6b54c54d063cd49a92f9116f93a173fca1952d529376fd6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d6d696e253230372e322d7265642e737667)

安装
--

[](#安装)

运行环境要求 PHP 7.2 及以上版本，以及 [cURL](http://php.net/manual/zh/book.curl.php)。

#### composer 安装

[](#composer-安装)

如果使用标准的包管理器 composer，你可以很容易的在项目中添加依赖并下载：

```
composer require chinayin/restapi-sdk
```

初始化
---

[](#初始化)

完成上述安装后，需要对 SDK 初始化。 同时联系技术同学，获取SYS\_ID 和 SECRET\_KEY。 然后在项目中加载 SDK，并初始化：

#### REGION

[](#region)

regionremarktesting测试环境uat预上线环境cn线上国内hk线上香港us线上美国```
// 如果是 composer 安装
// require_once("vendor/autoload.php");

// 如果是手动安装
require_once("vendor/restapi-sdk/src/autoload.php");

//// SSO使用下面这个
// 参数依次为 sys-id, secret-key, access-token
RestAPI\Client::initialize("sys_id", "secret_key", "access_token");

//// SERVICE_API使用这个
// 参数依次为 sys-id, secret-key, region
RestAPI\RestServiceClient::initialize("sys_id", "secret_key", "region");
```

使用示例
----

[](#使用示例)

#### 客户端请求

[](#客户端请求)

##### SsoAPI 服务

[](#ssoapi-服务)

```
use RestAPI\Client;
use RestAPI\CloudException;

try {
    $response = Client::get('/api/oauth/get');
    $response = Client::post('/api/oauth/checklogin',[]);
    $response = Client::put('/api/oauth/put',[]);
    $response = Client::delete('/api/oauth/delete',[]);
} catch (CloudException $ex) {
    // 如果返回错误，这里会抛出异常 CloudException
    // 错误格式 错误码不为0都为报错
    // { "error_code": 1, "message": "error" }
}
```

##### ServiceAPI 服务

[](#serviceapi-服务)

```
use RestAPI\RestServiceClient;
use RestAPI\RestAPIException;

try {
    $response = RestServiceClient::get('/api/oauth/get');
    $response = RestServiceClient::post('/api/oauth/checklogin',[]);
    $response = RestServiceClient::put('/api/oauth/put',[]);
    $response = RestServiceClient::delete('/api/oauth/delete',[]);
} catch (RestAPIException $ex) {
    // 如果返回错误，这里会抛出异常 RestServiceClient
    // 错误格式 错误码不为0都为报错
    // { "error_code": 1, "message": "error" }
    // $ex->getData();
}
```

```
// 精简用法(须配置env)
RestServicePost($path, $params, $headers = [])
RestServiceGet($path, $params, $headers = [])

$resp = RestServicePost('/api/oauth/checklogin',['username'=>'a']);

// 超时时间设置(2s)
$resp = RestServiceGet('/api/oauth/get',[],['timeout'=>2]);

// 依照本地环境生成服务网址
$url = RestServiceBuildRequestUrl('/api/oauth/get');
```

##### env配置

[](#env配置)

```
[restapi]
sys_id = 1
secret_key = xxxx
region = xx
# 当需要单独配置连接域名时
# server_url = rest.xxxx.local

```

感谢
--

[](#感谢)

leancloud

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance60

Regular maintenance activity

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

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

Recently: every ~108 days

Total

53

Last Release

250d ago

Major Versions

0.7.x-dev → v1.0.02022-03-08

PHP version history (2 changes)0.1.0PHP &gt;=7.0

v0.4PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10531946?v=4)[Leo](/maintainers/chinayin)[@chinayin](https://github.com/chinayin)

---

Top Contributors

[![chinayin](https://avatars.githubusercontent.com/u/10531946?v=4)](https://github.com/chinayin "chinayin (88 commits)")

---

Tags

sdkrestapi

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chinayin-restapi-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/chinayin-restapi-sdk/health.svg)](https://phpackages.com/packages/chinayin-restapi-sdk)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[saloonphp/saloon

Build beautiful API integrations and SDKs with Saloon

2.4k9.6M468](/packages/saloonphp-saloon)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[resend/resend-php

Resend PHP library.

564.7M21](/packages/resend-resend-php)

PHPackages © 2026

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