1
驗證它的時候總是返回false後,我得到令牌g-recaptcha-response
的響應,我與驗證碼驗證它是這樣的:驗證碼與谷歌
@Service
public class RecaptchaService {
private static class RecaptchaResponse {
@JsonProperty("success")
private boolean success;
@JsonProperty("error-codes")
private Collection<String> errorCodes;
}
@Value("${recaptcha.url}")
private String recaptchaUrl;
@Value("${recaptcha.secret-key}")
private String recaptchaSecretKey;
public boolean isResponseValid(String response) {
RestTemplate restTemplate = new RestTemplate();
Map<String, String> params = new HashMap<String, String>();
params.put("secret", recaptchaSecretKey);
params.put("response", response);
RecaptchaResponse recaptchaResponse = restTemplate.postForEntity(recaptchaUrl, params, RecaptchaResponse.class).getBody();
return recaptchaResponse.success;
}
}
但我總是得到false
爲recaptchaResponse.success
和[missing-input-response, missing-input-secret]
爲error-codes