Skip to content

Instantly share code, notes, and snippets.

@faridfr
Created April 23, 2018 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faridfr/ef08120d2323044d1a2d505ad7c1ab9f to your computer and use it in GitHub Desktop.
Save faridfr/ef08120d2323044d1a2d505ad7c1ab9f to your computer and use it in GitHub Desktop.
Laravel Kavenegar.com class
<?php
// you need GuzzleHttp to send requests
// set your configs in properties
// use like this :
// $sms = new \App\Kavenegar();
// $sms = $sms->verify($username,$smstype,$tokens)->getStatusCode();
namespace App;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
class Kavenegar
{
public $url = '';
public $class = '';
public $method = '';
public $baseUrl = 'https://api.kavenegar.com/';
public $apiVersion = 'v1';
private $api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
private $service_number = 'XXXXXXXXXXXX';
public function baseUrl($scope, $method)
{
$this->class = $scope;
$this->method = $method;
return $this->url =
$this->baseUrl .
$this->apiVersion . "/" .
$this->api_key . "/" .
$this->class . "/" .
$this->method . ".json";
}
public function send( $requestMethod , $scope, $method , $requestName , $inputs )
{
$client = new \GuzzleHttp\Client();
$response = $client->request($requestMethod, $this->baseUrl($scope, $method), [
$requestName => $inputs
]);
return $response;
}
public function verify($receptor,$template,$token,$type=''){
$response = $this->send( 'GET' , 'verify' , 'lookup' , 'query' ,
[
'receptor' => $receptor,
'template' => $template,
'token' => array_key_exists(0, $token) ? str_replace(' ', '_', $token[0]): '',
'token2' => array_key_exists(1, $token) ? str_replace(' ', '_', $token[1]) : '',
'token3' => array_key_exists(2, $token) ? str_replace(' ', '_', $token[2]) : '',
'type' => $type
]);
return $response;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment