\app\middleware\apiCheckSign

签名验证中间件 签名生成方式:strtoupper(md5(md5($hearder['request-time']).md5(Config::get('laytp.api.signKey')))) 签名验证方式: 请求的header头中需要有两个参数: - request-time = 当前请求的时间,这个单位并不要求固定,甚至传的都可以不是当前请求的时间,只要sign的值是使用这个参数的值按照规定的算法生成即可 - sign = md5(md5($hearder['request-time']).md5(Config::get('laytp.api.signKey'))) 此中间件,使用header头中request-time按照签名算法生成签名,然后与header中传递的sign参数比对,看是否一致,如果一致就通过验证,如果不一致就验证失败 需要设计,有些方法无需验签。比如获取配置的接口,需要得到后台配置的Config::get('laytp.api.signKey') Class CheckSign

Summary

Methods
Properties
Constants
success()
error()
exceptionError()
handle()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

success()

success(string  $msg = '', null  $data = null) : false|string|\think\response\Json

操作成功返回数据

Parameters

string $msg
null $data

Returns

false|string|\think\response\Json

error()

error(string  $msg = '', integer  $code = 1, array  $data = null) : \think\response\Json

操作失败返回数据

Parameters

string $msg
integer $code

错误码,为0表示没有错误,为1表示常规错误,前端仅需提示msg,其他值有具体含义,比如10401为未登录,前端需要跳转至登录界面

array $data

Returns

\think\response\Json

exceptionError()

exceptionError(  $e) : \think\response\Json

捕获异常后返回数据

Parameters

$e

Returns

\think\response\Json

handle()

handle(\think\Request  $request, \Closure  $next) : mixed

执行中间件

Parameters

\think\Request $request
\Closure $next

Returns

mixed