Skip to content

Commit

Permalink
add on off for the services
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroamada committed May 15, 2023
1 parent 81d7473 commit c59234d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Add your ultrasms instanceId and token to your `config/services.php`:
'instanceId' => env('ULTRASMS_INSTANCEID'),
'token' => env('ULTRASMS_TOKEN'),
'isMalaysiaMode' => env('ULTRASMS_MALAYSIA_MODE') ?? 0,
'isEnable' => env('ULTRASMS_ENABLE') ?? 0,
'isDebug' => env('ULTRASMS_DEBUG_ENABLE') ?? 0,
'debugReceiveNumber' => env('ULTRASMS_DEBUG_RECEIVE_NUMBER'),
],
Expand Down
31 changes: 19 additions & 12 deletions src/UltraSmsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class UltraSmsApi
/** @var integer */
public $isMalaysiaMode;

/** @var integer */
public $isEnable;

/** @var integer */
public $isDebug;

Expand All @@ -45,13 +48,14 @@ public function __construct($config)
$this->token = $config['token'];

$this->isMalaysiaMode = $config['isMalaysiaMode'];
$this->isEnable = (isset($config['isEnable']) ? $config['isEnable'] : 0);
$this->isDebug = $config['isDebug'];
$this->debugReceiveNumber = $config['debugReceiveNumber'];


$this->httpClient = new HttpClient([
'base_uri' => $this->apiUrl.$this->instanceId.$this->action,
'timeout' => 2.0,
'timeout' => 8.0,
]);
}

Expand All @@ -64,22 +68,25 @@ public function __construct($config)
*/
public function send($params)
{
try {
$sendsms_url = "?token={$this->token}&priority={$this->priority}&to={$params['to']}&body={$params['mesg']}";
if($this->isEnable)
{
try {
$sendsms_url = "?token={$this->token}&priority={$this->priority}&to={$params['to']}&body={$params['mesg']}";

$response = $this->httpClient->request('GET', $this->apiUrl.$this->instanceId.$this->action.$sendsms_url);
$response = $this->httpClient->request('GET', $this->apiUrl.$this->instanceId.$this->action.$sendsms_url);

$stream = $response->getBody();
$stream = $response->getBody();

$content = $stream->getContents();
$content = $stream->getContents();

$response = json_decode((string) $response->getBody(), true);
$response = json_decode((string) $response->getBody(), true);

return $response;
} catch (DomainException $exception) {
throw CouldNotSendNotification::exceptionUltraSmsRespondedWithAnError($exception);
} catch (\Exception $exception) {
throw CouldNotSendNotification::couldNotCommunicateWithUltraSms($exception);
return $response;
} catch (DomainException $exception) {
throw CouldNotSendNotification::exceptionUltraSmsRespondedWithAnError($exception);
} catch (\Exception $exception) {
throw CouldNotSendNotification::couldNotCommunicateWithUltraSms($exception);
}
}
}
}

0 comments on commit c59234d

Please sign in to comment.