if(!preg_match("/^[1][34578][0-9]{9}$/", $tel)){$result = array('code'=>1,'data'=>'请正确填写手机号码');}else{$teluser = "select * from ...";获取用户信息$teluser = $GLOBALS['db']->getRow($teluser);if(!$teluser){$result = array('code'=>1,'data'=>'该号码尚未注册');die(json_encode($result));}$salt = getSalt();//自定义验证码生成规则saveSalt($tel,$salt,$type);//存储用户验证码$content = $content = "您好,您的验证码为".$salt.",请妥善保管";$res = sendSMS($tel,$content);if($res==0){$result = array('code'=>0,'data'=>'发送成功');}else{$result = array('code'=>1,'data'=>'发送失败');}}die(json_encode($result));
function getSalt(){ $random = ''; for ($i = 0; $i < 4; $i++) { $random .= rand(0, 9); } return $random;}
function sendSMS( $mobile, $msg, $needstatus = 1) { $flag = 0; $params=''; $argv = array ( 'name' => "账号", 'pwd' => "密码", 'content' => $msg, 'mobile' => $mobile, 'sign'=>'自定义', 'type'=>'pt', ); foreach ($argv as $key=>$value) { if ($flag!=0) { $params .= "&"; $flag = 1; } $params.= $key."="; $params.= urlencode($value);// urlencode($value); $flag = 1; } $result = substr( file_get_contents($url), 0, 1 ); $url = "http://web.cr6868.com/asmx/smsservice.aspx?".$params; $con= substr( file_get_contents($url), 0, 1 ); return $con;}