如何在IONIC2中自动验证OTP,例如Whats' up in Recharge App

时间:2017-04-05 06:34:51

标签: ionic2

我用于获取OTP短信和SMS Cordova SMS插件列表。

我得到了Smses列表,但我想在我的文本框中输入最新的短信并自动验证OTP。

1 个答案:

答案 0 :(得分:1)

getSMS(sms)
  {

    if(window.SMS)window.SMS.listSMS({},data=>
    {
      setTimeout(()=>{console.log(data);
       this.otp =data;
        if(Array.isArray(this.otp)) {

                for(let i in this.otp) 
                {
                   var msg = this.otp[i];
                      let msgaddress = msg.address;
                     let msgbody = msg.body;
                     var newValue = msgbody.slice(0,34);

                     if(msgaddress == "VK-POCKET" || msgaddress == "VM-POCKET"  && newValue == "your pepocket registration otp is:")
                     {

                          var newVal = msgbody.substring(34,msgbody.length);

                           this.otpname=newVal;
                      }
                     }


                }

       },0 )
    },error=>
    {
      console.log(error);
    });


  }