使用 reCATPCHA 进行本机反应

Vic*_*son 5 javascript cross-domain recaptcha react-native

我正在尝试在我的 React Native 应用程序中实现google reCAPTCHA。我正在使用包装的网络视图。

<WebView 
    javaScriptEnabled={true} 
    mixedContentMode={'always'} 
    style={{height: 200}} 
    source={{
        html: this.getWebviewContent()
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google.com/recaptcha/api.js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<My key>"></div><input type="submit" value="Send"/></form></body></html>'
    var tmp =  originalForm
        .replace("[POST_URL]", "http://localhost:3000/v1/video")
        .replace("[TITLE]", this.state.form.title)
        .replace("[DESCRIPTION]", this.state.form.description)
        .replace("[URL]", this.state.form.url); 

    return tmp; 
}
Run Code Online (Sandbox Code Playgroud)

如果我渲染它,它会给我以下错误: 网站所有者错误:网站密钥域无效

我有一个理论,它不想合作,因为我将它作为“文件”运行,并且WebView您无法将文件添加为 Google 仪表板中域的一部分。

有没有办法file://在 Google 的 reCAPTCHA 仪表板中添加权限或伪造域,以便我可以在仪表板中添加该伪造的域。或者我完全迷失了,问题是别的?

mih*_*990 3

baseUrl您可以通过在 prop 中设置来为 WebView 设置域source

<WebView 
    javaScriptEnabled={true} 
    mixedContentMode={'always'} 
    style={{height: 200}} 
    source={{
        html: this.getWebviewContent(),
        baseUrl: 'http://your-domain.com' // <-- SET YOUR DOMAIN HERE
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google.com/recaptcha/api.js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<My key>"></div><input type="submit" value="Send"/></form></body></html>'
    var tmp =  originalForm
        .replace("[POST_URL]", "http://localhost:3000/v1/video")
        .replace("[TITLE]", this.state.form.title)
        .replace("[DESCRIPTION]", this.state.form.description)
        .replace("[URL]", this.state.form.url); 

    return tmp; 
}
Run Code Online (Sandbox Code Playgroud)