用户登录流程:
小程序调用 wx.login 后获得 code ,调用 laravel-wechat 的login 接口
https://depscreen.studentvision.cn/api/wechat/mini/login
返回 用户个人信息 openid accessToken 等
{
"error_code": 0,
"data": {
"access_token": "bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2RlcHNjcmVlbi5zdHVkZW50dmlzaW9uLmNuL2FwaS93ZWNoYXQvbWluaS9sb2dpbiIsImlhdCI6MTczMzk4NzMzMCwiZXhwIjoxNzMzOTkwOTMwLCJuYmYiOjE3MzM5ODczMzAsImp0aSI6IkFUTTloR1dvU1VuNjlaWWgiLCJzdWIiOiIxIiwicHJ2IjoiNDI1MTRkODBlZTM4NWRhODRjYTM4YWY0NTgyZThmNTRiYjRjZmIzOSJ9.qLXirUDL8GJjkg3LS47_J1LEpdA5j02VgyfUrt6RrpY",
"expires_in": 3600,
"wechat_user": {
"id": 1,
"app_id": "wx621e0fe15a370854",
"user_id": "0",
"openid": "oLG3w68wIQoTn5BwLOVyREIMtiFM",
"nickname": null,
"avatar": null,
"gender": "0",
"country": null,
"province": null,
"city": null,
"subscribed_at": null,
"created_at": "2024-12-11T04:15:17.997000Z",
"updated_at": "2024-12-11T04:15:17.997000Z",
"gender_readable": null
}
}
}
之后的每个请求都要带上 该jwt access token 作为通信票据以保证安全
Accept:application/json
Content-Type:application/json
Authorization:bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2RlcHNjcmVlbi5zdHVkZW50dmlzaW9uLmNuL2FwaS93ZWNoYXQvbWluaS9sb2dpbiIsImlhdCI6MTczMzk4NzMzMCwiZXhwIjoxNzMzOTkwOTMwLCJuYmYiOjE3MzM5ODczMzAsImp0aSI6IkFUTTloR1dvU1VuNjlaWWgiLCJzdWIiOiIxIiwicHJ2IjoiNDI1MTRkODBlZTM4NWRhODRjYTM4YWY0NTgyZThmNTRiYjRjZmIzOSJ9.qLXirUDL8GJjkg3LS47_J1LEpdA5j02VgyfUrt6RrpY
controller 增加一个middleware 作为checking
Route::middleware('auth:mini')
具体实现类是
这个作为jwt入口
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
php artisan jwt:secret
该命令可以重新生成jwt 私钥