/** * Register a cell number and respond with a token to be used as its identifier. * POST /vendor/register/{cell} * * @param string $cell of the User * * @return Response from calling the OTP API */ public function signup($cell) { // #$missed_call_service = 'motp'; #$missed_call_service = 'cognalys'; $missed_call_service = env('APP_OTP_PROVIDER', 'cognalys'); if ($cell == '919090909090') { $otp = '11111'; $vendor = new Vendor(); $vendor->signup($cell, $otp); $retval = []; $retval['service'] = 'motp'; $retval['message'] = 'Use 11111 as OTP'; $retval['status'] = 'OK'; $retval['service_response'] = 'OK'; return $retval; } if ($missed_call_service == 'motp') { $ndigits = 3; $password = str_pad(rand(1, 999), $ndigits, "0", STR_PAD_LEFT); $Publickey = '0004-73762a1f-5263457d-fe7d-176d42e7'; $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://api.mOTP.in/v1/{$Publickey}/{$cell}/{$password}"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // grab URL and pass it to the browser $result = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); $json = json_decode($result, true); #print_r($json); $otp = $password; $vendor = new Vendor(); $vendor->signup($cell, $otp); $retval = []; $retval['service'] = 'motp'; $retval['message'] = 'Use the last ' . $ndigits . ' digits of the number you recieved missed call from'; $retval['status'] = $json['Status']; $retval['service_response'] = $json['Result']; } if ($missed_call_service == 'cognalys') { $ndigits = 5; $app_id = 'dfc143fef04f431eb535bd5'; $access_token = '6789863e2fa229edfb3e57251cca55d9a601e6ba'; #https://www.cognalys.com/api/v1/otp/?app_id=dfc143fef04f431eb535bd5&access_token=6789863e2fa229edfb3e57251cca55d9a601e6ba&mobile=+918750688382 $url = 'https://cognalys.p.mashape.com/?'; $url .= 'app_id=' . $app_id; $url .= '&access_token=' . $access_token; $url .= '&mobile=+' . $cell; \Unirest\Request::verifyPeer(false); $result = \Unirest\Request::get($url, array("X-Mashape-Key" => "ehq1KAY8TemshmrDN3lvqKdMiPiAp11jxqijsnJp2pqiVjIMIL", "Accept" => "application/json")); $retval = []; $retval['message'] = 'Use the last ' . $ndigits . ' digits of the number you recieved missed call from'; #$retval['url'] = $url; $retval['service'] = 'cognalys'; $json = $result->body; if ($json->status == 'success') { preg_match_all('/\\d+/', $json->otp_start, $matches); $retval['keymatch'] = $json->keymatch; $retval['otp_start'] = $matches[0][0]; $vendor = new Vendor(); $vendor->signup($cell, $matches[0][0]); } $retval['status'] = $json->status; if ($json->status == 'failed') { $retval['status'] = 'Exception'; $retval['service_response'] = $json->errors; } } return $retval; }