滑块拼图验证码服务,支持滑块、点选等多种验证方式。有效防止机器注册、暴力破解、垃圾广告等恶意行为。毫秒级响应,验证准确率 99.9%。适用于网站登录、注册、评论、投票等场景。
| 接口 | 方法 | 路径 | 说明 |
|---|---|---|---|
| 获取验证码 | GET | /api/service/aj-captcha/get | 获取滑块拼图验证码,返回 captchaId、背景图、滑块图 |
| 校验验证码 | POST | /api/service/aj-captcha/check | 校验用户滑动轨迹,返回验证结果 |
| 查询服务信息 | GET | /api/service/aj-captcha/info | 查询服务元信息 + 商户调用余额 |
无需参数
{"code":0,"data":{"captchaId":"...","backgroundImage":"...","sliderImage":"..."}}
captchaId (string), sliderOffset (int)
{"code":0,"msg":"验证通过"}
无需参数
{"code":0,"data":{"service":{...},"remain_calls":100,"used_calls":0,"total_calls":1000}}
签名字符串为 AppKey + Timestamp + Nonce,使用 SecretKey 做 HMAC-SHA256,输出小写十六进制。把示例里的 AppKey、SecretKey 换成控制台中的凭证。
const crypto = require('crypto');
const appkey = 'ak_xxxxxxxxxxxxxxxx';
const secretKey = 'sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const baseUrl = '__BASE_URL__';
function signHeaders() {
const timestamp = Math.floor(Date.now() / 1000).toString();
const nonce = crypto.randomBytes(8).toString('hex');
const sign = crypto.createHmac('sha256', secretKey)
.update(appkey + timestamp + nonce)
.digest('hex');
return {
'X-AppKey': appkey,
'X-Timestamp': timestamp,
'X-Nonce': nonce,
'X-Sign': sign
};
}
// 获取验证码
async function getCaptcha() {
const res = await fetch(baseUrl + '/get', { headers: signHeaders() });
return res.json();
}
// 校验滑块偏移,sliderOffset 为用户拖动的像素
async function checkCaptcha(captchaId, sliderOffset) {
const res = await fetch(baseUrl + '/check', {
method: 'POST',
headers: Object.assign({ 'Content-Type': 'application/json' }, signHeaders()),
body: JSON.stringify({ captchaId: captchaId, sliderOffset: sliderOffset })
});
return res.json();
}
getCaptcha().then(function (data) {
console.log(data);
});
<?php
$appkey = 'ak_xxxxxxxxxxxxxxxx';
$secretKey = 'sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$baseUrl = '__BASE_URL__';
function gindimSign(string $appkey, string $secretKey): array
{
$timestamp = (string) time();
$nonce = bin2hex(random_bytes(8));
$sign = hash_hmac('sha256', $appkey . $timestamp . $nonce, $secretKey);
return [
'X-AppKey: ' . $appkey,
'X-Timestamp: ' . $timestamp,
'X-Nonce: ' . $nonce,
'X-Sign: ' . $sign,
];
}
function gindimRequest(string $method, string $url, array $headers, ?string $body = null): array
{
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $body,
]);
$raw = curl_exec($ch);
curl_close($ch);
return json_decode($raw ?: '', true) ?: [];
}
// 1. 获取验证码
$captcha = gindimRequest('GET', $baseUrl . '/get', gindimSign($appkey, $secretKey));
// 2. 校验滑块偏移,sliderOffset 为用户拖动的像素
$payload = json_encode([
'captchaId' => $captcha['data']['captchaId'] ?? '',
'sliderOffset' => 120,
], JSON_UNESCAPED_UNICODE);
$headers = gindimSign($appkey, $secretKey);
$headers[] = 'Content-Type: application/json';
$result = gindimRequest('POST', $baseUrl . '/check', $headers, $payload);