zhenzi0322

一. 官网文档

腾讯防火墙

appid与appSecret配置信息获取

二. 实现效果

暂无图片

三. php代码实现

3.1. 前端引入相应的信息

<meta name="csrf-token" content="{{ csrf_token() }}">
<script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>

<input type="text" name="phone" class="phone_text" maxlength="16" placeholder="手机号码">
<button id="TencentCaptcha" class="send_code" data-appid="20xxxxxx" data-cbfn="Tcode" type="button">获取短信码</button>

3.1.1. 解释属性

data-appid : APPID
data-cbfn : 回调函数名
id=\'TencentCaptcha\' 这个我是默认使用的。

3.2. 回调函数js实现

// 腾讯云极验验证码
var Tcode = new TencentCaptcha(\'20xxx这是appid\', function (res) {
    let phone = $(\'.phone_text\').val();
    let data = {\'ticket\': res.ticket, \'randstr\': res.randstr, \'phone\': phone};
    $.ajax({
        type: \'POST\',
        url: \'url地扯\',
        data: data,
        dataType: \'json\',
        headers: {
            \'X-CSRF-TOKEN\': $(\'meta[name="csrf-token"]\').attr(\'content\')
        },
        success: function (res) {
            console.log(res);
        }
    });
});
// 点击
$(document).on(\'click\', \'#TencentCaptcha\', function () {
    let phone = $(\'.phone_text\').val();
    if (phone) {
        Tcode.show(); //显示拼图验证码出来
    }else{
        // $(\'.error_text\').text(\'手机号不能为空\');
        alert("手机号不能为空");
    }
});

3.3. PHP之Laravel框架实现

下面是一个公共方法

use GuzzleHttp\Client; //使用这个门面

public function tencentCode($ticket, $randstr, $UserIp)
    {
        $aid = \'20xxx\';
        $AppSecretKey = \'0yxxxxxxxxx**\';
        $Randstr = $randstr; // 随机字符串
        $Ticket = $ticket; // 票据
        $UserIP = $UserIp;
        $client = new Client();
        try {
            $repose = $client->get("https://ssl.captcha.qq.com/ticket/verify?aid=" . $aid . "&AppSecretKey=" . $AppSecretKey . "&Ticket=" . $Ticket . "&Randstr=" . $Randstr . "&UserIP=" . $UserIP);
            $res = json_decode($repose->getBody()->getContents(), true);
            return [\'status\' => $res[\'response\'], \'err_msg\' => $res[\'err_msg\']];
        } catch (RequestException $exception) {
            return [\'status\' => 0, \'err_mg\' => $exception];
        }
    }

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-08-22
  • 2021-04-21
  • 2021-05-02
猜你喜欢
  • 2021-10-18
  • 2021-12-05
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
相关资源
相似解决方案