การยืนยันคำตอบของผู้ใช้
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หน้านี้อธิบายวิธียืนยันการตอบกลับของผู้ใช้ต่อคำถาม reCAPTCHA จากแอปพลิเคชันของคุณ
แบ็กเอนด์
สําหรับผู้ใช้เว็บ คุณสามารถรับโทเค็นการตอบกลับของผู้ใช้ได้ 3 วิธีดังนี้
g-recaptcha-response
พารามิเตอร์ POST เมื่อผู้ใช้ส่งแบบฟอร์มในเว็บไซต์
grecaptcha.getResponse(opt_widget_id)
หลังจากที่ผู้ใช้ผ่านด่าน reCAPTCHA
- เป็นอาร์กิวเมนต์สตริงให้กับฟังก์ชัน Callback หากระบุ
data-callback
ในแอตทริบิวต์แท็ก g-recaptcha
หรือพารามิเตอร์ Callback ในเมธอด grecaptcha.render
สําหรับผู้ใช้ไลบรารี Android คุณสามารถเรียกใช้เมธอด SafetyNetApi.RecaptchaTokenResult.getTokenResult() เพื่อรับโทเค็นการตอบกลับหากสถานะแสดงผลสำเร็จ
ข้อจำกัดของโทเค็น
โทเค็นการตอบกลับของผู้ใช้ reCAPTCHA แต่ละรายการจะใช้ได้เป็นเวลา 2 นาที และจะยืนยันได้ครั้งเดียวเพื่อ
เพื่อป้องกันการโจมตีซ้ำ หากต้องใช้โทเค็นใหม่ คุณก็เรียกใช้การยืนยัน reCAPTCHA อีกครั้งได้
หลังจากได้รับโทเค็นการตอบกลับแล้ว คุณต้องยืนยันโทเค็นดังกล่าวภายใน 2 นาทีด้วย reCAPTCHA โดยใช้
API ต่อไปนี้เพื่อให้แน่ใจว่าโทเค็นถูกต้อง
คำขอ API
URL: https://www.google.com/recaptcha/api/siteverify
วิธีการ: POST
พารามิเตอร์ POST |
คำอธิบาย |
secret |
ต้องระบุ กุญแจที่แชร์ระหว่างเว็บไซต์กับ reCAPTCHA |
response |
ต้องระบุ โทเค็นการตอบกลับของผู้ใช้ที่ได้จากการผสานรวมฝั่งไคลเอ็นต์ reCAPTCHA ในเว็บไซต์ของคุณ |
remoteip |
ไม่บังคับ ที่อยู่ IP ของผู้ใช้ |
การตอบกลับจาก API
การตอบสนองจะเป็นออบเจ็กต์ JSON ดังนี้
{
"success": true|false,
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
"hostname": string, // the hostname of the site where the reCAPTCHA was solved
"error-codes": [...] // optional
}
สำหรับ reCAPTCHA สำหรับ Android
{
"success": true|false,
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
"apk_package_name": string, // the package name of the app where the reCAPTCHA was solved
"error-codes": [...] // optional
}
ข้อมูลอ้างอิงรหัสข้อผิดพลาด
รหัสข้อผิดพลาด |
คำอธิบาย |
missing-input-secret |
ไม่มีพารามิเตอร์ลับ |
invalid-input-secret |
พารามิเตอร์ลับไม่ถูกต้องหรือผิดรูปแบบ |
missing-input-response |
ไม่มีพารามิเตอร์การตอบกลับ |
invalid-input-response |
พารามิเตอร์การตอบกลับไม่ถูกต้องหรือผิดรูปแบบ |
bad-request |
คำขอไม่ถูกต้องหรือผิดรูปแบบ |
timeout-or-duplicate |
การตอบกลับไม่ถูกต้องแล้ว เนื่องจากเก่าเกินไปหรือเคยใช้ไปแล้ว |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[[["\u003cp\u003eThis page details how to verify if a user successfully completed a reCAPTCHA challenge on your website or Android app.\u003c/p\u003e\n"],["\u003cp\u003eYou'll receive a response token from the reCAPTCHA integration that needs to be verified within two minutes using the reCAPTCHA API.\u003c/p\u003e\n"],["\u003cp\u003eVerification involves sending a POST request to the reCAPTCHA API with the secret key, response token, and optionally, the user's IP address.\u003c/p\u003e\n"],["\u003cp\u003eThe API response is a JSON object indicating success or failure, along with details like timestamp and potential error codes.\u003c/p\u003e\n"],["\u003cp\u003eEach response token is valid for a single use and expires after two minutes to prevent replay attacks.\u003c/p\u003e\n"]]],["To verify a user's reCAPTCHA response, obtain the response token via the `g-recaptcha-response` parameter, `grecaptcha.getResponse()`, or a callback function for web users or the `SafetyNetApi.RecaptchaTokenResult.getTokenResult()` method for Android. Then, within two minutes, send a POST request to `https://www.google.com/recaptcha/api/siteverify` with `secret` (your site's key) and `response` (the user token). The optional `remoteip` can be included. The JSON response indicates success, timestamp, and hostname or `apk_package_name` if Android, and error codes if any.\n"],null,["# Verifying the user's response\n\nThis page explains how to verify a user's response to a reCAPTCHA challenge from your application's\nbackend.\n\nFor web users, you can get the user's response token in one of three ways:\n\n- `g-recaptcha-response` POST parameter when the user submits the form on your site\n- [`grecaptcha.getResponse(opt_widget_id)`](/recaptcha/docs/display#js_api) after the user completes the reCAPTCHA challenge\n- As a string argument to your [callback function](/recaptcha/docs/display#render_param) if `data-callback` is specified in either the `g-recaptcha` tag attribute or the callback parameter in the `grecaptcha.render` method\n\nFor Android library users, you can call the\n[SafetyNetApi.RecaptchaTokenResult.getTokenResult()](https://developers.google.com/android/reference/com/google/android/gms/safetynet/SafetyNetApi.RecaptchaTokenResult.html#getTokenResult())\nmethod to get response token if the status returns successful.\n\nToken Restrictions\n------------------\n\nEach reCAPTCHA user response token is valid for two minutes, and can only be verified *once* to\nprevent replay attacks. If you need a new token, you can re-run the reCAPTCHA verification.\n\nAfter you get the response token, you need to verify it within two minutes with reCAPTCHA using the\nfollowing API to ensure the token is valid.\n\nAPI Request\n-----------\n\nURL: `https://www.google.com/recaptcha/api/siteverify`\n\nMETHOD: `POST`\n\n| POST Parameter | Description |\n|----------------|---------------------------------------------------------------------------------------------------|\n| `secret` | Required. The shared key between your site and reCAPTCHA. |\n| `response` | Required. The user response token provided by the reCAPTCHA client-side integration on your site. |\n| `remoteip` | Optional. The user's IP address. |\n\nAPI Response\n------------\n\nThe response is a JSON object: \n\n {\n \"success\": true|false,\n \"challenge_ts\": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)\n \"hostname\": string, // the hostname of the site where the reCAPTCHA was solved\n \"error-codes\": [...] // optional\n }\n\nFor reCAPTCHA Android: \n\n {\n \"success\": true|false,\n \"challenge_ts\": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)\n \"apk_package_name\": string, // the package name of the app where the reCAPTCHA was solved\n \"error-codes\": [...] // optional\n }\n\n### Error code reference\n\n| Error code | Description |\n|--------------------------|---------------------------------------------------------------------------------|\n| `missing-input-secret` | The secret parameter is missing. |\n| `invalid-input-secret` | The secret parameter is invalid or malformed. |\n| `missing-input-response` | The response parameter is missing. |\n| `invalid-input-response` | The response parameter is invalid or malformed. |\n| `bad-request` | The request is invalid or malformed. |\n| `timeout-or-duplicate` | The response is no longer valid: either is too old or has been used previously. |"]]