Browse Source

feat():订单页面

geek 4 years ago
parent
commit
c6cc1e16ab

+ 9 - 4
application/api/controller/Admin.php

@@ -12,6 +12,7 @@ use app\common\until\Until;
 use think\captcha\Captcha;
 use think\Db;
 use think\Exception;
+use think\facade\Cache;
 use think\Request;
 
 class Admin extends BaseController {
@@ -153,6 +154,7 @@ class Admin extends BaseController {
      *           @OA\Property(description="登入账号", property="account", type="string", default="admin"),
      *           @OA\Property(description="登入密码", property="password", type="string", default="123456"),
      *           @OA\Property(description="验证码", property="code", type="string", default="akjs"),
+     *           @OA\Property(description="生成验证码时的唯一码", property="uniqueKey", type="string", default="sdafsdfsd"),
      *           required={"account","password","code"})
      *       )
      *     ),
@@ -164,13 +166,15 @@ class Admin extends BaseController {
         $rule = [
             'account|用户名' => 'require',
             'password|内容'  => 'require',
-            'code|验证码'    => 'require'
+            'code|验证码'    => 'require',
+            'uniqueKey|唯一码'    => 'require'
         ];
         Until::check($rule, $input);
-        if( !captcha_check($input['code'] )) {
+        if( strtolower($input['code']) != strtolower(Cache::get($input['uniqueKey']))) {
             // 验证失败
             throw new ApiException('验证码错误');
         }
+        Cache::rm('uniqueKey');
         $model = (new AdminModel());
         $where[] = ['a.account', '=', $input['account']];
         $where[] = ['a.password', '=', $input['password']];
@@ -247,14 +251,15 @@ class Admin extends BaseController {
      * @OA\GET(path="/api/Admin/verifyImg",
      *   tags={"管理员管理"},
      *   summary="生成验证码",
+     *     @OA\Parameter(name="uniqueKey", in="query", description="唯一id", @OA\Schema(type="string",default="1121212")),
      *   @OA\RequestBody(
      *     ),
      *   @OA\Response(response="200", description="请求成功")
      * )
      */
-    public function verifyImg() {
+    public function verifyImg($uniqueKey) {
         $captcha = new Captcha();
-        return $captcha->entry();
+        return $captcha->entry('',$uniqueKey);
     }
 
     /**

+ 12 - 0
public/api.yaml

@@ -159,6 +159,10 @@ paths:
                   description: 验证码
                   type: string
                   default: akjs
+                uniqueKey:
+                  description: 生成验证码时的唯一码
+                  type: string
+                  default: sdafsdfsd
               type: object
       responses:
         '200':
@@ -223,6 +227,14 @@ paths:
         - 管理员管理
       summary: 生成验证码
       operationId: 'app\api\controller\Admin::verifyImg'
+      parameters:
+        -
+          name: uniqueKey
+          in: query
+          description: 唯一id
+          schema:
+            type: string
+            default: '1121212'
       requestBody: {  }
       responses:
         '200':

+ 5 - 2
vendor/topthink/think-captcha/src/Captcha.php

@@ -11,6 +11,7 @@
 
 namespace think\captcha;
 
+use think\facade\Cache;
 use think\facade\Session;
 
 class Captcha
@@ -133,7 +134,7 @@ class Captcha
      * @param string $id 要生成验证码的标识
      * @return \think\Response
      */
-    public function entry($id = '')
+    public function entry($id = '',$unique = '')
     {
         // 图片宽(px)
         $this->imageW || $this->imageW = $this->length * $this->fontSize * 1.5 + $this->length * $this->fontSize / 2;
@@ -193,13 +194,15 @@ class Captcha
         }
 
         // 保存验证码
+        $verifyCode = implode('',$code);
         $key                   = $this->authcode($this->seKey);
         $code                  = $this->authcode(strtoupper(implode('', $code)));
         $secode                = [];
         $secode['verify_code'] = $code; // 把校验码保存到session
         $secode['verify_time'] = time(); // 验证码创建时间
         Session::set($key . $id, $secode, '');
-
+        Cache::set($unique,$verifyCode,600);
+        
         ob_start();
         // 输出图像
         imagepng($this->im);