Example #1
0
 public static function mobile_getUser(\ApiParam $params)
 {
     if (!$params->mobile) {
         throw new \Exception('无效的手机号', 503);
     }
     $user = \User::loadByMobile($params->mobile);
     if (!$user) {
         return self::composeResponse(1, "user not registered");
     }
     $encrypted = self::encrypt($user->password, $params->api_key);
     return self::composeResponse(0, "获取信息成功", array('id' => $user->id, 'mobile' => $user->mobile, 'nickname' => $user->nickname, 'createdTime' => $user->createdTime, 'password' => $encrypted));
 }
Example #2
0
 private static function autoRegUser($mobile, $password)
 {
     if (!\Validate::isMobile($mobile)) {
         throw new \Exception('手机号码不对', 505);
     }
     if (strlen($password) == 0) {
         throw new \Exception('密码错误', 505);
     }
     $user = \User::loadByMobile($mobile);
     if ($user) {
         if (!$user->isMatchedPassword($password)) {
             throw new \Exception('密码错误', 505);
         }
     } else {
         try {
             $user = \Authorization::registerAutoUserNick($password, 'API_' . substr(time(), -6) . rand(1000, 9999), $mobile);
         } catch (Exception $e) {
             throw new \Exception('新建用户失败', 505);
         }
     }
     return $user;
 }