|
|
@@ -3,8 +3,9 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
-use app\common\model\User;
|
|
|
+use app\common\model\Users;
|
|
|
use think\captcha\Captcha;
|
|
|
+use think\Request;
|
|
|
|
|
|
/**
|
|
|
* 验证接口
|
|
|
@@ -29,11 +30,59 @@ class Validate extends Api
|
|
|
*/
|
|
|
public function get_captcha()
|
|
|
{
|
|
|
- $captcha = new Captcha();
|
|
|
+
|
|
|
+ $captcha = new Captcha(['codeSet' => '0123456789', 'length' => 4]);
|
|
|
+ $id = uniqid();
|
|
|
return $captcha->entry();
|
|
|
|
|
|
- return captcha_src();
|
|
|
+// $id = uniqid();
|
|
|
+// $src = $_SERVER['REQUEST_SCHEME'].'://'.$this->request->host() . captcha_src($id);
|
|
|
+// ob_clean(); //清除缓冲区,防止出现“图像因其本身有错无法显示'的问题
|
|
|
+// $type = getimagesize($src)['mime']; //获取图片类型
|
|
|
+// header("Content-Type:{$type}");
|
|
|
+// $imgData = file_get_contents($src); //获取图片二进制流
|
|
|
+// $base64String = 'data:' . $type . ';base64,' . base64_encode($imgData);
|
|
|
+// $this->success('', ['id' => $id, 'img' => $base64String]);
|
|
|
+//
|
|
|
+// $this->success('请求成功',$base64String);
|
|
|
+//
|
|
|
+//
|
|
|
+// return Captcha_src(); // png图片
|
|
|
+
|
|
|
+ // 获取验证码的图片内容
|
|
|
+ $image = $captcha->entry();
|
|
|
+
|
|
|
+ // 转换为Base64
|
|
|
+ $base64Image = $this->imageToBase64($image);
|
|
|
+
|
|
|
+ dump($base64Image);
|
|
|
+ $this->success('', ['id' => $id, 'img' => $captcha->entry($id)]);
|
|
|
+ return $captcha->entry($id);
|
|
|
+ //return captcha_src();
|
|
|
}
|
|
|
+
|
|
|
+ protected function imageToBase64($image)
|
|
|
+ {
|
|
|
+ // 确保已经安装GD库或者Imagick扩展
|
|
|
+ if (!function_exists('imagepng') && !function_exists('imagejpeg')) {
|
|
|
+ throw new \Exception('Need to install GD library or ImageMagick extension');
|
|
|
+ }
|
|
|
+
|
|
|
+ ob_start();
|
|
|
+ // 输出图片到输出缓冲区
|
|
|
+ imagepng($image) || imagejpeg($image);
|
|
|
+ $imageContent = ob_get_contents();
|
|
|
+ ob_end_clean();
|
|
|
+
|
|
|
+ // 将图片内容转为Base64
|
|
|
+ $base64Image = 'data:image/png;base64,' . base64_encode($imageContent);
|
|
|
+
|
|
|
+ // 释放图片资源
|
|
|
+ imagedestroy($image);
|
|
|
+
|
|
|
+ return $base64Image;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检测邮箱
|
|
|
*
|
|
|
@@ -45,7 +94,7 @@ class Validate extends Api
|
|
|
{
|
|
|
$email = $this->request->post('email');
|
|
|
$id = (int)$this->request->post('id');
|
|
|
- $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
|
|
|
+ $count = Users::where('email', '=', $email)->where('id', '<>', $id)->count();
|
|
|
if ($count > 0) {
|
|
|
$this->error(__('邮箱已经被占用'));
|
|
|
}
|
|
|
@@ -63,7 +112,7 @@ class Validate extends Api
|
|
|
{
|
|
|
$username = $this->request->post('username');
|
|
|
$id = (int)$this->request->post('id');
|
|
|
- $count = User::where('username', '=', $username)->where('id', '<>', $id)->count();
|
|
|
+ $count = Users::where('username', '=', $username)->where('id', '<>', $id)->count();
|
|
|
if ($count > 0) {
|
|
|
$this->error(__('用户名已经被占用'));
|
|
|
}
|
|
|
@@ -81,7 +130,7 @@ class Validate extends Api
|
|
|
{
|
|
|
$nickname = $this->request->post('nickname');
|
|
|
$id = (int)$this->request->post('id');
|
|
|
- $count = User::where('nickname', '=', $nickname)->where('id', '<>', $id)->count();
|
|
|
+ $count = Users::where('nickname', '=', $nickname)->where('id', '<>', $id)->count();
|
|
|
if ($count > 0) {
|
|
|
$this->error(__('昵称已经被占用'));
|
|
|
}
|
|
|
@@ -99,7 +148,7 @@ class Validate extends Api
|
|
|
{
|
|
|
$mobile = $this->request->post('mobile');
|
|
|
$id = (int)$this->request->post('id');
|
|
|
- $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
|
|
|
+ $count = Users::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
|
|
|
if ($count > 0) {
|
|
|
$this->error(__('该手机号已经占用'));
|
|
|
}
|
|
|
@@ -115,7 +164,7 @@ class Validate extends Api
|
|
|
public function check_mobile_exist()
|
|
|
{
|
|
|
$mobile = $this->request->post('mobile');
|
|
|
- $count = User::where('mobile', '=', $mobile)->count();
|
|
|
+ $count = Users::where('mobile', '=', $mobile)->count();
|
|
|
if (!$count) {
|
|
|
$this->error(__('手机号不存在'));
|
|
|
}
|
|
|
@@ -131,7 +180,7 @@ class Validate extends Api
|
|
|
public function check_email_exist()
|
|
|
{
|
|
|
$email = $this->request->post('email');
|
|
|
- $count = User::where('email', '=', $email)->count();
|
|
|
+ $count = Users::where('email', '=', $email)->count();
|
|
|
if (!$count) {
|
|
|
$this->error(__('邮箱不存在'));
|
|
|
}
|