配置 信息
// +----------------------------------------------------------------------
// | 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']);
```