由于大多数react-native-recaptchaV3库已经过时,所以我试图创建组件以获得不可见的recaptchaV3。但是onMessage()没有返回任何东西来获取令牌。有人能帮我完成这件事吗?
当我删除androidLayerType="software"应用程序时,它就崩溃了。如果使用androidLayerType="software",就会在控制台中得到未定义的内容。
“react本机-webview”:"^11.17.2",
class ReCaptchaComponent extends React.Component {
_webViewRef = React.createRef();
constructor(props) {
super(props);
}
render() {
return (
<View style={{flex: 0.0001, width: 0, height: 0}}>
<WebView
ref={ref => {
this._webViewRef = ref;
}}
androidLayerType="software"
javaScriptEnabled
originWhitelist={['*']}
automaticallyAdjustContentInsets
mixedContentMode={'always'}
onMessage={(e: any) => { console.log('onReceiveToken',e.nativeEvent.data);
}}
source={{html: recaptchaHtml,baseUrl: 'https://testing.xyz'}}
/>
</View>
);
}
}
const recaptchaHtml = `<!DOCTYPE html>
<html>
<head>
<style>
body {
display: flex;
justify-content: left;
align-items: top;
}
</style>
</head>
<body>
<div id="inline-badge"></div>
<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=onRecaptchaLoadCallback"></script>
<script>
function onRecaptchaLoadCallback() {
var clientId = grecaptcha.render('inline-badge', {
'sitekey': '_xBu49Sf-rsc1',
'badge': 'inline',
'size': 'invisible'
});
grecaptcha.ready(function () {
grecaptcha.execute(clientId, {
action: 'verify'
})
.then(function (token) {
window.ReactNativeWebView.postMessage(token, '*')
});
});
}
</script>
</body>
</html>`;
export default ReCaptchaComponent;发布于 2022-04-24 15:42:26
我增加了
react-native-webview -> android -> src -> java -> RNCWebViewManager.java在onReceivedSslError方法上我改变了,
handler.cancel()
至
handler.proceed();
https://stackoverflow.com/questions/71706701
复制相似问题