#tradewind:add wechat auth
This commit is contained in:
parent
5f850e288d
commit
4366c4a2ef
26
app/Http/Controllers/Api/WechatAuthController.php
Normal file
26
app/Http/Controllers/Api/WechatAuthController.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class WechatAuthController extends Controller
|
||||||
|
{
|
||||||
|
//
|
||||||
|
public function checkSign(Request $request)
|
||||||
|
{
|
||||||
|
$signature = $request->signature;
|
||||||
|
$timestamp = $request->timestamp;
|
||||||
|
$nonce = $request->nonce;
|
||||||
|
|
||||||
|
$token = config('token.wechat_token');
|
||||||
|
|
||||||
|
$tmpArr = [$token, $timestamp, $nonce];
|
||||||
|
sort($tmpArr, SORT_STRING);
|
||||||
|
$tmpStr = implode($tmpArr);
|
||||||
|
$tmpStr = sha1($tmpStr);
|
||||||
|
|
||||||
|
return $tmpStr === $signature;
|
||||||
|
}
|
||||||
|
}
|
@ -38,14 +38,9 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
$this->configureRateLimiting();
|
$this->configureRateLimiting();
|
||||||
|
|
||||||
$this->routes(function () {
|
$this->routes(function () {
|
||||||
Route::prefix('api')
|
Route::middleware('api')
|
||||||
->middleware('api')
|
|
||||||
->namespace($this->namespace)
|
->namespace($this->namespace)
|
||||||
->group(base_path('routes/api.php'));
|
->group(base_path('routes/api.php'));
|
||||||
|
|
||||||
Route::middleware('web')
|
|
||||||
->namespace($this->namespace)
|
|
||||||
->group(base_path('routes/web.php'));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
config/token.php
Normal file
7
config/token.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
'wechat_token' => env('WECHAT_TOKEN'),
|
||||||
|
|
||||||
|
];
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\Api\TestController;
|
use App\Http\Controllers\Api\TestController;
|
||||||
|
use App\Http\Controllers\Api\WechatAuthController;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
@ -21,5 +22,9 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
|
|||||||
|
|
||||||
Route::namespace('Api')->prefix('v1')->group(function () {
|
Route::namespace('Api')->prefix('v1')->group(function () {
|
||||||
Route::any('/test', [TestController::class, 'index'])->name('test.index');
|
Route::any('/test', [TestController::class, 'index'])->name('test.index');
|
||||||
|
|
||||||
|
Route::prefix('wechat')->group(function () {
|
||||||
|
Route::get('/auth', [WechatAuthController::class, 'checkSign'])->name('wechat.auth.checkSign');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user