bastphp / sign
2.2.0
2020-10-26 03:28 UTC
Requires
- ext-json: ^1.6
- illuminate/support: >=5.0
This package is auto-updated.
Last update: 2024-09-26 13:00:08 UTC
README
###需求
illuminate/support >= 5.0
###使用方法
目前仅支持MD5加密和验证
####安装方法
composer require bastphp/sign LARAVEL框架 php artisan vendor:publish --provider=Bastphp\Sign\SignProvider LUMEN框架需要先安装vendor:publish扩展,然后在bootstrap.php文件内添加以下两行代码 $app->register(Bastphp\Sign\SignProvider::class); $app->configure('signer'); 然后运行php artisan vendor:publish --provider=Bastphp\Sign\SignProvider
<?php
namespace App\Http\Controllers;
use Bastphp\Sign\SignClient;
class TestController extends Controller
{
public function test()
{
$signObj = SignClient::client();//默认MD5做驱动
$signObj->setAppId('123456');//设置加密的APPid
$signObj->setKey('123123123');//设置加密的key
$signObj->encode(['a'=>1,'b'=>2]);//生成签名
//$sign = SignClient::client()->encode(['a'=>1,'b'=>2]);
$sign = 'fb017403af19713cd9f94c21f2691803';
$res = $signObj->verify(['a'=>1,'b'=>2],$sign);//验证签名
var_dump($res);
}
}
###警告
在请求时必须将app_id添加到请求体中。
如果没有指定APPID和key,将使用默认配置。