配置 信息
// +----------------------------------------------------------------------
// | Token設置
// +----------------------------------------------------------------------
'token' => [
// 驅動方式
'type' => 'Mysql',
// 緩存前綴
'key' => 'i3d6o32wo8fvs1fvdpwens',
// 加密方式
'hashalgo' => 'ripemd160',
// 緩存有效期 0表示永久緩存
'expire' => 0,
],
//生成返回的tooken
/**
* 獲取全球唯一標識
* @return string
*/
public static function uuid()
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
通過hash_hmac函數和配置方法生成token存入數據庫
```
$config = \think\Config::get('token');
return hash_hmac($config['hashalgo'], $token, $config['key']);
```