/**
 * 检查手机号
 * 
 * @param string $phone 手机号
 * @return array | true
 */
function checkPhone($phone = '')
{
    $patternMobile = Sp_Dictionary::getOtherOption('patternMobile');
    if (empty($phone)) {
        return array('code' => '400', 'msg' => '手机号不能为空');
    } else {
        if (false == preg_match($patternMobile, $phone)) {
            return array('code' => '400', 'msg' => '手机格式不正确');
        } else {
            if (Sp_Account_Regist::isAvailableMobile($phone)) {
                return array('code' => '400', 'msg' => '手机号不存在');
            }
        }
    }
    return true;
}
 public function check($email = '', $mobile = '', $passwd = '', $confirm_passwd = '', $code = '')
 {
     $email = trim($email);
     $mobile = trim($mobile);
     $passwd = trim($passwd);
     $confirm_passwd = trim($confirm_passwd);
     $code = trim($code);
     $patternEmail = Sp_Dictionary::getOtherOption('patternEmail');
     $patternMobile = Sp_Dictionary::getOtherOption('patternMobile');
     $patternPasswd = Sp_Dictionary::getOtherOption('patternPasswd');
     if (false == preg_match($patternEmail, $email)) {
         return array('status' => '-120', 'msg' => '邮件格式不正确');
     } else {
         if (false == preg_match($patternMobile, $mobile)) {
             return array('status' => '-121', 'msg' => '电话格式不正确');
         } else {
             if (false == preg_match($patternPasswd, $passwd)) {
                 return array('status' => '-122', 'msg' => '密码格式不正确');
             } else {
                 if ($passwd !== $confirm_passwd) {
                     return array('status' => '-123', 'msg' => '密码和确认密码不一致');
                 } else {
                     if (false == Util_Captcha::verify_captcha($code)) {
                         return array('status' => '-124', 'msg' => '验证码错误');
                     } else {
                         if (false == Sp_Account_Regist::isAvailableEmail($email)) {
                             return array('status' => '-125', 'msg' => '该邮件已经注册');
                         } else {
                             if (false == Sp_Account_Regist::isAvailableMobile($mobile)) {
                                 return array('status' => '-126', 'msg' => '该手机号已经注册');
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
 public function checkCodeAndUser($username = '', $code = '', $type = '')
 {
     $username = trim($username);
     $code = trim($code);
     $patternMobile = Sp_Dictionary::getOtherOption('patternMobile');
     $patternEmail = Sp_Dictionary::getOtherOption('patternEmail');
     if (strlen($code) != 6) {
         return array('status' => '-126', 'msg' => '验证码长度有误');
     }
     if (preg_match($patternEmail, $username) || preg_match($patternMobile, $username)) {
         if (preg_match($patternMobile, $username)) {
             if (TRUE == Sp_Account_Regist::isAvailableMobile($username)) {
                 return array('status' => '-125', 'msg' => '该手机号不存在');
             }
             $row = Sp_Sendmsg::getSmsByPhone($username, $type);
             $nowTime = time() - $row['crttime'];
             if (!is_array($row) || $nowTime > 15 * 60 || $row['code'] != $code) {
                 return array('status' => '-126', 'msg' => '验证码错误');
             }
         }
         if (preg_match($patternEmail, $username)) {
             if (TRUE == Sp_Account_Regist::isAvailableEmail($username)) {
                 return array('status' => '-126', 'msg' => '该邮箱不存在');
             }
             $row = Sp_Sendmsg::getSmsByEmail($username, $type);
             $nowTime = time() - $row['crttime'];
             if (!is_array($row) || $nowTime > 15 * 60 || $row['code'] != $code) {
                 return array('status' => '-126', 'msg' => '验证码错误');
             }
         }
         return TRUE;
     } else {
         return array('status' => '-121', 'msg' => '格式不正确');
     }
 }