Created
April 23, 2018 21:41
-
-
Save faridfr/ef08120d2323044d1a2d505ad7c1ab9f to your computer and use it in GitHub Desktop.
Laravel Kavenegar.com class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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