>  기사  >  php教程  >  前一任的神级代码,速来膜拜

前一任的神级代码,速来膜拜

PHP中文网
PHP中文网원래의
2016-05-25 16:58:321242검색

[PHP]代码 

<?php
/**
 * App用户注册接口
 * return: json
 */
public function signup_old(){
	$yyUser = M(&#39;table.user&#39;,&#39;youyax_&#39;);
	$data[&#39;user&#39;] = $_POST[&#39;userName&#39;];
	$data[&#39;telephone&#39;] = $_POST[&#39;telephone&#39;];
	$password = $_POST[&#39;password&#39;];
	$repassword = $_POST[&#39;repassword&#39;];
	$data[&#39;beAgent&#39;] = $_POST[&#39;beAgent&#39;];
	$data[&#39;realName&#39;] = $_POST[&#39;realName&#39;];
	$data[&#39;email&#39;] = $_POST[&#39;email&#39;];
	$data[&#39;credit&#39;] = I(&#39;identityCard&#39;);
	if(empty($data[&#39;user&#39;]) || empty($password) || empty($repassword) || empty($data[&#39;email&#39;]) ){
		$arr[&#39;code&#39;] = 0;
		$arr[&#39;message&#39;] = &#39;必填项不能为空!&#39;;
		echo json_encode($arr);
		return false;
	}
	$lenP = strlen($password);
	if($lenP < 6 || $lenP >20){
		$arr[&#39;code&#39;] = 0;
		$arr[&#39;message&#39;] = &#39;密码必须为6-20位!&#39;;
		echo json_encode($arr);
		return false;
	}
	if( empty($data[&#39;beAgent&#39;]) ){
		$data[&#39;beAgent&#39;] = 0;
	}
	if($data[&#39;beAgent&#39;] == 1){
		if(empty($data[&#39;realName&#39;]) || empty($data[&#39;telephone&#39;]) || empty($data[&#39;credit&#39;])){
			$arr[&#39;code&#39;] = 0;
			$arr[&#39;message&#39;] = &#39;经纪人必须填写手机号、真实姓名、身份证号!&#39;;
			echo json_encode($arr);
			return false;
		}
		$creditLength = strlen($data[&#39;credit&#39;]);
		if (!in_array($creditLength, array(15, 18)))
			$this->response(0, &#39;身份证号码不合法&#39;);
	}
	$verifyE = $this->checkEmail($data[&#39;email&#39;]);
	if($verifyE){
		$email = $data[&#39;email&#39;];
		$mapE[&#39;email&#39;] = array(&#39;in&#39;,$email);
		$count = $yyUser->where($mapE)->count();
		if($count==0){
			if($repassword == $password){
				$data[&#39;pass&#39;] = md5($password);
				$userName = $data[&#39;user&#39;];
				$mapU[&#39;user&#39;] = array(&#39;in&#39;,$userName);
				$count = $yyUser->where($mapU)->count();
				if($count==0){
					$tel = $data[&#39;telephone&#39;];
					$verifyT = $this->checkTel($tel);
					if( !empty($data[&#39;telephone&#39;])){
						if(!$verifyT){
							$arr[&#39;code&#39;] = 0;
							$arr[&#39;message&#39;] = &#39;不是正确的手机号码!&#39;;
							echo json_encode($arr);
							return false;
						}
						$mapT[&#39;telephone&#39;] = array(&#39;in&#39;,$tel);
						$count = $yyUser->where($mapT)->count();
						if($count!=0){
							$arr[&#39;code&#39;] = 0;
							$arr[&#39;message&#39;] = &#39;手机号码已被使用!&#39;;
							echo json_encode($arr);
							return false;
						}
					}
					$data[&#39;status&#39;] = 1;
					$bools = $yyUser->add($data);
					if($bools){
						$id = $yyUser->field(&#39;id&#39;)->where(&#39;user = &#39;.&#39;"&#39;.$data[&#39;user&#39;].&#39;"&#39;)->select();
						$userId = $id[0][&#39;id&#39;];
						$arr[&#39;code&#39;] = 1;
						$arr[&#39;message&#39;] = &#39;注册成功!&#39;;
						$arrData[&#39;userId&#39;] = $userId;
						$arrData[&#39;userName&#39;] = $data[&#39;user&#39;];
						$arrData[&#39;beAgent&#39;] = $data[&#39;beAgent&#39;];
						$arrData[&#39;realName&#39;] = $data[&#39;realName&#39;];
						$arrData[&#39;password&#39;] = $data[&#39;pass&#39;];
						$arrData[&#39;email&#39;] = $data[&#39;email&#39;];
						$arr[&#39;data&#39;] = $arrData;
						echo json_encode($arr);
					}else {
						$arr[&#39;code&#39;] = 0;
						$arr[&#39;message&#39;] = &#39;注册失败,系统异常,请重新注册!&#39;;
						echo json_encode($arr);
					}
				}else {
					$arr[&#39;code&#39;] = 0;
					$arr[&#39;message&#39;] = &#39;用户名已被使用!&#39;;
					echo json_encode($arr);
				}
			}else {
				$arr[&#39;code&#39;] = 0;
				$arr[&#39;message&#39;] = &#39;密码不一致!&#39;;
				echo json_encode($arr);
			}
		}else {
			$arr[&#39;code&#39;] = 0;
			$arr[&#39;message&#39;] = &#39;手机号码已被使用!&#39;;
			echo json_encode($arr);
		}
	}else {
		$arr[&#39;code&#39;] = 0;
		$arr[&#39;message&#39;] = &#39;手机号码不合法&#39;;
		echo json_encode($arr);
	}
}

                   

                   

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:微信首页responseMsg()다음 기사:PHPWORD