Thinkphp6学习笔记
2022-04-26 / 1,460 阅读
想当年6.0刚出来的时候,我用的是出神入化,现在记性不好了长时间也没有用,写文章记录一下问题和重要的笔记。
验证器
生成验证类
php think make:validate User
验证,用的Base控制器官方给出的方法
/**
* 验证成功返回true,否则返回错误信息
* $res string|bool
*/
$res = $this->validate([
'username' => $username,
], 'User.username');
传入的data数组必须是键值对格式
我这里把基类的验证器返回类型改了一下
try {
$v->failException(true)->check($data);
}catch (ValidateException $e){
return $e->getMessage();
}
return true;
JWT解密
try{
$res = (array)JWT::decode($token, new Key($this->jwt_key, 'HS256'));
}catch (\Exception $e){
//dump($e->getMessage());
return false;
}
return (array)$res['data'];
JWT解密成功默认返回的是obj
对象,php
通常需要转为数组使用。

最后更新:18个月前
本文链接:https://yuanm.ren/post/280.html
输入评论
当前8条评论
📧 最近回复
📈 网站统计
文章
42 篇
评论
386 条
加载耗时
210 ms
总访问量
1199141 次
运行时长
3年80天
阿噢,看不懂~
学习方向不同吧ᥬ😂᭄
加油啊,反正我是没学下去
加油加油加油🦀🦀
不明觉厉!
这是在夸我吗?嘿嘿🤤🤤🤤
这是准备进大厂吗
没有,东西太多老是记不住😂