Commit de75d67a by lujunyi

小程序登录示例,搭建小程序api基础结构

parent 7ded0420
<?php
namespace App\Api\Controllers;
use App\Http\Controllers\BaseApiController;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends BaseApiController
{
public function userInfo()
{
$userId = auth('api')->user()->id;
$data = ['abcde' => 111, 'role' => '问诊人', 'id' => $userId];
return $this->success($data);
}
// 小程序静默登录,如果没有记录则生成一条
public function login(Request $request)
{
$code = $request->input('code');
$credentials = app('wechat.mini_program')->auth->session($code);
if ($credentials['openid'] ?? '') {
$user = User::firstOrCreate(['miniapp_openid', $credentials['openid']]);
$token = auth('api')->claims(['role' => '问诊人'])->fromUser($user);
// $data = $this->respondWithToken($token)->original;
$data = ['token' => $token];
return $this->success($data);
} else {
return $this->fail('登录错误~');
}
}
/**
* Log the user out (Invalidate the token).
*
* @return \Illuminate\Http\JsonResponse
*/
public function logout()
{
auth('api')->logout();
return response()->json(['message' => '退出成功~']);
}
/**
* Refresh a token.
* 刷新token,如果开启黑名单,以前的token便会失效。
* 值得注意的是用上面的getToken再获取一次Token并不算做刷新,两次获得的Token是并行的,即两个都可用。
*
* @return \Illuminate\Http\JsonResponse
*/
public function refresh()
{
return $this->respondWithToken(auth('api')->refresh());
}
/**
* Get the token array structure.
*
* @param string $token
* @return \Illuminate\Http\JsonResponse
*/
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 60,
]);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Response;
class BaseApiController extends Controller
{
/**
* 返回成功信息
*
* @param mixed $data
*/
public function success($data = [], string $message = 'success', int $code = Response::HTTP_OK): \Illuminate\Http\JsonResponse
{
return response()->json(['status' => true, 'code' => $code, 'message' => $message, 'data' => $data]);
}
/**
* 返回失败信息
*
* @param bool $status
*/
public function failed($data = [], string $message = 'fail', int $code = Response::HTTP_INTERNAL_SERVER_ERROR): \Illuminate\Http\JsonResponse
{
return response()->json(['status' => false, 'code' => $code, 'message' => $message, 'data' => $data]);
}
}
......@@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
* @var array<int, string>
*/
protected $except = [
//
'wechat',
];
}
......@@ -7,8 +7,9 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable
class User extends Authenticatable implements JWTSubject
{
use HasApiTokens, HasFactory, Notifiable;
......@@ -42,4 +43,25 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
// 下面是jwt-aut必须要实现的方法
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
}
......@@ -17,8 +17,10 @@
"laravel/tinker": "^2.8",
"overtrue/laravel-filesystem-cos": "^3.5",
"overtrue/laravel-query-logger": "^3.1",
"overtrue/laravel-wechat": "^6.0",
"predis/predis": "^2.2",
"sparkinzy/dcat-viewer": "^1.0"
"sparkinzy/dcat-viewer": "^1.0",
"tymon/jwt-auth": "^2.1"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.13",
......@@ -98,7 +100,8 @@
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"easywechat-composer/easywechat-composer": true
}
},
"minimum-stability": "dev",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "968a505b5ea9d58508587d9085546d77",
"content-hash": "bbf64803dc3b06e15e1d478d97b9269f",
"packages": [
{
"name": "box/spout",
......@@ -1051,6 +1051,54 @@
"time": "2024-10-09T13:47:03+00:00"
},
{
"name": "easywechat-composer/easywechat-composer",
"version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/mingyoung/easywechat-composer.git",
"reference": "3fc6a7ab6d3853c0f4e2922539b56cc37ef361cd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mingyoung/easywechat-composer/zipball/3fc6a7ab6d3853c0f4e2922539b56cc37ef361cd",
"reference": "3fc6a7ab6d3853c0f4e2922539b56cc37ef361cd",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0 || ^2.0",
"php": ">=7.0"
},
"require-dev": {
"composer/composer": "^1.0 || ^2.0",
"phpunit/phpunit": "^6.5 || ^7.0"
},
"type": "composer-plugin",
"extra": {
"class": "EasyWeChatComposer\\Plugin"
},
"autoload": {
"psr-4": {
"EasyWeChatComposer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "张铭阳",
"email": "mingyoungcheung@gmail.com"
}
],
"description": "The composer plugin for EasyWeChat",
"support": {
"issues": "https://github.com/mingyoung/easywechat-composer/issues",
"source": "https://github.com/mingyoung/easywechat-composer/tree/1.4.1"
},
"time": "2021-07-05T04:03:22+00:00"
},
{
"name": "egulias/email-validator",
"version": "4.0.2",
"source": {
......@@ -2328,6 +2376,144 @@
"time": "2024-09-23T13:32:56+00:00"
},
{
"name": "lcobucci/clock",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/lcobucci/clock.git",
"reference": "039ef98c6b57b101d10bd11d8fdfda12cbd996dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lcobucci/clock/zipball/039ef98c6b57b101d10bd11d8fdfda12cbd996dc",
"reference": "039ef98c6b57b101d10bd11d8fdfda12cbd996dc",
"shasum": ""
},
"require": {
"php": "~8.1.0 || ~8.2.0",
"psr/clock": "^1.0"
},
"provide": {
"psr/clock-implementation": "1.0"
},
"require-dev": {
"infection/infection": "^0.26",
"lcobucci/coding-standard": "^9.0",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9.4",
"phpstan/phpstan-deprecation-rules": "^1.1.1",
"phpstan/phpstan-phpunit": "^1.3.2",
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpunit/phpunit": "^9.5.27"
},
"type": "library",
"autoload": {
"psr-4": {
"Lcobucci\\Clock\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Luís Cobucci",
"email": "lcobucci@gmail.com"
}
],
"description": "Yet another clock abstraction",
"support": {
"issues": "https://github.com/lcobucci/clock/issues",
"source": "https://github.com/lcobucci/clock/tree/3.0.0"
},
"funding": [
{
"url": "https://github.com/lcobucci",
"type": "github"
},
{
"url": "https://www.patreon.com/lcobucci",
"type": "patreon"
}
],
"time": "2022-12-19T15:00:24+00:00"
},
{
"name": "lcobucci/jwt",
"version": "4.3.0",
"source": {
"type": "git",
"url": "https://github.com/lcobucci/jwt.git",
"reference": "4d7de2fe0d51a96418c0d04004986e410e87f6b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lcobucci/jwt/zipball/4d7de2fe0d51a96418c0d04004986e410e87f6b4",
"reference": "4d7de2fe0d51a96418c0d04004986e410e87f6b4",
"shasum": ""
},
"require": {
"ext-hash": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-sodium": "*",
"lcobucci/clock": "^2.0 || ^3.0",
"php": "^7.4 || ^8.0"
},
"require-dev": {
"infection/infection": "^0.21",
"lcobucci/coding-standard": "^6.0",
"mikey179/vfsstream": "^1.6.7",
"phpbench/phpbench": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/php-invoker": "^3.1",
"phpunit/phpunit": "^9.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Lcobucci\\JWT\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Luís Cobucci",
"email": "lcobucci@gmail.com",
"role": "Developer"
}
],
"description": "A simple library to work with JSON Web Token and JSON Web Signature",
"keywords": [
"JWS",
"jwt"
],
"support": {
"issues": "https://github.com/lcobucci/jwt/issues",
"source": "https://github.com/lcobucci/jwt/tree/4.3.0"
},
"funding": [
{
"url": "https://github.com/lcobucci",
"type": "github"
},
{
"url": "https://www.patreon.com/lcobucci",
"type": "patreon"
}
],
"time": "2023-01-02T13:28:00+00:00"
},
{
"name": "league/commonmark",
"version": "2.5.3",
"source": {
......@@ -3389,6 +3575,73 @@
"time": "2024-09-26T08:29:21+00:00"
},
{
"name": "overtrue/laravel-wechat",
"version": "6.2.0",
"source": {
"type": "git",
"url": "https://github.com/overtrue/laravel-wechat.git",
"reference": "a12e5dd4d1385330f1f6890a2446b1aad09ef0c9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/overtrue/laravel-wechat/zipball/a12e5dd4d1385330f1f6890a2446b1aad09ef0c9",
"reference": "a12e5dd4d1385330f1f6890a2446b1aad09ef0c9",
"shasum": ""
},
"require": {
"illuminate/container": "^5.1 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"w7corp/easywechat": "^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.1",
"laravel/framework": "^8.5"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Overtrue\\LaravelWeChat\\ServiceProvider"
],
"aliases": {
"EasyWeChat": "Overtrue\\LaravelWeChat\\Facade"
}
}
},
"autoload": {
"psr-4": {
"Overtrue\\LaravelWeChat\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "overtrue",
"email": "anzhengchao@gmail.com"
}
],
"description": "微信 SDK for Laravel",
"keywords": [
"laravel",
"sdk",
"wechat",
"weixin"
],
"support": {
"issues": "https://github.com/overtrue/laravel-wechat/issues",
"source": "https://github.com/overtrue/laravel-wechat/tree/6.2.0"
},
"funding": [
{
"url": "https://github.com/overtrue",
"type": "github"
}
],
"time": "2023-06-01T07:43:24+00:00"
},
{
"name": "overtrue/qcloud-cos-client",
"version": "2.1.6",
"source": {
......@@ -3462,6 +3715,77 @@
"time": "2024-09-04T13:58:12+00:00"
},
{
"name": "overtrue/socialite",
"version": "4.11.2",
"source": {
"type": "git",
"url": "https://github.com/overtrue/socialite.git",
"reference": "83dd537a88b30cd9204ee2c46a5b2e181bc1fa66"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/overtrue/socialite/zipball/83dd537a88b30cd9204ee2c46a5b2e181bc1fa66",
"reference": "83dd537a88b30cd9204ee2c46a5b2e181bc1fa66",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-openssl": "*",
"guzzlehttp/guzzle": "^7.0",
"php": ">=8.0.2"
},
"require-dev": {
"jetbrains/phpstorm-attributes": "^1.0",
"laravel/pint": "^1.2",
"mockery/mockery": "^1.3",
"phpstan/phpstan": "^1.7",
"phpunit/phpunit": "^11.3"
},
"type": "library",
"autoload": {
"files": [
"src/Contracts/FactoryInterface.php",
"src/Contracts/UserInterface.php",
"src/Contracts/ProviderInterface.php"
],
"psr-4": {
"Overtrue\\Socialite\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "overtrue",
"email": "anzhengchao@gmail.com"
}
],
"description": "A collection of OAuth 2 packages.",
"keywords": [
"Feishu",
"login",
"oauth",
"qcloud",
"qq",
"social",
"wechat",
"weibo"
],
"support": {
"issues": "https://github.com/overtrue/socialite/issues",
"source": "https://github.com/overtrue/socialite/tree/4.11.2"
},
"funding": [
{
"url": "https://github.com/overtrue",
"type": "github"
}
],
"time": "2024-10-08T16:23:14+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.9.3",
"source": {
......@@ -3537,6 +3861,59 @@
"time": "2024-07-20T21:41:07+00:00"
},
{
"name": "pimple/pimple",
"version": "v3.5.0",
"source": {
"type": "git",
"url": "https://github.com/silexphp/Pimple.git",
"reference": "a94b3a4db7fb774b3d78dad2315ddc07629e1bed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/silexphp/Pimple/zipball/a94b3a4db7fb774b3d78dad2315ddc07629e1bed",
"reference": "a94b3a4db7fb774b3d78dad2315ddc07629e1bed",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"psr/container": "^1.1 || ^2.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.4@dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4.x-dev"
}
},
"autoload": {
"psr-0": {
"Pimple": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "Pimple, a simple Dependency Injection Container",
"homepage": "https://pimple.symfony.com",
"keywords": [
"container",
"dependency injection"
],
"support": {
"source": "https://github.com/silexphp/Pimple/tree/v3.5.0"
},
"time": "2021-10-28T11:13:42+00:00"
},
{
"name": "predis/predis",
"version": "v2.2.2",
"source": {
......@@ -4551,8 +4928,180 @@
"time": "2024-08-27T18:56:10+00:00"
},
{
"name": "symfony/console",
"version": "v6.4.13",
"name": "symfony/cache",
"version": "v6.4.14",
"source": {
"type": "git",
"url": "https://github.com/symfony/cache.git",
"reference": "36fb8aa88833708e9f29014b6f15fac051a8b613"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/cache/zipball/36fb8aa88833708e9f29014b6f15fac051a8b613",
"reference": "36fb8aa88833708e9f29014b6f15fac051a8b613",
"shasum": ""
},
"require": {
"php": ">=8.1",
"psr/cache": "^2.0|^3.0",
"psr/log": "^1.1|^2|^3",
"symfony/cache-contracts": "^2.5|^3",
"symfony/service-contracts": "^2.5|^3",
"symfony/var-exporter": "^6.3.6|^7.0"
},
"conflict": {
"doctrine/dbal": "<2.13.1",
"symfony/dependency-injection": "<5.4",
"symfony/http-kernel": "<5.4",
"symfony/var-dumper": "<5.4"
},
"provide": {
"psr/cache-implementation": "2.0|3.0",
"psr/simple-cache-implementation": "1.0|2.0|3.0",
"symfony/cache-implementation": "1.1|2.0|3.0"
},
"require-dev": {
"cache/integration-tests": "dev-master",
"doctrine/dbal": "^2.13.1|^3|^4",
"predis/predis": "^1.1|^2.0",
"psr/simple-cache": "^1.0|^2.0|^3.0",
"symfony/config": "^5.4|^6.0|^7.0",
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
"symfony/filesystem": "^5.4|^6.0|^7.0",
"symfony/http-kernel": "^5.4|^6.0|^7.0",
"symfony/messenger": "^5.4|^6.0|^7.0",
"symfony/var-dumper": "^5.4|^6.0|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Cache\\": ""
},
"classmap": [
"Traits/ValueWrapper.php"
],
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides extended PSR-6, PSR-16 (and tags) implementations",
"homepage": "https://symfony.com",
"keywords": [
"caching",
"psr6"
],
"support": {
"source": "https://github.com/symfony/cache/tree/v6.4.14"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-11-05T15:34:40+00:00"
},
{
"name": "symfony/cache-contracts",
"version": "v3.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/cache-contracts.git",
"reference": "df6a1a44c890faded49a5fca33c2d5c5fd3c2197"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/cache-contracts/zipball/df6a1a44c890faded49a5fca33c2d5c5fd3c2197",
"reference": "df6a1a44c890faded49a5fca33c2d5c5fd3c2197",
"shasum": ""
},
"require": {
"php": ">=8.1",
"psr/cache": "^3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"psr-4": {
"Symfony\\Contracts\\Cache\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Generic abstractions related to caching",
"homepage": "https://symfony.com",
"keywords": [
"abstractions",
"contracts",
"decoupling",
"interfaces",
"interoperability",
"standards"
],
"support": {
"source": "https://github.com/symfony/cache-contracts/tree/v3.5.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-04-18T09:32:20+00:00"
},
{
"name": "symfony/console",
"version": "v6.4.13",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
......@@ -6709,6 +7258,83 @@
"time": "2024-09-25T14:18:03+00:00"
},
{
"name": "symfony/var-exporter",
"version": "v6.4.13",
"source": {
"type": "git",
"url": "https://github.com/symfony/var-exporter.git",
"reference": "0f605f72a363f8743001038a176eeb2a11223b51"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/var-exporter/zipball/0f605f72a363f8743001038a176eeb2a11223b51",
"reference": "0f605f72a363f8743001038a176eeb2a11223b51",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/deprecation-contracts": "^2.5|^3"
},
"require-dev": {
"symfony/property-access": "^6.4|^7.0",
"symfony/serializer": "^6.4|^7.0",
"symfony/var-dumper": "^5.4|^6.0|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\VarExporter\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Allows exporting any serializable PHP data structure to plain PHP code",
"homepage": "https://symfony.com",
"keywords": [
"clone",
"construct",
"export",
"hydrate",
"instantiate",
"lazy-loading",
"proxy",
"serialize"
],
"support": {
"source": "https://github.com/symfony/var-exporter/tree/v6.4.13"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-09-25T14:18:03+00:00"
},
{
"name": "thenorthmemory/xml",
"version": "1.1.1",
"source": {
......@@ -6813,6 +7439,90 @@
"time": "2023-12-08T13:03:43+00:00"
},
{
"name": "tymon/jwt-auth",
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/tymondesigns/jwt-auth.git",
"reference": "51620ebd5b68bb3ce9e66ba86bda303ae5f10f7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tymondesigns/jwt-auth/zipball/51620ebd5b68bb3ce9e66ba86bda303ae5f10f7f",
"reference": "51620ebd5b68bb3ce9e66ba86bda303ae5f10f7f",
"shasum": ""
},
"require": {
"illuminate/auth": "^9.0|^10.0|^11.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"illuminate/http": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"lcobucci/jwt": "^4.0",
"nesbot/carbon": "^2.0|^3.0",
"php": "^8.0"
},
"require-dev": {
"illuminate/console": "^9.0|^10.0|^11.0",
"illuminate/database": "^9.0|^10.0|^11.0",
"illuminate/routing": "^9.0|^10.0|^11.0",
"mockery/mockery": ">=0.9.9",
"phpunit/phpunit": "^9.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-develop": "1.0-dev",
"dev-2.x": "2.0-dev"
},
"laravel": {
"aliases": {
"JWTAuth": "Tymon\\JWTAuth\\Facades\\JWTAuth",
"JWTFactory": "Tymon\\JWTAuth\\Facades\\JWTFactory"
},
"providers": [
"Tymon\\JWTAuth\\Providers\\LaravelServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Tymon\\JWTAuth\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sean Tymon",
"email": "tymon148@gmail.com",
"homepage": "https://tymon.xyz",
"role": "Developer"
}
],
"description": "JSON Web Token Authentication for Laravel and Lumen",
"homepage": "https://github.com/tymondesigns/jwt-auth",
"keywords": [
"Authentication",
"JSON Web Token",
"auth",
"jwt",
"laravel"
],
"support": {
"issues": "https://github.com/tymondesigns/jwt-auth/issues",
"source": "https://github.com/tymondesigns/jwt-auth"
},
"funding": [
{
"url": "https://www.patreon.com/seantymon",
"type": "patreon"
}
],
"time": "2024-03-14T19:29:49+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.6.1",
"source": {
......@@ -6971,6 +7681,97 @@
"time": "2022-03-08T17:03:00+00:00"
},
{
"name": "w7corp/easywechat",
"version": "5.35.3",
"source": {
"type": "git",
"url": "https://github.com/w7corp/easywechat.git",
"reference": "4e6e5760d5c6827784d7b442fabede163af46d66"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/w7corp/easywechat/zipball/4e6e5760d5c6827784d7b442fabede163af46d66",
"reference": "4e6e5760d5c6827784d7b442fabede163af46d66",
"shasum": ""
},
"require": {
"easywechat-composer/easywechat-composer": "^1.1",
"ext-fileinfo": "*",
"ext-libxml": "*",
"ext-openssl": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^6.2 || ^7.0",
"monolog/monolog": "^1.22 || ^2.0 || ^3.0",
"overtrue/socialite": "^3.2 || ^4.0",
"php": ">=7.4",
"pimple/pimple": "^3.0",
"psr/simple-cache": "^1.0||^2.0||^3.0",
"symfony/cache": "^3.3 || ^4.3 || ^5.0 || ^6.0",
"symfony/event-dispatcher": "^4.3 || ^5.0 || ^6.0",
"symfony/http-foundation": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.7",
"dms/phpunit-arraysubset-asserts": "^0.2.0",
"friendsofphp/php-cs-fixer": "^3.5.0",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.2.3",
"phpstan/phpstan": "^0.12.0",
"phpunit/phpunit": "^9.3"
},
"type": "library",
"extra": {
"hooks": {
"pre-commit": [
"composer test",
"composer fix-style"
],
"pre-push": [
"composer test",
"composer fix-style"
]
}
},
"autoload": {
"files": [
"src/Kernel/Support/Helpers.php",
"src/Kernel/Helpers.php"
],
"psr-4": {
"EasyWeChat\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "overtrue",
"email": "anzhengchao@gmail.com"
}
],
"description": "微信SDK",
"keywords": [
"easywechat",
"sdk",
"wechat",
"weixin",
"weixin-sdk"
],
"support": {
"issues": "https://github.com/w7corp/easywechat/issues",
"source": "https://github.com/w7corp/easywechat/tree/5.35.3"
},
"funding": [
{
"url": "https://github.com/overtrue",
"type": "github"
}
],
"time": "2024-08-29T11:19:11+00:00"
},
{
"name": "webmozart/assert",
"version": "1.11.0",
"source": {
......
......@@ -40,6 +40,11 @@
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'jwt',
'provider' => 'users',
'hash' => false,
],
],
/*
......
<?php
/*
* This file is part of jwt-auth.
*
* (c) Sean Tymon <tymon148@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
/*
|--------------------------------------------------------------------------
| JWT Authentication Secret
|--------------------------------------------------------------------------
|
| Don't forget to set this in your .env file, as it will be used to sign
| your tokens. A helper command is provided for this:
| `php artisan jwt:secret`
|
| Note: This will be used for Symmetric algorithms only (HMAC),
| since RSA and ECDSA use a private/public key combo (See below).
|
*/
'secret' => env('JWT_SECRET'),
/*
|--------------------------------------------------------------------------
| JWT Authentication Keys
|--------------------------------------------------------------------------
|
| The algorithm you are using, will determine whether your tokens are
| signed with a random string (defined in `JWT_SECRET`) or using the
| following public & private keys.
|
| Symmetric Algorithms:
| HS256, HS384 & HS512 will use `JWT_SECRET`.
|
| Asymmetric Algorithms:
| RS256, RS384 & RS512 / ES256, ES384 & ES512 will use the keys below.
|
*/
'keys' => [
/*
|--------------------------------------------------------------------------
| Public Key
|--------------------------------------------------------------------------
|
| A path or resource to your public key.
|
| E.g. 'file://path/to/public/key'
|
*/
'public' => env('JWT_PUBLIC_KEY'),
/*
|--------------------------------------------------------------------------
| Private Key
|--------------------------------------------------------------------------
|
| A path or resource to your private key.
|
| E.g. 'file://path/to/private/key'
|
*/
'private' => env('JWT_PRIVATE_KEY'),
/*
|--------------------------------------------------------------------------
| Passphrase
|--------------------------------------------------------------------------
|
| The passphrase for your private key. Can be null if none set.
|
*/
'passphrase' => env('JWT_PASSPHRASE'),
],
/*
|--------------------------------------------------------------------------
| JWT time to live
|--------------------------------------------------------------------------
|
| Specify the length of time (in minutes) that the token will be valid for.
| Defaults to 1 hour.
|
| You can also set this to null, to yield a never expiring token.
| Some people may want this behaviour for e.g. a mobile app.
| This is not particularly recommended, so make sure you have appropriate
| systems in place to revoke the token if necessary.
| Notice: If you set this to null you should remove 'exp' element from 'required_claims' list.
|
*/
'ttl' => env('JWT_TTL', 60),
/*
|--------------------------------------------------------------------------
| Refresh time to live
|--------------------------------------------------------------------------
|
| Specify the length of time (in minutes) that the token can be refreshed
| within. I.E. The user can refresh their token within a 2 week window of
| the original token being created until they must re-authenticate.
| Defaults to 2 weeks.
|
| You can also set this to null, to yield an infinite refresh time.
| Some may want this instead of never expiring tokens for e.g. a mobile app.
| This is not particularly recommended, so make sure you have appropriate
| systems in place to revoke the token if necessary.
|
*/
'refresh_ttl' => env('JWT_REFRESH_TTL', 20160),
/*
|--------------------------------------------------------------------------
| JWT hashing algorithm
|--------------------------------------------------------------------------
|
| Specify the hashing algorithm that will be used to sign the token.
|
*/
'algo' => env('JWT_ALGO', Tymon\JWTAuth\Providers\JWT\Provider::ALGO_HS256),
/*
|--------------------------------------------------------------------------
| Required Claims
|--------------------------------------------------------------------------
|
| Specify the required claims that must exist in any token.
| A TokenInvalidException will be thrown if any of these claims are not
| present in the payload.
|
*/
'required_claims' => [
'iss',
'iat',
'exp',
'nbf',
'sub',
'jti',
],
/*
|--------------------------------------------------------------------------
| Persistent Claims
|--------------------------------------------------------------------------
|
| Specify the claim keys to be persisted when refreshing a token.
| `sub` and `iat` will automatically be persisted, in
| addition to the these claims.
|
| Note: If a claim does not exist then it will be ignored.
|
*/
'persistent_claims' => [
// 'foo',
// 'bar',
],
/*
|--------------------------------------------------------------------------
| Lock Subject
|--------------------------------------------------------------------------
|
| This will determine whether a `prv` claim is automatically added to
| the token. The purpose of this is to ensure that if you have multiple
| authentication models e.g. `App\User` & `App\OtherPerson`, then we
| should prevent one authentication request from impersonating another,
| if 2 tokens happen to have the same id across the 2 different models.
|
| Under specific circumstances, you may want to disable this behaviour
| e.g. if you only have one authentication model, then you would save
| a little on token size.
|
*/
'lock_subject' => true,
/*
|--------------------------------------------------------------------------
| Leeway
|--------------------------------------------------------------------------
|
| This property gives the jwt timestamp claims some "leeway".
| Meaning that if you have any unavoidable slight clock skew on
| any of your servers then this will afford you some level of cushioning.
|
| This applies to the claims `iat`, `nbf` and `exp`.
|
| Specify in seconds - only if you know you need it.
|
*/
'leeway' => env('JWT_LEEWAY', 0),
/*
|--------------------------------------------------------------------------
| Blacklist Enabled
|--------------------------------------------------------------------------
|
| In order to invalidate tokens, you must have the blacklist enabled.
| If you do not want or need this functionality, then set this to false.
|
*/
'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true),
/*
| -------------------------------------------------------------------------
| Blacklist Grace Period
| -------------------------------------------------------------------------
|
| When multiple concurrent requests are made with the same JWT,
| it is possible that some of them fail, due to token regeneration
| on every request.
|
| Set grace period in seconds to prevent parallel request failure.
|
*/
'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0),
/*
|--------------------------------------------------------------------------
| Cookies encryption
|--------------------------------------------------------------------------
|
| By default Laravel encrypt cookies for security reason.
| If you decide to not decrypt cookies, you will have to configure Laravel
| to not encrypt your cookie token by adding its name into the $except
| array available in the middleware "EncryptCookies" provided by Laravel.
| see https://laravel.com/docs/master/responses#cookies-and-encryption
| for details.
|
| Set it to true if you want to decrypt cookies.
|
*/
'decrypt_cookies' => false,
/*
|--------------------------------------------------------------------------
| Providers
|--------------------------------------------------------------------------
|
| Specify the various providers used throughout the package.
|
*/
'providers' => [
/*
|--------------------------------------------------------------------------
| JWT Provider
|--------------------------------------------------------------------------
|
| Specify the provider that is used to create and decode the tokens.
|
*/
'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class,
/*
|--------------------------------------------------------------------------
| Authentication Provider
|--------------------------------------------------------------------------
|
| Specify the provider that is used to authenticate users.
|
*/
'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class,
/*
|--------------------------------------------------------------------------
| Storage Provider
|--------------------------------------------------------------------------
|
| Specify the provider that is used to store tokens in the blacklist.
|
*/
'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class,
],
];
<?php
/*
* This file is part of the overtrue/laravel-wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
return [
/*
* 默认配置,将会合并到各模块中
*/
'defaults' => [
/*
* 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
*/
'response_type' => 'array',
/*
* 使用 Laravel 的缓存系统
*/
'use_laravel_cache' => true,
/**
* 日志配置
*
* level: 日志级别, 可选为:
* debug/info/notice/warning/error/critical/alert/emergency
* path:日志文件位置(绝对路径!!!),要求可写权限
*/
'log' => [
'default' => env('APP_DEBUG', false) ? 'dev' : 'prod', // 默认使用的 channel,生产环境可以改为下面的 prod
'channels' => [
// 测试环境
'dev' => [
'driver' => 'single',
'path' => storage_path('logs/wechat.log'),
'level' => 'debug',
],
// 生产环境
'prod' => [
'driver' => 'daily',
'path' => storage_path('logs/wechat.log'),
'level' => 'debug',
],
],
],
],
/*
* 路由配置
*/
'route' => [
/*
* 开放平台第三方平台路由配置
*/
// 'open_platform' => [
// 'uri' => 'serve',
// 'action' => Overtrue\LaravelWeChat\Controllers\OpenPlatformController::class,
// 'attributes' => [
// 'prefix' => 'open-platform',
// 'middleware' => null,
// ],
// ],
],
/*
* 公众号
*/
'official_account' => [
'default' => [
'app_id' => env('WECHAT_OFFICIAL_ACCOUNT_APPID', 'your-app-id'), // AppID
'secret' => env('WECHAT_OFFICIAL_ACCOUNT_SECRET', 'your-app-secret'), // AppSecret
'token' => env('WECHAT_OFFICIAL_ACCOUNT_TOKEN', 'your-token'), // Token
'aes_key' => env('WECHAT_OFFICIAL_ACCOUNT_AES_KEY', ''), // EncodingAESKey
/*
* OAuth 配置
*
* scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
* callback:OAuth授权完成后的回调页地址(如果使用中间件,则随便填写。。。)
* enforce_https:是否强制使用 HTTPS 跳转
*/
// 'oauth' => [
// 'scopes' => array_map('trim', explode(',', env('WECHAT_OFFICIAL_ACCOUNT_OAUTH_SCOPES', 'snsapi_userinfo'))),
// 'callback' => env('WECHAT_OFFICIAL_ACCOUNT_OAUTH_CALLBACK', '/examples/oauth_callback.php'),
// 'enforce_https' => true,
// ],
],
],
/*
* 开放平台第三方平台
*/
// 'open_platform' => [
// 'default' => [
// 'app_id' => env('WECHAT_OPEN_PLATFORM_APPID', ''),
// 'secret' => env('WECHAT_OPEN_PLATFORM_SECRET', ''),
// 'token' => env('WECHAT_OPEN_PLATFORM_TOKEN', ''),
// 'aes_key' => env('WECHAT_OPEN_PLATFORM_AES_KEY', ''),
// ],
// ],
/*
* 小程序
*/
'mini_program' => [
'default' => [
'app_id' => env('WECHAT_MINI_PROGRAM_APPID', ''),
'secret' => env('WECHAT_MINI_PROGRAM_SECRET', ''),
'token' => env('WECHAT_MINI_PROGRAM_TOKEN', ''),
'aes_key' => env('WECHAT_MINI_PROGRAM_AES_KEY', ''),
],
],
/*
* 微信支付
*/
// 'payment' => [
// 'default' => [
// 'sandbox' => env('WECHAT_PAYMENT_SANDBOX', false),
// 'app_id' => env('WECHAT_PAYMENT_APPID', ''),
// 'mch_id' => env('WECHAT_PAYMENT_MCH_ID', 'your-mch-id'),
// 'key' => env('WECHAT_PAYMENT_KEY', 'key-for-signature'),
// 'cert_path' => env('WECHAT_PAYMENT_CERT_PATH', 'path/to/cert/apiclient_cert.pem'), // XXX: 绝对路径!!!!
// 'key_path' => env('WECHAT_PAYMENT_KEY_PATH', 'path/to/cert/apiclient_key.pem'), // XXX: 绝对路径!!!!
// 'notify_url' => 'http://example.com/payments/wechat-notify', // 默认支付结果通知地址
// ],
// // ...
// ],
/*
* 企业微信
*/
// 'work' => [
// 'default' => [
// 'corp_id' => 'xxxxxxxxxxxxxxxxx',
// 'agent_id' => 100020,
// 'secret' => env('WECHAT_WORK_AGENT_CONTACTS_SECRET', ''),
// //...
// ],
// ],
];
......@@ -14,6 +14,16 @@
|
*/
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
// return $request->user();
// });
// 不需要登录的组
// 小程序静默登录
Route::post('login', 'App\Api\Controllers\UserController@login');
// 需要验证是否登录的路由组
Route::middleware(['jwt.auth'])->group(function () {
// 获取用户信息
Route::get('/users', 'App\Api\Controllers\UserController@userInfo');
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment