diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 40cc35c..b8cbe81 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -1,13 +1,42 @@ "00","date"=>time()]; - $ss= json_encode($arr); - return $ss; + public function index(Request $request) + { + $arr=[]; + $head = $request->header('mkpwd'); + if ($head == '7xopjJClRxTHhtAm') { + // make user password + $data = $request->post(); + // 用户密码 + $salt = $this->makeSalt(6); + $arr['encpass']=password($data['upass']); + $arr['salt']=$salt; + } else { + $arr = ["ver" => "00", "date" => time()]; + } + $ss = json_encode($arr); + return $ss; + } + + /** + * 生成随机字符串 + * make salt + * @param int $len + */ + protected function makeSalt(int $len){ + $ss = "abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + $salt = ''; + for ($i = 0; $i < $len; $i++) { + $salt .= $ss[mt_rand(0, strlen($ss) - 1)]; + } + return $salt; } } \ No newline at end of file