-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cb03dc
commit 0d387b7
Showing
5 changed files
with
101 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Laraflow\Sms\Drivers; | ||
|
||
use Illuminate\Http\Client\Response; | ||
use Illuminate\Support\Facades\Http; | ||
use Laraflow\Sms\Contracts\SmsDriver; | ||
use Laraflow\Sms\SmsMessage; | ||
|
||
/** | ||
* @reference https://www.smsapi.com/docs/#2-single-sms | ||
*/ | ||
class SmsApi extends SmsDriver | ||
{ | ||
/** | ||
* this function allow programmer to append more config | ||
* that may or may be needed in the configuration file | ||
* | ||
* @return string[] | ||
*/ | ||
protected function mergeConfig(): array | ||
{ | ||
return [ | ||
'url' => 'https://api.smsapi.com/sms.do', | ||
'format' =>'json' | ||
]; | ||
} | ||
|
||
/** | ||
* Return validation rules for | ||
* that sms driver to operate. | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'url' => 'required|url:http,https', | ||
'api_token' => 'required|string' | ||
]; | ||
} | ||
|
||
/** | ||
* Execute the sms sending request to api provider | ||
* | ||
* @param SmsMessage $message | ||
* @return Response | ||
*/ | ||
public function send(SmsMessage $message): Response | ||
{ | ||
$this->payload = [ | ||
'to' => $message->getReceiver(), | ||
'from' => $message->getSender(), | ||
'message' => $message->getContent(), | ||
'format' => $this->config['format'] | ||
]; | ||
|
||
$this->removeEmptyParams(); | ||
|
||
return Http::withoutVerifying() | ||
->timeout(30) | ||
->withToken($this->config['api_token']) | ||
->withHeader('Content-Type', 'application/json') | ||
->withHeader('Accept', 'application/json') | ||
->post($this->config['url'], $this->payload); | ||
|
||
} | ||
} |
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