Home > other >  SMS Alert API Validation in laravel
SMS Alert API Validation in laravel

Time:10-19

public function verifyotp(Request $request) { $mobile=$request->mobilenumber;

$otp=$request->otp;


$client = new \GuzzleHttp\Client();
$tem='https://www.smsalert.co.in/api/mverify.json?apikey=#&mobileno=';
$cod='&code=';
$msg=($tem.$mobile.$cod.$otp);
$res=$client->request('POST', $msg);
(string) $res->getBody();


if($res->getBody(['description']=== "['desc']:Code does not match.")
{
    echo 'Code Not Matched';
}

elseif(($res->getBody(['description'] === "['desc']:Code Matched successfully."))
{
    echo  'Code Matched;
}

}

I have get response from api.I got Two response

one is like this

{ "status": "success", "description": { "desc": "Code does not match." } }

Second like this

{ "status": "success", "description": { "desc": "Code matched successfully." } } In This response i want to read "desc" on my controller

How to check desc using if condition ?

CodePudding user response:

You can use json_decode function like this :

$result = json_decode($response);
echo $result->description->desc;

see this for detail

Done...

  • Related