cryptommer /
smsirlaravel
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Cryptommer\Smsirlaravel; |
||||
| 4 | |||||
| 5 | use GuzzleHttp\Client; |
||||
| 6 | use Ipecompany\Smsirlaravel\SmsirlaravelLogs; |
||||
| 7 | |||||
| 8 | class Smsirlaravel |
||||
| 9 | { |
||||
| 10 | public static function DBlog($result, $messages, $numbers) { |
||||
| 11 | if(config('smsirlaravel.db-log')) { |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 12 | if (!is_array($numbers)) { |
||||
| 13 | $numbers = array($numbers); |
||||
| 14 | } |
||||
| 15 | $res = json_decode($result->getBody()->getContents(),true); |
||||
| 16 | |||||
| 17 | if(count($messages) == 1) { |
||||
| 18 | foreach ( $numbers as $number ) { |
||||
| 19 | if (is_array($messages)) { |
||||
| 20 | $msg = $messages[0]; |
||||
| 21 | } else { |
||||
| 22 | $msg = $messages; |
||||
| 23 | } |
||||
| 24 | $log = SmsirlaravelLogs::create( [ |
||||
|
0 ignored issues
–
show
|
|||||
| 25 | 'response' => $res['Message'], |
||||
| 26 | 'message' => $msg, |
||||
| 27 | 'status' => $res['IsSuccessful'], |
||||
| 28 | 'from' => config('smsirlaravel.line-number'), |
||||
| 29 | 'to' => $number, |
||||
| 30 | ]); |
||||
| 31 | } |
||||
| 32 | } else { |
||||
| 33 | foreach ( array_combine( $messages, $numbers ) as $message => $number ) { |
||||
| 34 | SmsirlaravelLogs::create( [ |
||||
| 35 | 'response' => $res['Message'], |
||||
| 36 | 'message' => $message, |
||||
| 37 | 'status' => $res['IsSuccessful'], |
||||
| 38 | 'from' => config('smsirlaravel.line-number'), |
||||
| 39 | 'to' => $number, |
||||
| 40 | ]); |
||||
| 41 | } |
||||
| 42 | } |
||||
| 43 | } |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * this method used in every request to get the token at first. |
||||
| 48 | * |
||||
| 49 | * @return mixed - the Token for use api |
||||
| 50 | */ |
||||
| 51 | public static function getToken() |
||||
| 52 | { |
||||
| 53 | $client = new Client(); |
||||
| 54 | $body = ['UserApiKey'=>config('smsirlaravel.api-key'),'SecretKey'=>config('smsirlaravel.secret-key'),'System'=>'laravel_v_1_4']; |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 55 | $result = $client->post(config('smsirlaravel.webservice-url').'api/Token',['json'=>$body,'connect_timeout'=>30]); |
||||
| 56 | return json_decode($result->getBody(),true)['TokenKey']; |
||||
| 57 | } |
||||
| 58 | |||||
| 59 | /** |
||||
| 60 | * this method return your credit in sms.ir (sms credit, not money) |
||||
| 61 | * |
||||
| 62 | * @return mixed - credit |
||||
| 63 | */ |
||||
| 64 | public static function credit() |
||||
| 65 | { |
||||
| 66 | $client = new Client(); |
||||
| 67 | $result = $client->get(config('smsirlaravel.webservice-url').'api/credit',['headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 68 | return json_decode($result->getBody(),true)['Credit']; |
||||
| 69 | } |
||||
| 70 | |||||
| 71 | /** |
||||
| 72 | * by this method you can fetch all of your sms lines. |
||||
| 73 | * |
||||
| 74 | * @return mixed , return all of your sms lines |
||||
| 75 | */ |
||||
| 76 | public static function getLines() |
||||
| 77 | { |
||||
| 78 | $client = new Client(); |
||||
| 79 | $result = $client->get(config('smsirlaravel.webservice-url').'api/SMSLine',['headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 80 | return json_decode($result->getBody(),true); |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | /** |
||||
| 84 | * Simple send message with sms.ir account and line number |
||||
| 85 | * |
||||
| 86 | * @param $messages = Messages - Count must be equal with $numbers |
||||
|
0 ignored issues
–
show
|
|||||
| 87 | * @param $numbers = Numbers - must be equal with $messages |
||||
| 88 | * @param null $sendDateTime = don't fill it if you want to send message now |
||||
| 89 | * |
||||
| 90 | * @return mixed, return status |
||||
| 91 | */ |
||||
| 92 | public static function send($messages,$numbers,$sendDateTime = null) |
||||
| 93 | { |
||||
| 94 | $client = new Client(); |
||||
| 95 | $messages = (array)$messages; |
||||
| 96 | $numbers = (array)$numbers; |
||||
| 97 | if($sendDateTime === null) { |
||||
| 98 | $body = ['Messages'=>$messages,'MobileNumbers'=>$numbers,'LineNumber'=>config('smsirlaravel.line-number')]; |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 99 | } else { |
||||
| 100 | $body = ['Messages'=>$messages,'MobileNumbers'=>$numbers,'LineNumber'=>config('smsirlaravel.line-number'),'SendDateTime'=>$sendDateTime]; |
||||
| 101 | } |
||||
| 102 | $result = $client->post(config('smsirlaravel.webservice-url').'api/MessageSend',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
| 103 | |||||
| 104 | self::DBlog($result,$messages,$numbers); |
||||
| 105 | |||||
| 106 | return json_decode($result->getBody(),true); |
||||
| 107 | } |
||||
| 108 | |||||
| 109 | /** |
||||
| 110 | * add a person to the customer club contacts |
||||
| 111 | * |
||||
| 112 | * @param $prefix = mr, dr, dear... |
||||
|
0 ignored issues
–
show
|
|||||
| 113 | * @param $firstName = first name of this contact |
||||
| 114 | * @param $lastName = last name of this contact |
||||
| 115 | * @param $mobile = contact mobile number |
||||
| 116 | * @param string $birthDay = birthday of contact, not require |
||||
| 117 | * @param string $categotyId = which category id of your customer club to join this contact? |
||||
| 118 | * |
||||
| 119 | * @return \Psr\Http\Message\ResponseInterface = $result as json |
||||
| 120 | */ |
||||
| 121 | public static function addToCustomerClub($prefix,$firstName,$lastName,$mobile,$birthDay = '',$categotyId = '') |
||||
| 122 | { |
||||
| 123 | $client = new Client(); |
||||
| 124 | $body = ['Prefix'=>$prefix,'FirstName'=>$firstName,'LastName'=>$lastName,'Mobile'=>$mobile,'BirthDay'=>$birthDay,'CategoryId'=>$categotyId]; |
||||
| 125 | $result = $client->post(config('smsirlaravel.webservice-url').'api/CustomerClubContact',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 126 | // $res = json_decode($result->getBody()->getContents(),true); |
||||
| 127 | |||||
| 128 | self::DBlog($result,"افزودن $firstName $lastName به مخاطبین باشگاه ",$mobile); |
||||
| 129 | |||||
| 130 | return json_decode($result->getBody(),true); |
||||
| 131 | } |
||||
| 132 | |||||
| 133 | /** |
||||
| 134 | * this method send message to your customer club contacts (known as white sms module) |
||||
| 135 | * |
||||
| 136 | * @param $messages |
||||
| 137 | * @param $numbers |
||||
| 138 | * @param null $sendDateTime |
||||
|
0 ignored issues
–
show
|
|||||
| 139 | * @param bool $canContinueInCaseOfError |
||||
| 140 | * |
||||
| 141 | * @return \Psr\Http\Message\ResponseInterface |
||||
| 142 | */ |
||||
| 143 | public static function sendToCustomerClub($messages,$numbers,$sendDateTime = null,$canContinueInCaseOfError = true) |
||||
| 144 | { |
||||
| 145 | $client = new Client(); |
||||
| 146 | $messages = (array)$messages; |
||||
| 147 | $numbers = (array)$numbers; |
||||
| 148 | if($sendDateTime !== null) { |
||||
|
0 ignored issues
–
show
|
|||||
| 149 | $body = ['Messages'=>$messages,'MobileNumbers'=>$numbers,'SendDateTime'=>$sendDateTime,'CanContinueInCaseOfError'=>$canContinueInCaseOfError]; |
||||
| 150 | } else { |
||||
| 151 | $body = ['Messages'=>$messages,'MobileNumbers'=>$numbers,'CanContinueInCaseOfError'=>$canContinueInCaseOfError]; |
||||
| 152 | } |
||||
| 153 | $result = $client->post(config('smsirlaravel.webservice-url').'api/CustomerClub/Send',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 154 | |||||
| 155 | self::DBlog($result,$messages,$numbers); |
||||
| 156 | |||||
| 157 | return json_decode($result->getBody(),true); |
||||
| 158 | |||||
| 159 | } |
||||
| 160 | |||||
| 161 | /** |
||||
| 162 | * this method add contact to the your customer club and then send a message to him/her |
||||
| 163 | * |
||||
| 164 | * @param $prefix |
||||
| 165 | * @param $firstName |
||||
| 166 | * @param $lastName |
||||
| 167 | * @param $mobile |
||||
| 168 | * @param $message |
||||
| 169 | * @param string $birthDay |
||||
| 170 | * @param string $categotyId |
||||
| 171 | * |
||||
| 172 | * @return mixed |
||||
| 173 | */ |
||||
| 174 | public static function addContactAndSend($prefix,$firstName,$lastName,$mobile,$message,$birthDay = '',$categotyId = '') |
||||
| 175 | { |
||||
| 176 | $client = new Client(); |
||||
| 177 | $body = ['Prefix'=>$prefix,'FirstName'=>$firstName,'LastName'=>$lastName,'Mobile'=>$mobile,'BirthDay'=>$birthDay,'CategoryId'=>$categotyId,'MessageText'=>$message]; |
||||
| 178 | $result = $client->post(config('smsirlaravel.webservice-url').'api/CustomerClub/AddContactAndSend',['json'=>[$body],'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 179 | |||||
| 180 | self::DBlog($result,$message,$mobile); |
||||
| 181 | |||||
| 182 | return json_decode($result->getBody(),true); |
||||
| 183 | } |
||||
| 184 | |||||
| 185 | /** |
||||
| 186 | * this method send a verification code to your customer. need active the module at panel first. |
||||
| 187 | * |
||||
| 188 | * @param $code |
||||
| 189 | * @param $number |
||||
| 190 | * |
||||
| 191 | * @param bool $log |
||||
| 192 | * |
||||
| 193 | * @return mixed |
||||
| 194 | */ |
||||
| 195 | public static function sendVerification($code,$number,$log = false) |
||||
| 196 | { |
||||
| 197 | $client = new Client(); |
||||
| 198 | $body = ['Code'=>$code,'MobileNumber'=>$number]; |
||||
| 199 | $result = $client->post(config('smsirlaravel.webservice-url').'api/VerificationCode',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 200 | if($log) { |
||||
| 201 | self::DBlog($result,$code,$number); |
||||
| 202 | } |
||||
| 203 | return json_decode($result->getBody(),true); |
||||
| 204 | } |
||||
| 205 | |||||
| 206 | /** |
||||
| 207 | * @param array $parameters = all parameters and parameters value as an array |
||||
| 208 | * @param $template_id = you must create a template in sms.ir and put your template id here |
||||
|
0 ignored issues
–
show
|
|||||
| 209 | * @param $number = phone number |
||||
| 210 | * @return mixed = the result |
||||
| 211 | */ |
||||
| 212 | public static function ultraFastSend(array $parameters, $template_id, $number) { |
||||
| 213 | $params = []; |
||||
| 214 | foreach ($parameters as $key => $value) { |
||||
| 215 | $params[] = ['Parameter' => $key, 'ParameterValue' => $value]; |
||||
| 216 | } |
||||
| 217 | $client = new Client(); |
||||
| 218 | $body = ['ParameterArray' => $params,'TemplateId' => $template_id,'Mobile' => $number]; |
||||
| 219 | $result = $client->post(config('smsirlaravel.webservice-url').'api/UltraFastSend',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 220 | |||||
| 221 | return json_decode($result->getBody(),true); |
||||
| 222 | } |
||||
| 223 | |||||
| 224 | /** |
||||
| 225 | * this method used for fetch received messages |
||||
| 226 | * |
||||
| 227 | * @param $perPage |
||||
| 228 | * @param $pageNumber |
||||
| 229 | * @param $formDate |
||||
| 230 | * @param $toDate |
||||
| 231 | * |
||||
| 232 | * @return mixed |
||||
| 233 | */ |
||||
| 234 | public static function getReceivedMessages($perPage,$pageNumber,$formDate,$toDate) |
||||
| 235 | { |
||||
| 236 | $client = new Client(); |
||||
| 237 | $result = $client->get(config('smsirlaravel.webservice-url')."api/ReceiveMessage?Shamsi_FromDate={$formDate}&Shamsi_ToDate={$toDate}&RowsPerPage={$perPage}&RequestedPageNumber={$pageNumber}",['headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 238 | |||||
| 239 | return json_decode($result->getBody()->getContents())->Messages; |
||||
| 240 | } |
||||
| 241 | |||||
| 242 | /** |
||||
| 243 | * this method used for fetch your sent messages |
||||
| 244 | * |
||||
| 245 | * @param $perPage = how many sms you want to fetch in every page |
||||
|
0 ignored issues
–
show
|
|||||
| 246 | * @param $pageNumber = the page number |
||||
| 247 | * @param $formDate = from date |
||||
| 248 | * @param $toDate = to date |
||||
| 249 | * |
||||
| 250 | * @return mixed |
||||
| 251 | */ |
||||
| 252 | public static function getSentMessages($perPage,$pageNumber,$formDate,$toDate) |
||||
| 253 | { |
||||
| 254 | $client = new Client(); |
||||
| 255 | $result = $client->get(config('smsirlaravel.webservice-url')."api/MessageSend?Shamsi_FromDate={$formDate}&Shamsi_ToDate={$toDate}&RowsPerPage={$perPage}&RequestedPageNumber={$pageNumber}",['headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 256 | |||||
| 257 | return json_decode($result->getBody()->getContents())->Messages; |
||||
| 258 | } |
||||
| 259 | |||||
| 260 | |||||
| 261 | /** |
||||
| 262 | * @param $mobile = The mobile number of that user who you wanna to delete it |
||||
|
0 ignored issues
–
show
|
|||||
| 263 | * |
||||
| 264 | * @return mixed = the result |
||||
| 265 | */ |
||||
| 266 | public static function deleteContact($mobile) { |
||||
| 267 | $client = new Client(); |
||||
| 268 | $body = ['Mobile' => $mobile, 'CanContinueInCaseOfError' => false]; |
||||
| 269 | $result = $client->post(config('smsirlaravel.webservice-url').'api/CustomerClub/DeleteContactCustomerClub',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]); |
||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 270 | |||||
| 271 | return json_decode($result->getBody(),true); |
||||
| 272 | } |
||||
| 273 | |||||
| 274 | } |
||||
| 275 |