File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace app \api \validate ;
3+
4+ use app \api \controller \Send ;
5+
6+ /**
7+ * 公共验证码方法
8+ * Class Common
9+ * @package app\api\validate
10+ */
11+ class ValidataCommon
12+ {
13+ use Send;
14+ /**
15+ * 默认支持验证规则
16+ * 更多验证规则请使用原生验证器
17+ * @var array
18+ */
19+ public static $ dataRule = ['require ' ,'int ' ,'mobile ' ];
20+
21+ /**
22+ * 接口参数公共验证方法
23+ * @param array $rule
24+ * @param array $data
25+ */
26+ static function validateCheck ($ rule = [],$ data = []){
27+ if (is_array ($ rule ) && is_array ($ data )){
28+ foreach ($ rule as $ k => $ v ){
29+ if (!in_array ($ v ,self ::$ dataRule )){
30+ return self ::returnMsg (401 ,'fail ' ,'验证规则只支持require,int ' );
31+ }
32+ if (!isset ($ data [$ k ]) || empty ($ data [$ k ])){
33+ return self ::returnMsg (401 ,'fail ' ,$ k .'不能为空 ' );
34+ }else {
35+ if ($ v == 'int ' ){
36+ if (!is_numeric ($ data [$ k ])){
37+ return self ::returnMsg (401 ,'fail ' ,$ k .'类型必须为 ' .$ v );
38+ }
39+ }elseif ($ v == 'mobile ' ){
40+ if (!preg_match ('/^1[3-9][0-9]\d{8}$/ ' ,$ data [$ k ])){
41+ return self ::returnMsg (401 ,'fail ' ,$ k .'手机号格式错误 ' );
42+ }
43+ }
44+ }
45+ }
46+ }else {
47+ return self ::returnMsg (401 ,'fail ' ,'验证数据格式为数组 ' );
48+ }
49+
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments