PHPackages                             shen2/zenapi - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. shen2/zenapi

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

shen2/zenapi
============

一个更好的OAuth2访问类，同时支持微博、微信、QQ空间、腾讯微博、人人、百度、搜狐、开心、豆瓣、Google、Instagram、土豆、优酷、奇艺等社交网站

54747↓50%13PHP

Since Jul 16Pushed 10y ago6 watchersCompare

[ Source](https://github.com/shen2/zenapi)[ Packagist](https://packagist.org/packages/shen2/zenapi)[ RSS](/packages/shen2-zenapi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ZenAPI
======

[](#zenapi)

通过一个统一风格的OAuth2访问库，统一各大社交网站接口。

安装方法
----

[](#安装方法)

ZenAPI需要php5.3+，唯一的依赖是curl extension。

ZenAPI遵循PSR-4规范。只需在composer.json中添加依赖：

```
    ...
    "require": {
        ...
        "shen2/zenapi": "dev-master"
    }
    ...

```

然后

```
$ composer install

```

OAuth2类和授权流程
------------

[](#oauth2类和授权流程)

OAuht2类是包含了生成授权地址，获取token的方法。

- 跳转到社交网站的授权页

```
$config = array(
	'akey' => 'app key',
	'skey' => 'secret key',
	'scope' => 'email,friendships_groups_read',
);
$oauth = new ZenAPI\WeiboOAuth2($config['akey'], $config['skey']);  //初始化oauth
$params = array(
	'client_id'	=> $config['akey'],
	'redirect_uri'	=> 'callback',//设置回调
	'response_type'	=> 'code',
	'state'		=> 'made by md5 avoid crsf',
	'display'	=> null,
	'scope'		=> $config['scope'],
	'forcelogin'    => 0, //是否使用已登陆微博账号
);

$authorizeUrl = $oauth->authorizeURL() . "?" . http_build_query($params);
header('Location : ' . $authorizeUrl);
```

- 获取access\_token

```
//微博返回的code
$keys = array(
	'code'	=> $_REQUEST['code'],
	'redirect_uri'=> '{{redirec_uri}}',
);

//获取token
$token = $oauth->getAccessToken('code', $keys);
```

Client类和API访问方法
---------------

[](#client类和api访问方法)

- 首先用之前获得的access\_token实例化一个Client对象
- 然后就可以通过调用RESTful的方法，访问各种数据接口，如get()、post()、delete()

```
//根据上一步的acces_token实例化Client对象
$client = new ZenAPI\WeiboClient($token['access_token']);

//根据uid获取用户信息
$info = $client->get('users/show', array('uid'=>1739476392));

//删除一条微博
$data = $client->post('comments/destory', array('uid'=>1739476392, 'cid' => 'weiboid'));
```

目前支持的社交网站
---------

[](#目前支持的社交网站)

- 微博
- QQ
- 腾讯微博
- 人人
- 百度
- 搜狐
- 豆瓣
- 开心
- 多说
- Google
- Instagram
- Github
- 优酷
- 土豆
- 爱奇艺

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 54.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2515a1b7a6e85454fd15245886d030202007d1329757aa4bf0d0123f49789279?d=identicon)[shen2](/maintainers/shen2)

---

Top Contributors

[![shen2](https://avatars.githubusercontent.com/u/1523457?v=4)](https://github.com/shen2 "shen2 (25 commits)")[![maliemin-Mstar](https://avatars.githubusercontent.com/u/3032500?v=4)](https://github.com/maliemin-Mstar "maliemin-Mstar (19 commits)")[![hikenote](https://avatars.githubusercontent.com/u/8486259?v=4)](https://github.com/hikenote "hikenote (2 commits)")

### Embed Badge

![Health badge](/badges/shen2-zenapi/health.svg)

```
[![Health](https://phpackages.com/badges/shen2-zenapi/health.svg)](https://phpackages.com/packages/shen2-zenapi)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

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