suntianxiang/cn-oauth
Composer 安装命令:
composer require suntianxiang/cn-oauth
包简介
a library for wechat,alipay,weibo OAuth2 Client
README 文档
README
一个简单、开箱即用的OAuth2客户端
supported list 支持列表
- alipay 支付宝
- wechat 微信 公众号 网页登录
- weibo 微博
- eleme 饿了么商户
requires
- php >= 7.0
- openssl (if using alipay)
- guzzlehttp ^6.3
install 安装
using composer
composer require suntianxiang/cn-oauth
usage 使用
- 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 { // 用户取消授权 }
- 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 定义自己的提供者
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
suntianxiang/cn-oauth 适用场景与选型建议
suntianxiang/cn-oauth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 12 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 suntianxiang/cn-oauth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 suntianxiang/cn-oauth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-17