Skip to content

Commit

Permalink
Add ippanel driver
Browse files Browse the repository at this point in the history
  • Loading branch information
daniyal2959 authored and jabysa committed Jun 23, 2022
1 parent 67978ef commit bb1c042
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ For PHP integration you can use [jaby/sms](https://github.com/jaby/sms) package.


# List of available drivers
- [ippanel](https://ippanel.com/) :heavy_check_mark:
- [farazsms](https://farazsms.com/) :heavy_check_mark:
- [kavenegar](https://kavenegar.com/) :heavy_check_mark:

Expand Down
167 changes: 167 additions & 0 deletions src/Drivers/ippanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php


namespace Jaby\Sms\Drivers;


use Jaby\Sms\SmsInterface;

class ippanel implements SmsInterface
{
protected $drive = 'ippanel';

protected $method;

protected $username;

protected $password;

protected $from;

protected $pattern_code;

protected $to;

protected $input_data;

protected $url;

protected $numbers;

protected $data;

protected $text;

/**
* farazsms constructor.
*/
public function __construct()
{
$this->username = config('sms.drivers.'.$this->drive.'.username');
$this->password = config('sms.drivers.'.$this->drive.'.password');
$this->from = config('sms.drivers.'.$this->drive.'.from');
$this->url = config('sms.drivers.'.$this->drive.'.urlPattern');
}

/**
* @return bool|mixed|string
*/
public function send()
{
if ($this->method == 'pattern')
$res = $this->sendPattern();
else
$res = $this->message($this->text);
return $res;
}

/**
* @param $text
* @return $this|mixed
*/
public function text($text)
{
$this->text = $text;

return $this;
}

/**
* @param null $pattern_code
* @return $this|mixed
*/
public function pattern($pattern_code = null)
{
$this->method = 'pattern';
if ($pattern_code)
$this->pattern_code = $pattern_code;
return $this;
}

/**
* @param array $data
* @return $this|mixed
*/
public function data(array $data)
{
$this->data = $data;

return $this;
}

/**
* @param $from
* @return $this|mixed
*/
public function from($from)
{
$this->from = $from;

return $this;
}

/**
* @param array $numbers
* @return $this|mixed
*/
public function to(array $numbers)
{
$this->numbers = $numbers;

return $this;
}

/**
* @return bool|mixed|string
*/
public function sendPattern()
{
$numbers = $this->numbers;
$pattern_code = $this->pattern_code;
$username = $this->username;
$password = $this->password;
$from = $this->from;
$to = $numbers;
$input_data = $this->data;
$url = $this->url."?username=" . $username . "&password=" . urlencode($password) . "&from=$from&to=" . json_encode($to) . "&input_data=" . urlencode(json_encode($input_data)) . "&pattern_code=$pattern_code";
$handler = curl_init($url);
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handler, CURLOPT_POSTFIELDS, $input_data);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handler);
return $response;
}

/**
* @param $text
* @return mixed
*/
public function message($text)
{

$this->url = config('sms.drivers.'.$this->drive.'.urlNormal');

$rcpt_nm = $this->numbers;
$param = array
(
'uname'=> $this->username ,
'pass'=> $this->password,
'from'=>$this->from,
'message'=>$text,
'to'=>json_encode($rcpt_nm),
'op'=>'send'
);

$handler = curl_init($this->url);
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handler, CURLOPT_POSTFIELDS, $param);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
$response2 = curl_exec($handler);

$response2 = json_decode($response2);
$res_code = $response2[0];
$res_data = $response2[1];

return $res_data;
}
}
8 changes: 8 additions & 0 deletions src/config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
|
*/
'drivers' => [
'ippanel' => [
'username' => 'username',
'password' => 'password',
'urlPattern' => 'https://ippanel.com/patterns/pattern',
'urlNormal' => 'https://ippanel.com/services.jspd',
'from' => '+983000505',
],
'farazsms' => [
'username' => 'username',
'password' => 'password',
Expand Down Expand Up @@ -53,6 +60,7 @@
*/

'map' => [
'ippanel' => Jaby\Sms\Drivers\ippanel::class,
'farazsms' => Jaby\Sms\Drivers\farazsms::class,
'kavenegar' => Jaby\Sms\Drivers\kavenegar::class,
]
Expand Down

0 comments on commit bb1c042

Please sign in to comment.