Skip to content

Commit 3771cf4

Browse files
start
1 parent 68f6fd1 commit 3771cf4

9 files changed

+357
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
3+
composer\.lock

.styleci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: psr2

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
All notable changes to `:package_name` will be documented in this file.
4+
5+
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
6+
7+
## NEXT - YYYY-MM-DD
8+
9+
### Added
10+
- Nothing
11+
12+
### Deprecated
13+
- Nothing
14+
15+
### Fixed
16+
- Nothing
17+
18+
### Removed
19+
- Nothing
20+
21+
### Security
22+
- Nothing

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2017 :author_name <:author_email>
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

composer.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "mahdimajidzadeh/kavenegar",
3+
"type": "library",
4+
"description": "laravel package for Kavenegar sms",
5+
"keywords": [
6+
"sms",
7+
"kavenegar"
8+
],
9+
"homepage": "https://github.com/MahdiMajidzadeh/kavenegar",
10+
"license": "MIT",
11+
"authors": [
12+
{
13+
"name": "Mahdi Majidzadeh",
14+
"email": "[email protected]",
15+
"homepage": "http://majidzadeh.ir",
16+
"role": "Developer"
17+
}
18+
],
19+
"require": {
20+
"illuminate/support": "~5.1",
21+
"php" : "~5.6|~7.0",
22+
"guzzlehttp/guzzle": "~6.0"
23+
},
24+
"require-dev": {
25+
"phpunit/phpunit" : ">=5.4.3",
26+
"squizlabs/php_codesniffer": "^2.3"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"MahdiMajidzadeh\\kavenegar\\": "src"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"MahdiMajidzadeh\\kavenegar\\": "tests"
36+
}
37+
},
38+
"scripts": {
39+
"test": "phpunit",
40+
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
41+
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
42+
},
43+
"extra": {
44+
"branch-alias": {
45+
"dev-master": "1.0-dev"
46+
}
47+
},
48+
"config": {
49+
"sort-packages": true
50+
}
51+
}

src/Kavenegar.php

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<?php
2+
3+
namespace MahdiMajidzadeh\kavenegar;
4+
5+
use GuzzleHttp\Client;
6+
7+
class Kavenegar
8+
{
9+
10+
private $base_url;
11+
12+
public function __construct()
13+
{
14+
$this->base_url = config('kavenegar.base_url').config('kavenegar.key').'/';
15+
}
16+
17+
public function send($receptor, $message, $sender = null, $date = null, $type = null, $localid = null)
18+
{
19+
if (is_array($receptor)) {
20+
$receptor = implode(",", $receptor);
21+
}
22+
if (is_array($localid)) {
23+
$localid = implode(",", $localid);
24+
}
25+
26+
$params = array(
27+
"receptor" => $receptor,
28+
"sender" => $sender,
29+
"message" => $message,
30+
"date" => $date,
31+
"type" => $type,
32+
"localid" => $localid
33+
);
34+
35+
return $this->execute('sms/send.json', $params);
36+
}
37+
38+
public function sendArray($receptor, $sender, $message, $date = null, $type = null, $localmessageid = null)
39+
{
40+
if (!is_array($receptor)) {
41+
$receptor = (array) $receptor;
42+
}
43+
if (!is_array($sender)) {
44+
$sender = (array) $sender;
45+
}
46+
if (!is_array($message)) {
47+
$message = (array) $message;
48+
}
49+
$repeat = count($receptor);
50+
if (!is_null($type) && !is_array($type)) {
51+
$type = array_fill(0, $repeat, $type);
52+
}
53+
if (!is_null($localmessageid) && !is_array($localmessageid)) {
54+
$localmessageid = array_fill(0, $repeat, $localmessageid);
55+
}
56+
57+
$params = array(
58+
"receptor" => json_encode($receptor),
59+
"sender" => json_encode($sender),
60+
"message" => json_encode($message),
61+
"date" => $date,
62+
"type" => json_encode($type),
63+
"localmessageid" => json_encode($localmessageid)
64+
);
65+
66+
return $this->execute('sms/sendarray.json', $params);
67+
}
68+
69+
public function status($messageid)
70+
{
71+
$params = array(
72+
"messageid" => is_array($messageid) ? implode(",", $messageid) : $messageid
73+
);
74+
75+
return $this->execute('sms/status.json',$params);
76+
}
77+
78+
public function statusLocalMessageid($localid)
79+
{
80+
$params = array(
81+
"localid" => is_array($localid) ? implode(",", $localid) : $localid
82+
);
83+
return $this->execute('sms/statuslocalmessageid.json', $params);
84+
}
85+
86+
public function select($messageid)
87+
{
88+
$params = array(
89+
"messageid" => is_array($messageid) ? implode(",", $messageid) : $messageid
90+
);
91+
92+
return $this->execute('sms/select.json', $params);
93+
}
94+
95+
public function selectOutbox($startdate, $enddate = null, $sender = null)
96+
{
97+
$params = array(
98+
"startdate" => $startdate,
99+
"enddate" => $enddate,
100+
"sender" => $sender
101+
);
102+
103+
return $this->execute('sms/selectoutbox.json', $params);
104+
}
105+
106+
public function latestOutbox($pagesize = null, $sender = null)
107+
{
108+
$params = array(
109+
"pagesize" => $pagesize,
110+
"sender" => $sender
111+
);
112+
113+
return $this->execute('sms/latestoutbox.json', $params);
114+
}
115+
116+
public function countOutbox($statustext, $startdate = null, $status = 1)
117+
{
118+
$params = array(
119+
"statustext" => $statustext,
120+
"startdate" => $startdate,
121+
"status" => $status
122+
);
123+
124+
return $this->execute('sms/countoutbox.json', $params);
125+
}
126+
127+
public function cancel($messageid)
128+
{
129+
$params = array(
130+
"messageid" => is_array($messageid) ? implode(",", $messageid) : $messageid
131+
);
132+
133+
return $this->execute('sms/cancel.json',$params);
134+
}
135+
136+
public function Receive($linenumber, $isread = 0)
137+
{
138+
$params = array(
139+
"linenumber" => $linenumber,
140+
"isread" => $isread
141+
);
142+
143+
return $this->execute('sms/receive.json', $params);
144+
}
145+
146+
public function countInbox($startdate, $enddate, $linenumber, $isread = 0)
147+
{
148+
$params = array(
149+
"startdate" => $startdate,
150+
"enddate" => $enddate,
151+
"linenumber" => $linenumber,
152+
"isread" => $isread
153+
);
154+
155+
return $this->execute('sms/countinbox.json', $params);
156+
}
157+
158+
public function countPostalcode($postalcode)
159+
{
160+
$params = array(
161+
"postalcode" => $postalcode
162+
);
163+
return $this->execute('sms/countpostalcode.json', $params);
164+
}
165+
166+
167+
public function sendByPostalcode($postalcode, $sender, $message, $mcistartindex, $mcicount, $mtnstartindex, $mtncount, $date = null)
168+
{
169+
$params = array(
170+
"postalcode" => $postalcode,
171+
"sender" => $sender,
172+
"message" => $message,
173+
"mcistartindex" => $mcistartindex,
174+
"mcicount" => $mcicount,
175+
"mtnstartindex" => $mtnstartindex,
176+
"mtncount" => $mtncount,
177+
"date" => $date
178+
);
179+
180+
return $this->execute('sms/sendbypostalcode.json', $params);
181+
}
182+
183+
public function lookup($receptor, $template, $token, $token2 = null, $token3 = null, $type = null)
184+
{
185+
$params = array(
186+
"receptor" => $receptor,
187+
"token" => $token,
188+
"token2" => $token2,
189+
"token3" => $token3,
190+
"template" => $template,
191+
"type" => $type
192+
);
193+
194+
return $this->execute('verify/lookup.json', $params);
195+
}
196+
197+
private function execute($url, $params)
198+
{
199+
$client = new Client([
200+
'base_uri' => $this->base_url,
201+
]);
202+
203+
$response = $client->request('POST', $url, [
204+
'form_params' => $params
205+
]);
206+
207+
$body = (string)$response->getBody();
208+
209+
// return json_decode($body);
210+
return ($body);
211+
212+
// return $this->base_url;
213+
}
214+
}

src/config/kavenegar.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
return [
4+
5+
'base_url' => 'http://api.kavenegar.com/v1/',
6+
7+
'key' => '4D51653777736E7661735074574451497557377841673D3D',
8+
// 'key' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
9+
10+
];

src/kavenegarServiceProvider.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace MahdiMajidzadeh\kavenegar;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class kavenegarServiceProvider extends ServiceProvider
8+
{
9+
public function boot()
10+
{
11+
$this->publishes([
12+
__DIR__.'/config/kavenegar.php' => config_path('kavenegar.php'),
13+
]);
14+
}
15+
16+
public function register()
17+
{
18+
//
19+
}
20+
}

0 commit comments

Comments
 (0)