PHP code example of static7 / tencent-captcha

1. Go to this page and download the library: Download static7/tencent-captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

static7 / tencent-captcha example snippets


    //腾讯验证码
    $Captcha = new \static7\Captcha(['aid'=>'xxx',''=>'xxxx']);

    /**
     * Submit
     * @author staitc7 <[email protected]>
     * @return mixed
     * @throws \think\Exception
     */
    public function submit()
    {
        $param=$this->app->request->param();
        $Captcha=new \static7\Captcha();
        // 两种方式 一种
//        $result=$Captcha->setRandstr($param['randstr'])->setTicket($param['ticket'])->verify();
        //或者
        $result=$Captcha->verify($param['ticket'],$param['randstr']);
        if ((int)$result['response']===0){
            return $this->result($param,0,$result['err_msg']);
        }
        return $this->result($param,1,'成功');
    }