php Poster生成

作者:admin 时间:24-06-14 阅读数:132人阅读

官网

    public function captchaada(Request $request)
    {
        # 自定义参数
        $params = [
            'src'           => public_path('5a038e28ccc90c05cee573d301d87a.png'),  // 背景图片,尺寸 340 * 191
            'im_width'      => 340, // 画布宽度
            'im_height'     => 251, // 画布高度
            'im_type'       => 'png', // png 默认 jpg quality 质量
            'quality'       => 80,    // jpg quality 质量
            'bg_width'      => 340, // 背景宽度
            'bg_height'     => 191, // 背景高度
            'slider_width'  => 50,  // 滑块宽度
            'slider_height' => 50,  // 滑块高度
            'slider_border' => 2,   // 滑块边框
            'slider_bg'     => 1,   // 滑块背景数量
        ];

        $type = input('type', 'slider');
        if($type == 'rotate'){
            $params = [
                'src'           => public_path('logo-128.png'),  // 背景图片,尺寸 350 * 350 正方形都可 
                'im_width'      => 350, // 画布宽度
                'im_height'     => 350, // 画布高度
                'im_type'       => 'png', // png 默认 jpg quality 质量
                'quality'       => 80,    // jpg quality 质量
            ];
        }
        /**
         * 获取验证参数
         * 内部使用了 laravel 的 cache 缓存,返回的是图片的 base64 、 缓存key 、滑块高度
         * @param string $type   验证码类型
         * @param array  $params 验证码自定义参数
         * @return arary
         */
        $data = PosterManager::Captcha()->type($type)->config($params)->get();
        Cache::set($data['key'], $data['secret']);
        return JsonResponse(200, 'ok', $data);
    }

    public function captchaada_check(Request $request)
    {
        $type = input('type', 'slider');
        $x =  input('x');
        $key =  input('key');
        if(empty($x) || empty($key)){
            return JsonResponse(200, '参数不存在', null, false);
        } 
        $secret = '';
        if(Cache::has($key)){
            $secret = Cache::get($key);
        }
        //key x坐标 容错值 签名
        $res = PosterManager::Captcha()->type($type)->check($key, $x, 6, $secret);
        if(!$res){
            return JsonResponse(200, '校验失败', $res);
        }
        return JsonResponse(200, '校验成功', $res);
    }


发表评论

您是本站第2299名访客 今日有0篇新文章