User Tools

Site Tools


Sidebar

en:objects:smsactivate:functional:get_code

get_code

get_code($wt_wait); - get activation code from SMS.

The function accepts parameters as input:

  • $wt_wait – wait *10 seconds.
    After testing, the function returns the result of its work to the script :
  • true – the operation was successfully performed
  • false – the operation was not completed

    The resulting code itself can be obtained from the smsactivate->codevariable. However, if your text message is not parsed correctly, use the smsactivate->answervariable for parsing.

    The smsactivate->answer variable can be:

      STATUS_OK:$code - code received (where $code is the activation code)

      STATUS_WAIT_CODE - waiting for SMS
      STATUS_WAIT_RETRY:$lastcode - waiting for the code to be updated (where $lastcode is the last, failed code)
      STATUS_WAIT_RESEND - waiting for SMS to be sent again (the software must click re-send SMS and change the status to 6)
      STATUS_CANCEL - activation canceled
      Possible error:
      NO_ACTIVATION - activation id does not exist
      ERROR_SQL - SQL server error
      BAD_KEY - invalid API key
      BAD_ACTION - Invalid action


    PHP example:

    <?php $xhe_host = "127.0.0.1:7010";
     
    //connect the object to control the emulator, if not already connected
    if(!isset($path))
      $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //Start
    echo "<hr> <font color = blue> smsactivate->".basename(__FILE__)."</font> <hr>";
     
    //set the service api key
    $smsactivate->api_key = '3161df9b1fe1ccb8cfd7dA91db765de8';
     
    //get phone number
    if(!$smsactivate->get_phone_number('ot'))
    {
        while($smsactivate->answer == "NO_NUMBERS")
        {
            $smsactivate->get_phone_number('ot');
            sleep(10);
        }
     
        if(strpos($smsactivate->answer, 'ACCESS_NUMBER') === false)
        {
           echo("answer $smsactivate->servis $smsactivate->answer <br>");
           $app->quit();
        }
    }
     
    //sms sent
    $smsactivate->set_status(1);
    //received phone number
    echo $phone = trim($smsactivate->number);
    echo "<br>";
     
    /* use the number here in the registration form
    after which an SMS is sent to the phone
    */
     
    //wait * 10 in seconds
    $wt_wait = 7;
    //get code from SMS
    if(!$smsactivate->get_code($wt_wait))
    {
        echo("ERROR: $smsactivate->answer could not get code from SMS message");
     
       //inform the service that we release the number
        $smsactivate->set_status(8);
    }
    else//if necessary, correct the parsing of the SMS text, if the code is not correctly parsed from it
    {
       //inform the service that everything is ok
        $smsactivate->set_status();
       //code from sms
        echo trim($smsactivate->code).'<br>';
    }
     
     
    //end
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

     

    C# example:

     

    Java Script example:

     
  • en/objects/smsactivate/functional/get_code.txt · Last modified: 2020/10/13 21:48 (external edit)