liliuwei/youquanya-social

有券呀(www.youquanya.com)授权登录扩展

Installs: 8 219

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:think-extend

v1.1 2021-01-13 05:14 UTC

This package is auto-updated.

Last update: 2021-10-13 08:03:45 UTC


README

有券呀(www.youquanya.com)授权登录扩展

安装(扩展包)

composer require liliuwei/youquanya-social

配置Config信息

// 安装之后会在config目录里自动生成youquanya_social.php配置文件
<?php
return [
    //有券呀登录配置
    'youquanya' => [
        'app_key' => '*******', //应用注册成功后分配的 APP ID
        'app_secret' => '*******',  //应用注册成功后分配的KEY
        'callback' => 'http://www.youquanya.com/oauth/callback/type/youquanya', // 应用回调地址
    ]
];

用法示例

<a href="{:url('Oauth/login',['type'=>'youquanya'])}">登录</a>
//设置路由
Route::get('oauth/callback','index/oauth/callback');
<?php

namespace app\index\controller;
use think\Controller;
class Oauth extends Controller
{
    //登录地址
        public function login($type = null)
        {
            if ($type == null) {
                $this->error('参数错误');
            }
            // 获取对象实例
            $sns = \youquanya\social\Oauth::getInstance($type);
            //跳转到授权页面
            $this->redirect($sns->getRequestCodeURL());
        }
    
        //授权回调地址
        public function callback($type = null, $code = null)
        {
            if ($type == null || $code == null) {
                $this->error('参数错误');
            }
            $sns = \youquanya\social\Oauth::getInstance($type);
            // 获取TOKEN
            $token = $sns->getAccessToken($code);
            //获取当前第三方登录用户信息
            if (is_array($token)) {
                $user_info = \youquanya\social\GetInfo::getInstance($type, $token);
                dump($user_info);// 获取用户资料
                echo '登录成功!!';
                echo '正在持续开发中,敬请期待!!';
            } else {
                echo "获取用户的基本信息失败";
            }
        }
}