Download the PHP package huoshaotuzi/sociate without Composer

On this page you can find all versions of the php package huoshaotuzi/sociate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sociate

sociate for laravel

基于 Laravel 开发的第三方登录插件,支持 QQ、新浪微博、百度、Github、微信公众号登录。

演示地址:火兔游戏

更新记录

安装

config/app.php 注册服务器提供者:

发布配置文件到 config 目录下:

.env 文件添加第三方应用配置信息,不需要的可以不用添加:

*_KEYAPP_KEY,不同平台的叫法可能不同,统称应用 ID,微信公众号为 APPID;

*_SECRETSECRET,一串随机的字符串,应用密匙,要注意该字段不能暴露给用户;

*_REDIRECT 即授权回调页地址,百度与微博、微信公众号可以在配置应用自行设置, QQ 貌似不支持。

以上,配置完成。

流程说明

第三方登录其实就是第三方平台给你一个跳转到他们页面的链接,用户点击授权之后,第三方平台会携带一个 code 参数和你自定义的 state 字段重定向到你在应用配置的授权回调页地址,通过 code 换取用户的 access_token,再用 access_token 换取用户资料,最后把资料保存下来。

微信公众号登录(非微信网页扫码登录)

微信公众号官方文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842

由于微信公众号比其他平台更复杂一点,因此在这里特别进行介绍,如果是刚入门的小白则可以快速入手。

首先需要一个公众号,个人申请的订阅号无法开通获取用户的权限,因此这个公众号必须是服务号或者是已认证的订阅号。

个人开发者或者本地测试时可以申请微信测试号,测试号可以测试公众号的各个接口,测试号申请地址: http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login

开发过程中一般要使用测试号进行开发,测试完毕没有问题的时候,产品上线阶段再修改配置文件的 APP_IDSECRET

开发还需要下载微信 web 开发者工具,下载地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455784140

参照官方说明。

通过开发者ID及密码调用获取 access_token 接口时,需要设置访问来源IP为白名单。

以上准备完毕。

公众号登录授权获取用户信息有两种,在传入 scope 参数时进行区分。 参照官方说明:

关于网页授权的两种scope的区别说明 以snsapi_base为scope发起的网页授权,是用来获取进入页面的用户的openid的,并且是静默授权并自动跳转到回调页的。

用户感知的就是直接进入了回调页(往往是业务页面)

以snsapi_userinfo为scope发起的网页授权,是用来获取用户的基本信息的。

但这种授权需要用户手动同意,并且由于用户同意过,所以无须关注,就可在授权后获取该用户的基本信息。

本插件默认使用 snsapi_userinfo 参数。

接下来进入开发流程,首先需要在 .env 文件配置你的应用信息,接着在 routes/web.php 创建两个路由地址:

我这里使用的 /auth 即为授权回调地址,在 .env 将 WECHAT_REDIRECT 设置为 http://127.0.0.1:8000/auth

在公众号测试号页面拉到底部,体验接口权限表下找到“网页帐号-网页授权获取用户基本信息”右侧点击“修改”。

授权回调页面域名:127.0.0.1:8000

点击确认进行保存。

创建路由对应控制器及方法:

以上就完成了公众号授权获取用户信息。

基本方法

首先需要在登录页面添加第三方登录引导链接:

driver($type) 方法接收第三方平台参数,该值可以是 qqweibobaidu,不区分大小写(后续更新会支持更多平台)。

getLoginUrl($state) 方法支持一个参数 state 作为返回参数,授权成功后该值会原样返回,不传默认为空。

可以在登录页视图的第三方登录按钮中,使用如下代码:

登录成功后使用 request('state') 获取到登录前的页面,再进行重定向跳转,增加用户体验。

接下来在 routes/web.php 添加授权回调页路由,授权回调页的地址应该与你的应用配置一致,否则会提示 redirect_uri 错误:

本地开发时,回调页填写 http://127.0.0.1:8000(默认端口)

创建第三方登录控制器:

控制器添加代码:

值得一提的是,我们只要用到授权登录功能,因此 access_tokenrefresh_token 对我们来说没有意义,可以不用保存下来,除非后续需要调用其他接口,像读取用户微博等, token 的值会在获取的时候刷新,如果要用到的话记得更新记录。

在控制器中使用

如果不想使用 use 引入,或在视图不方便使用命名空间,则可使用 Laravel 提供的辅助方法 app() 来调用,比较推荐用这种方法。


All versions of sociate with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
guzzlehttp/guzzle Version ^6.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package huoshaotuzi/sociate contains the following files

Loading the files please wait ....