2017 © Pedro Peláez
 

library cn-oauth

a library for wechat,alipay,weibo OAuth2 Client

image

suntianxiang/cn-oauth

a library for wechat,alipay,weibo OAuth2 Client

  • Saturday, February 10, 2018
  • by suntianxiang
  • Repository
  • 1 Watchers
  • 2 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

# CnOAuth

一个简单、开箱即用的OAuth2客户端, (*1)

TravisCI, (*2)

supported list 支持列表

  1. alipay 支付宝
  2. wechat 微信 公众号 网页登录
  3. weibo 微博

4. eleme 饿了么商户

requires

  • php >= 7.0
  • openssl (if using alipay)
  • guzzlehttp ^6.3

install 安装

using composer, (*3)

composer require suntianxiang/cn-oauth

usage 使用

  1. wechat 微信

redirect.php, (*4)

    # 微信
    $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, (*5)

    # 微信
    $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 {
        // 用户取消授权
    }
  1. alipay 支付宝

redirect.php, (*6)

$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, (*7)

    $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 定义自己的提供者

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

The Versions

10/02 2018

dev-master

9999999-dev

a library for wechat,alipay,weibo OAuth2 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by 孙天相

05/02 2018

0.2.0

0.2.0.0

a library for wechat,alipay,weibo OAuth2 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by 孙天相

18/12 2017

0.1.0

0.1.0.0

a library for wechat,alipay,weibo OAuth2 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by 孙天相