hogus/api-signature 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hogus/api-signature

最新稳定版本:1.0

Composer 安装命令:

composer require hogus/api-signature

包简介

laravel api signature

README 文档

README

Install

composer require hogus/api-signature

Publish Config

php artisan vendor:publish --provider=Hogus\\ApiSignature\\ApiSignatureServiceProvider

Env

#sign
API_SIGN_ENABLED=true
API_SIGN_SECRET=secret
#API_SIGN_KEY=sign
#API_SIGN_TIMESTAMP_KEY=timestamp
#API_SIGN_TIMEOUT=60

Http Middleware

Add the API signature middleware to the middleware aliases in your Kernel.php file:

protected $middlewareAliases = [
    //...,
    'sign' => \Hogus\ApiSignature\Middleware\ApiSignature::class,
]

Router

Apply the sign middleware to the desired routes or route groups:

Route::middleware('sign:api')->group(function () {
    // your routes
});

This ensures that the API signature will be verified for all requests to these routes.

Custom Exceptions (options)

If you want to handle API signature verification exceptions in a custom way, you can define a renderable closure in your app/Exceptions/Handler.php file. For example, to return a JSON response containing the error message:

use Hogus\ApiSignature\ApiSignatureException;
$this->renderable(function (ApiSignatureException $exception, $request) {
    return response()->json(['message' => $exception->getMessage()]);
});

Supports

  • MD5
  • Hash(sha256)

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-13