Esempio n. 1
0
 public static function sendCode(\ApiParam $params, $type = "resetPassword")
 {
     if (!\Validate::isMobile($params->mobile)) {
         throw new \Exception('手机号码不正确', 1001);
     }
     $user = \User::loadByMobile($params->mobile);
     if (!$user) {
         throw new \Exception('手机号码未注册,请先注册新用户', 1002);
     }
     if (\Cache::getCountNumber("SendCode_{$params->mobile}", 60) > 1) {
         \InstantCounter::count("SendCode_Retry");
         throw new \Exception('请您1分钟后再试.', 1003);
     }
     $code = \Authorization::mobilePassword($params->mobile);
     $content = "";
     if ($params->api_key == 'api_mobile_android') {
         $content = "您的手机验证码为{$code}。本条免费,有效期一天";
     } else {
         $content = "您的手机验证码为{$code},请在手机客户端上输入后继续下一步操作。本条免费,有效期一天";
     }
     \Sms::send($params->mobile, $content, '手机客户端_获取验证码-' . $type);
     return TRUE;
     //成功发送
 }
Esempio n. 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;
 }