PHPackages                             anerg2046/sns\_auth - 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. anerg2046/sns\_auth

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

anerg2046/sns\_auth
===================

weixin weibo qq alipay twitter google line facebook sns oauth

v2.0.11(4y ago)62012.2k—0%186[5 issues](https://github.com/anerg2046/sns_auth/issues)MITPHPPHP &gt;=5.6.0

Since Dec 14Pushed 4y ago28 watchersCompare

[ Source](https://github.com/anerg2046/sns_auth)[ Packagist](https://packagist.org/packages/anerg2046/sns_auth)[ RSS](/packages/anerg2046-sns-auth/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (1)Versions (24)Used By (0)

通用第三方登录说明文档
===========

[](#通用第三方登录说明文档)

[![GitHub stars](https://camo.githubusercontent.com/b2aa2bda91f93b895009d84962d36800aec5e29d5421e0199155302c87e03ebc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f616e657267323034362f736e735f617574682e737667)](https://github.com/anerg2046/sns_auth/stargazers)[![GitHub forks](https://camo.githubusercontent.com/49c90fd881102b2e52db874435902a45e506e64c99570420987617078482e113/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f616e657267323034362f736e735f617574682e737667)](https://github.com/anerg2046/sns_auth/network)[![GitHub issues](https://camo.githubusercontent.com/962816248e0d2a0ff15609273f8c0ed074ef18e49a778e45068ea7aeed66cd6c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f616e657267323034362f736e735f617574682e737667)](https://github.com/anerg2046/sns_auth/issues)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3ea6e4c99efffdf45b4992f026565060611aee67ce1dc50597c9cd879468dc40/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616e657267323034362f736e735f617574682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/anerg2046/sns_auth/?branch=master)[![Build Status](https://camo.githubusercontent.com/ca3eda0ed964cabe4005fd5f1e0a22a6381f6520676f91f34bea7c3f40061385/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616e657267323034362f736e735f617574682f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/anerg2046/sns_auth/build-status/master)[![Latest Stable Version](https://camo.githubusercontent.com/be315a31e19e10c951ab200f8face93fda111fa8d0c2f17918f114c7554b78da/68747470733a2f2f706f7365722e707567782e6f72672f616e657267323034362f736e735f617574682f762f737461626c65)](https://packagist.org/packages/anerg2046/sns_auth)[![Total Downloads](https://camo.githubusercontent.com/aec879be3ffdcb6e0d21bc516c9d60a0bec1ce88f0a5ee89ed1b3e14e525bac4/68747470733a2f2f706f7365722e707567782e6f72672f616e657267323034362f736e735f617574682f646f776e6c6f616473)](https://packagist.org/packages/anerg2046/sns_auth)[![License](https://camo.githubusercontent.com/09cb8e3807ff2f19fc866094b698eb84a2237c784f91465f69360392360606b5/68747470733a2f2f706f7365722e707567782e6f72672f616e657267323034362f736e735f617574682f6c6963656e7365)](https://packagist.org/packages/anerg2046/sns_auth)[![PHP Version](https://camo.githubusercontent.com/132eb2fad8bc173f1489c3481e81763d1a02b392a4e55bd35eb0a1fc8b5d1ee5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344352e362d3838393242462e737667)](http://www.php.net/)

2.0 版本全新发布，目前支持的登录平台包括：

- 微信
- QQ
- 微博
- 支付宝
- Facebook
- Twitter
- Line
- Google

### 安装

[](#安装)

```
composer require anerg2046/sns_auth

```

> 类库使用的命名空间为`\\anerg\\OAuth2`

### 目录结构

[](#目录结构)

```
.
├── README.md                        说明文件
├── composer.json                    composer文件
├── src                              代码源文件目录
│   ├── Connector
│   │   ├── Gateway.php              必须继承的抽象类
│   │   └── GatewayInterface.php     必须实现的接口
│   ├── Gateways
│   │   ├── Alipay.php
│   │   ├── Facebook.php
│   │   ├── Google.php
│   │   ├── Line.php
│   │   ├── Qq.php
│   │   ├── Twitter.php
│   │   ├── Weibo.php
│   │   └── Weixin.php
│   ├── Helper
│   │   └── Str.php                  字符串辅助类
│   └── OAuth.php                    抽象实例类
└── wx_proxy.php                     微信多域名代理文件

```

### 公共方法

[](#公共方法)

在接口文件中，定义了 4 个方法，是每个第三方基类都必须实现的，用于相关的第三方登录操作和获取数据。方法名如下：

```
    /**
     * 得到跳转地址
     */
    public function getRedirectUrl();

    /**
     * 获取当前授权用户的openid标识
     */
    public function openid();

    /**
     * 获取格式化后的用户信息
     */
    public function userinfo();

    /**
     * 获取原始接口返回的用户信息
     */
    public function userinfoRaw();
```

微信有一个额外的方法，用于获取代理请求的地址

```
    /**
     * 获取中转代理地址
     */
    public function getProxyURL();
```

### 典型用法

[](#典型用法)

以 ThinkPHP5 为例

```
