前后端分离滑动验证php+vue

PHP

class SlideVerifyService extends BaseService
{
    public $basePath;
    public $im = null;
    public $im_fullbg = null;
    public $im_bg = null;
    public $im_slide = null;
    public $bg_width = 408;
    public $bg_height = 150;
    public $mark_width = 50;
    public $mark_height = 50;
    public $_x = 0;
    public $_y = 0;

    public function make($bg_width = 408, $bg_height = 150)
    {
        $this->bg_width = $bg_width;
        $this->bg_height = $bg_height;
        $this->_init();
        $this->_createSlide();
        $this->_createBg();

        ob_start();
        imagepng($this->im_bg);
        $bg_data = ob_get_contents();
        ob_end_clean();

        ob_start();
        imagepng($this->im_slide, null, 7);
        $slide_data = ob_get_contents();
        ob_end_clean();

        $this->_destroy();
        return [
            "captcha" => $this->_x,
            "bg" => 'data:image/png;base64,' . chunk_split(base64_encode($bg_data)),
            "slide" => 'data:image/png;base64,' . chunk_split(base64_encode($slide_data)),
        ];
    }

    private function _init()
    {
        $this->basePath = Yii::$app->getBasePath() . "/bussadmin/verify/";
        $files = yii\helpers\FileHelper::findFiles($this->basePath . "/bg/",['only'=>['*.png']]);
        $bg = mt_rand(1, count($files));
        $this->im_fullbg = imagecreatefrompng($files[$bg-1]);

        $this->im_bg = imagecreatetruecolor($this->bg_width, $this->bg_height);
        imagecopy($this->im_bg, $this->im_fullbg, 0, 0, 0, 0, $this->bg_width, $this->bg_height);

        $this->im_slide = imagecreatetruecolor($this->mark_width, $this->bg_height);

        $this->_x = mt_rand(50, $this->bg_width - $this->mark_width - 1);
        $this->_y = mt_rand(0, $this->bg_height - $this->mark_height - 1);
    }

    private function _createBg()
    {
        $file_mark = $this->basePath . '/img/mark.png';
        $im = imagecreatef
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值