find(); if (!$user){ json_result(400,"账号不存在"); } if (!password_verify($pwd,$user->pwd)){ json_result(400,"密码错误"); } json_result(200,"登录成功",$user); } // 获取验证码 public function code() { $phone=input("phone");if (!$phone)json_result(400,"请输入手机号或者邮箱"); $type=input("type")?:0; // 查询是否重复发送 $where["phone"]=$phone; $where["add_time"]=["<",time()-(1*60)]; $phone_code=PhoneCode::where($where)->find(); if ($phone_code){ json_result(400,"验证码已发送请稍后再发送"); } $res=Tripartite::send_code($phone,$type); json_result(200,"验证码发送成功",$res); } // 注册 public function register() { $phone=input("phone");if (!$phone)json_result(400,"请输入手机号或者邮箱"); $code=input("code");if (!$code)json_result(400,"请输入验证码"); $name=input("name");if (!$name)json_result(400,"请输入账户呢称"); $type=input("type")?:0; $pwd=input("pwd");if (!$pwd)json_result(400,"请输入密码"); $pid=input("pid"); // 查看账号是存在 $where["phone|mail"]=$phone; $user=User::where($where)->find(); if ($user){ json_result(400,"账号已注册,请前去登录"); } // 验证码 $phone_code=Tripartite::push_code($phone); if ($phone_code!=$code){ json_result(400,"验证码错误"); } if ($pid){ $where["code"]=$pid; $pid_user=User::where($where)->find(); if (!$pid_user){ json_result(400,"上级账号不存在"); } $add["pid"]=$pid_user->id; } $add["code"]=uniqid(); if ($type==0){ $add["phone"]=$phone; }else{ $add["mail"]=$phone; } $add["name"]=$name; $uuid=Uuid::uuid1(); $add["token"]=$uuid->getHex();; $add["add_time"]=time(); $add["pwd"]= password_hash($pwd, PASSWORD_DEFAULT);; User::create($add); json_result(200,"测试成功"); } // 忘记密码 第一部 public function forget_password() { $phone=input("phone");if(!$phone)json_result(400,"请输入手机号码或者邮箱"); $type=input("type")?:0; $code=input("code");if (!$code)json_result(400,"请输入验证码"); $name=input("name"); // 查看账号是存在 $where["phone|mail"]=$phone; $user=User::where($where)->find(); if (!$user){ json_result(400,"账号不存在"); } // 验证码 $phone_code=Tripartite::push_code($phone,$type); if ($phone_code!=$code){ json_result(400,"验证码错误"); } json_result(200,"验证码成功"); } // 修改密码--第二步 public function update_password() { $pwd=input("pwd");if (!$pwd)json_result(400,"请输入密码"); $phone=input("phone");if(!$phone)json_result(400,"请输入手机号码或者邮箱"); // 查看账号是存在 $where["phone|mail"]=$phone; $user=User::where($where)->find(); if (!$user){ json_result(400,"账号不存在"); } $add["pwd"]= password_hash($pwd, PASSWORD_DEFAULT);; User::where(["id"=>$user->id])->update($add); json_result(200,"设置密码成功"); } // 上传图片 public function up_image() { $img = request()->file('image'); if ($img){ $up['image']=Upfile::uploadone($img); json_result(1,"成功",$up['image']); }else{ json_result(2,"请上传图片"); } } }