Skip to content

Commit

Permalink
Merge branch 'master' of github.com:yedincisenol/sms
Browse files Browse the repository at this point in the history
  • Loading branch information
yedincisenol committed Oct 27, 2019
2 parents ec89318 + 973b13e commit cae33a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/Config/Sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
'Verimor' => [
'request_endpoint' => 'http://sms.verimor.com.tr/v2/send.json',
'username' => 'username',
'password' => 'password'
]
'username' => 'username',
'password' => 'password',
],
];
10 changes: 6 additions & 4 deletions src/Drivers/Iletimerkezi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class Iletimerkezi extends Sms
* @param $numbers
* @param $header
*
* @return mixed
* @throws DriverSmsSendFailException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \yedincisenol\Sms\Exceptions\DriverConfigurationException
*
* @return mixed
*/
public function send($message, $numbers, $header)
{
Expand All @@ -32,19 +33,20 @@ public function send($message, $numbers, $header)
'text' => $message,
], ]);
} catch (\Exception $e) {
$this->checkResponse($e->getResponse());
$this->checkResponse($e->getResponse());
}
}

/**
* @param $response
*
* @throws DriverSmsSendFailException
*/
protected function checkResponse($response)
{
$xml = simplexml_load_string((string) $response->getBody(), "SimpleXMLElement", LIBXML_NOCDATA);
$xml = simplexml_load_string((string) $response->getBody(), 'SimpleXMLElement', LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
$array = json_decode($json, true);

throw new DriverSmsSendFailException($array['status']['message'], $array['status']['code']);
}
Expand Down
27 changes: 14 additions & 13 deletions src/Drivers/Verimor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace yedincisenol\Sms\Drivers;

use GuzzleHttp\Exception\RequestException;
use http\Client\Response;
use Psr\Http\Message\ResponseInterface;
use yedincisenol\Sms\Exceptions\DriverConfigurationException;

class Verimor extends Sms
Expand All @@ -13,34 +11,36 @@ class Verimor extends Sms
* @var array Required config fields
*/
protected $requiredConfig = [
'username', 'password'
'username', 'password',
];

/**
* @param $message
* @param $numbers
* @param $header
*
* @return void
* @throws \yedincisenol\Sms\Exceptions\DriverConfigurationException
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return void
*/
public function send($message, $numbers, $header)
{
$this->validateConfig();

try {
$this->httpClient->request('POST', $this->config['request_endpoint'], [
'json' => [
'username' => $this->config['username'],
'password' => $this->config['password'],
'username' => $this->config['username'],
'password' => $this->config['password'],
'source_addr' => $header,
'messages' => [
'messages' => [
[
'msg' => $message,
'dest' => implode(',', $numbers)
]
]
]
'msg' => $message,
'dest' => implode(',', $numbers),
],
],
],
]);
} catch (RequestException $exception) {
$this->checkResponse($exception->getCode());
Expand All @@ -49,6 +49,7 @@ public function send($message, $numbers, $header)

/**
* @param $responseCode
*
* @throws DriverConfigurationException
*/
protected function checkResponse($responseCode)
Expand All @@ -62,4 +63,4 @@ protected function checkResponse($responseCode)
break;
}
}
}
}
4 changes: 2 additions & 2 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$verimor = new \yedincisenol\Sms\Sms('Verimor', [
'username' => 'username',
'password' => 'password'
'password' => 'password',
]);

$verimor->send('Selam', ['00905459196661'], 'HEADER');
$verimor->send('Selam', ['00905459196661'], 'HEADER');

0 comments on commit cae33a0

Please sign in to comment.