Php laravel framework quick integration login, laravel framework
The final solution is: https://github.com/liuyunzhuge/php_weixin_provider. For more information, see the following.
This article is intended for users of the php laravel framework and introduces a simple integrated login Method Based on this framework. The usage is as follows:
1. Install php_weixin_provider
Run composer require thirdproviders/weixin in the project to complete the installation. After the installation is successful, you should be able to see the php_weixin_provider library file under the vendor directory of the project:
// Use a proxy to log on to the Route: get ('/login', function () {return Societe: with ('weixin ') -> setProxyUrl ('HTTP: // proxy.your.com ')-> setRedirectUrl (url ('/login/notify')-> redirect ();}); // use a proxy to log on to the Route: get ('/login2', function () {return Societe: with ('weixin ') -> setProxyUrl ('HTTP: // proxy.your.com ')-> setDevice ('')-> setRedirectUrl (url ('/login/notify ')) -> redirect () ;}); // do not use proxy jump. log on to the Route: get ('/login', function () {return Societe :: with ('weixin')-> setRedirectUrl (url ('/login/notify')-> redirect () ;}); // do not use proxy jump, log on to the Route: get ('/login4', function () {return Societe: with ('weixin')-> setDevice ('') -> setRedirectUrl (url ('/login/logy')-> redirect ();});
Sociate:: with ('weixin') will return the instance of php_weixin_provider, that is, it:
// Logon callback Route: get ('/login/logs y', function () {$ user = null; try {$ user = sociate::: with ('weixin ') -> user ();} catch (\ Exception $ e) {return 'get user exception';} return $ user-> nickname ;});
After the php_weixin_provider instance is obtained through sociate:: with ('weixin'), the user method is called automatically and the relevant interface is called, and the returned value is encapsulated into an object for returning. If any errors occur during this process, they will be thrown in the form of exceptions, such as state parameter verification failure, or code failure.
The returned $ user object contains the following valid attributes:
Summary:
This solution is implemented based on laravel/Societe and released to composer. Laravel/Societe is a third-party login module officially provided by laravel. Based on this module, it can easily integrate the authentication of most third-party platforms. Currently, it has provided many third-party login implementations: https://socialiteproviders.github.io /. In addition to facebook, google, github, and other foreign websites, domestic websites, Weibo, and qq are also provided. At the beginning, I used the default logon provider provided by the official website, but later I found the following problems:
1. Authorization proxy not supported;
2. The pc end and the mobile end are actually implemented in two projects:
3. The encapsulated user object does not contain the unionid.
4. It is difficult to change the configuration parameters:
Therefore, based on its official logon provider, I implemented a new solution based on my own ideas to solve these problems I found.