PHPackages                             suntianxiang/cn-oauth - 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. suntianxiang/cn-oauth

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

suntianxiang/cn-oauth
=====================

a library for wechat,alipay,weibo OAuth2 Client

0.2.2(4y ago)2582MITPHPPHP &gt; 7.0

Since Dec 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/suntianxiang/CnOAuth)[ Packagist](https://packagist.org/packages/suntianxiang/cn-oauth)[ RSS](/packages/suntianxiang-cn-oauth/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (3)Versions (7)Used By (0)

CnOAuth
=======

[](#cnoauth)

---

一个简单、开箱即用的OAuth2客户端

[![TravisCI](https://camo.githubusercontent.com/5fc3dfe25c9ef6882fe072ee4a62925c841a278e2548d17442090c41f7d816a3/68747470733a2f2f7472617669732d63692e6f72672f73756e7469616e7869616e672f436e4f417574682e737667)](https://travis-ci.org/suntianxiang/CnOAuth)

### supported list 支持列表

[](#supported-list-支持列表)

1. alipay 支付宝
2. wechat 微信 公众号 网页登录
3. weibo 微博
4. eleme 饿了么商户

---

### requires

[](#requires)

- php &gt;= 7.0
- openssl (if using alipay)
- guzzlehttp ^6.3

### install 安装

[](#install-安装)

using composer

```
composer require suntianxiang/cn-oauth
```

### usage 使用

[](#usage-使用)

1. wechat 微信

redirect.php

```
    # 微信
    $wechat = new \CnOAuth\Provider\WechatOfficialAccount([
        'clientId' => 'you client id',
        'clientSecret' => 'you client secret',
        'redirectUri' => 'redirect uri'
    ]);

    $url = $wechat->getAuthorizationUrl([
        'scope' => $wechat->getDefaultScopes(),
        'state' => 'state'
    ]);

    header('Location: '.$url);
```

callback.php

```
    # 微信
    $wechat = new \CnOAuth\Provider\WechatOfficialAccount([
        'clientId' => 'you client id',
        'clientSecret' => 'you client secret',
        'redirectUri' => 'redirect uri'
    ]);
    $grant = $wechat->getGrant('authorization');

    if ($grant->getCode()) {
        $access_token = $wechat->getAccessToken($grant);

        $owner = $wechat->getResourceOwner($access_token);

        print_r($owner->toArray());
    } else {
        // 用户取消授权
    }
```

2. alipay 支付宝

redirect.php

```
$alipay = new \CnOAuth\Provider\Alipay([
    'gatewayUrl' => 'https://openapi.alipay.com/gateway.do',
    'clientId' => '2017090408550236',
    'rsaPrivateKey' => 'your private key',
    'alipayrsaPublicKey' => 'your alipay public key [支付宝公钥]',
    'apiVersion' => '1.0',
    'signType' => 'RSA2',
    'postCharset' => 'UTF-8',
    'format' => 'json',
    'redirectUri' => 'you callback url'
]);

$url = $alipay->getAuthorizationUrl([
    'scope' => $provider->getDefaultScopes(),
    'state' => mt_rand(1000, 9999)
]);

header('Location: '.$url);
```

callback.php

```
    $alipay = new \CnOAuth\Provider\Alipay([
        'gatewayUrl' => 'https://openapi.alipay.com/gateway.do',
        'clientId' => '2017090408550236',
        'rsaPrivateKey' => 'your private key',
        'alipayrsaPublicKey' => 'your alipay public key [支付宝公钥]',
        'apiVersion' => '1.0',
        'signType' => 'RSA2',
        'postCharset' => 'UTF-8',
        'format' => 'json',
        'redirectUri' => 'you callback url'
    ]);

    $grant = $alipay->getGrant('authorization');

    if ($grant->getCode()) {
        $access_token = $alipay->getAccessToken($grant);

        $owner = $alipay->getResourceOwner($access_token);

        print_r($owner->toArray());
    } else {
        // user cancel auth
    }
```

### Define Provider 定义自己的提供者

[](#define-provider-定义自己的提供者)

```
1. create a provider 继承AbstractProvider
    See CnOAuth\Provider\AbstractProvider.php
        CnOAuth\Provider\ResourceOwnerInterface.php
2. create a grant type 继承AbstractGrant
    See CnOAuth\Grant\AbstractGrant
3. implements ResourceOwnerInterface

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Total

4

Last Release

1545d ago

### Community

Maintainers

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

---

Top Contributors

[![suntianxiang](https://avatars.githubusercontent.com/u/9280445?v=4)](https://github.com/suntianxiang "suntianxiang (20 commits)")

---

Tags

alipay-oauthoauth2phpwechat

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/suntianxiang-cn-oauth/health.svg)

```
[![Health](https://phpackages.com/badges/suntianxiang-cn-oauth/health.svg)](https://phpackages.com/packages/suntianxiang-cn-oauth)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[google/auth

Google Auth Library for PHP

1.4k286.7M205](/packages/google-auth)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19664.8M1.6k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M398](/packages/drupal-core-recommended)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751284.3k37](/packages/civicrm-civicrm-core)

PHPackages © 2026

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