Pārlūkot izejas kodu

fix:代理商身份

super-yimizi 17 stundas atpakaļ
vecāks
revīzija
975b7d9cf5

+ 6 - 2
application/api/controller/Login.php

@@ -146,7 +146,9 @@ class Login extends Base
             //如果已经有账号则直接登录
             $ret = $this->auth->direct($user->id);
         } else {
-            $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
+            // 生成随机用户名,不再使用手机号作为用户名
+            $randomUsername = $this->auth->generateUniqueUsername('user');
+            $ret = $this->auth->register($randomUsername, Random::alnum(), '', $mobile, []);
         }
         if ($ret) {
             Sms::flush($mobile, 'mobilelogin');
@@ -289,7 +291,9 @@ class Login extends Base
                 //如果已经有账号则直接登录
                 $ret = $this->auth->direct($user->id);
             } else {
-                $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, ['nickname' => substr_replace($mobile, '****', 3, 4)]);
+                // 生成随机用户名,不再使用手机号作为用户名
+                $randomUsername = $this->auth->generateUniqueUsername('wx');
+                $ret = $this->auth->register($randomUsername, Random::alnum(), '', $mobile, ['nickname' => substr_replace($mobile, '****', 3, 4)]);
             }
 
             //判断是否绑定模式,openid是否有关联,没有关联的情况下手动进行关联

+ 28 - 0
application/common/library/Auth.php

@@ -123,6 +123,34 @@ class Auth
     }
 
     /**
+     * 生成随机字符串
+     * @param int $len 字符串长度
+     * @return string
+     */
+    public function GetRandStr($len) {
+        $chars = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a", "b", "c","d", "e", "f", "g", "h", "i", "j", "k","l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v","w", "x", "y", "z","0", "1", "2","3", "4", "5", "6", "7", "8", "9");
+        $charsLen = count($chars) - 1;
+        shuffle($chars);
+        $output = "";
+        for ($i=0; $i<$len; $i++){
+            $output .= $chars[mt_rand(0, $charsLen)];
+        }
+        return $output;
+    }
+
+    /**
+     * 生成随机用户名
+     * @param string $prefix 前缀
+     * @param int $length 随机部分长度
+     * @return string
+     */
+    public function generateUniqueUsername($prefix = 'user', $length = 8)
+    {
+        $randomPart = $this->GetRandStr($length);
+        return $prefix .'_' . $randomPart;
+    }
+
+    /**
      * 注册用户
      *
      * @param string $username 用户名