zhengzhibin 2 лет назад
Родитель
Сommit
e4770f6d02
3 измененных файлов с 9 добавлено и 6 удалено
  1. 5 4
      app/api/controller/Common.php
  2. 1 1
      app/api/controller/接口文档.md
  3. 3 1
      app/helper_str.php

+ 5 - 4
app/api/controller/Common.php

@@ -41,8 +41,8 @@ class Common extends Base
         $validate = new \think\Validate([
             ['openid', 'max:50'],
             ['unionid', 'max:50'],
-            ['nickname|昵称', 'max:50'],
-            ['head_pic|头像', 'max:255'],
+//            ['nickname|昵称', 'max:50'],
+//            ['headimgurl|头像', 'max:255'],
 //            ['sex|性别', 'in:0,1,2'],
 //            ['country|国家', 'max:50'],
 //            ['province|省份', 'max:50'],
@@ -73,10 +73,10 @@ class Common extends Base
                 'openid' => $post['openid']??'',
                 'unionid' => $post['unionid']??'',
                 'passport' => $passport,
-                'nickname' => $post['nickname']??'',
+                'nickname' => limitStrLen('nickname', $post['nickname']??'', 50),
                 'user_type' => User::TYPE_WECHAT,
                 'user_cate' => User::CATE_USER,
-                'head_pic' => $post['head_pic']??'',
+                'head_pic' => limitStrLen('headimgurl', $post['headimgurl']??'', 255),
                 'status' => User::STATUS_PASS,
                 'ip' => $this->request->ip(),
                 'sex' => $post['sex']??0,
@@ -94,6 +94,7 @@ class Common extends Base
                 "login_time" => time(),
                 'openid' => $post['openid']??'',
                 'unionid' => $post['unionid']??'',
+                'head_pic' => limitStrLen('headimgurl', $post['headimgurl']??'', 255),
             ];
             $user->allowField(true)->save($data);
         }

+ 1 - 1
app/api/controller/接口文档.md

@@ -50,7 +50,7 @@
     "time": "1682778816",
     "data": {
         "nickname": "111", //昵称
-        "head_pic": "",  //头像,目前微信不返回头像
+        "head_pic": "",  //头像
         "sex": 0,   //性别:0未知,1男,2女
         "country": "", //国家
         "province": "", //省份

+ 3 - 1
app/helper_str.php

@@ -54,6 +54,7 @@ function isUrl($str)
         return false;
     }
 }
+
 // +----------------------------------------------------------------------
 // 字符串截取
 // +----------------------------------------------------------------------
@@ -123,8 +124,9 @@ function limitStrLen($name, $value, $len = 10)
     }
     if (is_string($value) && mb_strlen($value, "utf-8") > $len) {
         \think\Log::notice("limitLen error:$name = $value");
+        return subStrCN($value, $len);
     }
-    return subStrCN($value, $len);
+    return $value;
 }