Git Product home page Git Product logo

oauth's Introduction

配置

install

composer require jsanf/oauth

config.php

return [
    'Wechat' => [
        'appid' => 'wxedfaa675aa',        //个人微信appid
        'secret'=> '0a4ab6706702585c043c3d70245',      
        'redirect_uri' => 'https://member-sso.pxo.cn/user/receive'  //回调地址
    ],
    'Wxwork' => [
        'agentid' => '1000170',
        'redirect_uri' => 'https://member-sso.pxo.cn/user/receive',     //回调地址

        //第三方应用
        'appid' => 'wwe394e1149a61',                                //suiteId
        'secret' => 'lQUGcC-5yScSKPGnheKuwB7CMCUOPk4ZM',      //suite_secret
        'token' => 'XPOLhzU227GemS',
        'EncodingAESKey' => '1QBd6iL5qKsjY0HsBA4vPtwBm8NSRz',

        //suite_ticket 缓存名称
        'suiteTicketCacheKey' => 'member:suite_ticket'
    ]
]

simple

    /**
     * 第三方登录
     */
    public function third()
    {
        $oauth = (new Oauth)->getInstance("Wechat", $config['Wechat'] ?? '');
        if(!$oauth) {
            echo "该登录方式不存在.";
            exit;
        }
        $param['return_url'] = $this->get['return_url'];
        $param['oauth_type'] = 'Wechat';
        //$param['scope'] = $this->get['scope'] ?? 'snsapi_base';
        $oauth->code($param);
    }

    /**
     * 第三方回调
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function receive()
    {
        $config = $config['Wechat'] ?? [];
        if(!$config) {
            echo 'oauth_type有误.';exit;
        }

        $config['return_data'] = $this->get;
        $oauth = (new Oauth)->getInstance('Wechat', $config);
        $userInfo = $oauth->userInfo();

        $token = $userInfo['openid'];

        //保存用户信息

        //缓存用户信息到redis缓存
        $this->redis::set('member:'.$token, $userInfo);

        header("Location:" . $_GET['return_url'] . '?token=' . $token);
    }

oauth's People

Contributors

jsanf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.