简体   繁体   English

如何使用cordova插件检测OTP

[英]how to detect OTP using cordova plugin

I have used this plugin "Phonegap-SMS-reception-plugin" but I am not able to install it from command prompt or manually. 我已经使用了此插件“ Phonegap-SMS-reception-plugin”,但无法从命令提示符或手动安装它。 Other than this I cannot find any other plugin for detecting OTP and fetch the data from sms from hybrid mobile app 除此之外,我找不到其他任何插件来检测OTP并从混合移动应用程序的短信中获取数据

There is some file missing in that plugin. 该插件中缺少一些文件。 Use this cordova-plugin-sms 使用此cordova-plugin-sms

<script type="text/javascript">

    var body = "";
    var address = "";

    $( document ).ready(function() {

        if(( /(ipad|iphone|ipod|android)/i.test(navigator.userAgent) )) {
            document.addEventListener('deviceready', initApp, false);
        } else {
            alert('need run on mobile device for full functionalities.');
        }

    });




            function startWatch() {  // start listening incoming sms
                if(SMS) SMS.startWatch(function(){
                    alert('watching', 'watching started');
                }, function(){
                    alert('failed to start watching');
                });
            }


            function stopWatch()  {   // stop listening incoming sms
                 if(SMS) SMS.stopWatch(function(){
                    update('watching', 'watching stopped');
                }, function(){
                    updateStatus('failed to stop watching');
                });

            }




        function initApp() {
        if (! SMS ) { alert( 'SMS plugin not ready' ); return; }


        document.addEventListener('onSMSArrive', function(e){
            var sms = e.data;

            body = sms.body;
            address = sms.address;

        });
    }


    </script>

Be sure that the app has read sms permission granted in Marshmallow. 确保该应用程序已读取棉花糖中授予的短信权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM