Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the combination of laravel passport and SMS login?

Shulou Source: shulou.com Published: 2022-06-02 05:10:16 10月03日 Update

This article mainly explains "what is the combination of laravel passport and SMS login". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the combination of laravel passport and SMS login?"

Preparation steps

Laravel passport environment

How to install and how to use it, just read the documentation. Here, record the hole with SMS and how to combine with passport.

Kengichi

Easy-sms package interfacing with Tencent Cloud, please use version 1.3 and version 2.0 will consistently report that the error cannot be sent. I have repeatedly tested it several times, which is simply killing me, and if code contains letters, he will prompt me that there is something wrong with my signature. The interface of Tencent Cloud under the real name diss is speechless.

Pit two

Judge CAPTCHA match, create a user, then how to give him token, Baidu has a bunch of methods, everything is miscellaneous, everything has been tried, not only support laravel5 or version, otherwise what kind of simply

If ($innerVerificationCode==$verificationCode) {/ / CAPTCHA is successful, which is judged by the fact that the user of this mobile phone is in the database. If the token is not created immediately, give him token $user=User::query ()-> where ('phone_number', $phoneNumber)-> first (); if (! $user) {$user= new User (); $user- > name = $phoneNumber; $user- > phone_number= $phoneNumber; $user- > login_type=User::USER_LOGIN_TYPE_PHONE; $user- > password = bcrypt (' 12345678') $user- > save ();} return $this- > getToken ($user, 'id');} / / has been struggling with how to give him access_token directly without an account password, but has not failed for various reasons? then the api request public function getToken ($user, $type) {$http = new\ GuzzleHttp\ Client () $response = $http- > post (config ('app.url').' / api/fund/oauth/token', ['form_params' = > [' grant_type' = > 'password',' username' = > $user- > $type,// user name that can be directly logged in to the user, after configuration, can also be a mailbox, version 5.8 This defaults to the registered mailbox 'password' = >' 12345678 password corresponding to 'scope' = >' *',],]) Return json_decode ($response- > getBody (), false);}

The code of the access_token API is as follows:

Tags: Mobile phone method user SMS login version success content parameters password interface user name email Tencent learning verification practical deeper Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker macOS Shulou Technology Shulou Tech Info