Overview

Namespaces

  • SMSApi
    • Api
      • Action
        • Phonebook
        • Sender
        • Sms
        • User
      • Response
    • Exception
    • Proxy
      • Http

Classes

  • SMSApi\Proxy\Http\AbstractHttp
  • SMSApi\Proxy\Http\Curl
  • SMSApi\Proxy\Http\Native
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace SMSApi\Api\Action\Sms;
  4: 
  5: use SMSApi\Api\Action\AbstractAction;
  6: use SMSApi\Api\Response\StatusResponse;
  7: use SMSApi\Proxy\Uri;
  8: 
  9: /**
 10:  * Class Send
 11:  * @package SMSApi\Api\Action\Sms
 12:  *
 13:  * @method StatusResponse execute()
 14:  */
 15: class Send extends AbstractAction
 16: {
 17:     /**
 18:      * @var string
 19:      */
 20:     protected $encoding = 'utf-8';
 21: 
 22:     /**
 23:      * @param $data
 24:      * @return StatusResponse
 25:      */
 26:     protected function response($data)
 27:     {
 28:         return new StatusResponse($data);
 29:     }
 30: 
 31:     /**
 32:      * @return Uri
 33:      * @throws \SMSApi\Exception\ActionException
 34:      */
 35:     public function uri() {
 36: 
 37:         $query = "";
 38: 
 39:         $query .= $this->paramsLoginToQuery();
 40: 
 41:         $query .= $this->paramsBasicToQuery();
 42: 
 43:         $query .= $this->paramsOther();
 44: 
 45:         return new Uri( $this->proxy->getProtocol(), $this->proxy->getHost(), $this->proxy->getPort(), "/api/sms.do", $query );
 46:     }
 47: 
 48:     /**
 49:      * Set SMS text message.
 50:      *
 51:      * Content of one message is normally 160 characters per single
 52:      * SMS or 70 in case of using at least one special character
 53:      *
 54:      * @param $text
 55:      * @return $this
 56:      */
 57:     public function setText( $text ) {
 58:         $this->params[ 'message' ] = urlencode( $text );
 59:         return $this;
 60:     }
 61: 
 62:     /**
 63:      * Set the SMS encoding charset, default is UTF-8.
 64:      *
 65:      * Example:
 66:      * windows-1250
 67:      * iso-8859-2
 68:      *
 69:      * @param string $encoding
 70:      * @return $this
 71:      */
 72:     public function setEncoding( $encoding ) {
 73:         $this->encoding = $encoding;
 74:         return $this;
 75:     }
 76: 
 77: 
 78:     /**
 79:      * Set mobile phone number of the recipients.
 80:      *
 81:      * @param string|array|int $to Phone number recipient/s.
 82:      * @return $this
 83:      */
 84:     public function setTo( $to ) {
 85: 
 86:         if ( !is_array( $to ) ) {
 87:             $to = array( $to );
 88:         }
 89: 
 90:         $this->to->exchangeArray( $to );
 91:         return $this;
 92:     }
 93: 
 94:     /**
 95:      * Set name of the group from the phone book to which message should be sent.
 96:      *
 97:      * @param string $group String group name
 98:      * @return $this
 99:      */
100:     public function setGroup( $group ) {
101:         $this->group = $group;
102:         return $this;
103:     }
104: 
105:     /**
106:      * Set scheduled date sending message.
107:      *
108:      * Setting a past date will result in sending message instantly.
109:      *
110:      * @param mixed $date set timestamp or ISO 8601 date format
111:      * @return $this
112:      */
113:     public function setDateSent( $date ) {
114:         $this->date = $date;
115:         return $this;
116:     }
117: 
118:     /**
119:      * Set optional custom value sent with SMS and sent back in CALLBACK.
120:      *
121:      * @param string|array $idx
122:      * @return $this
123:      */
124:     public function setIDx( $idx ) {
125:         if ( !is_array( $idx ) ) {
126:             $idx = array( $idx );
127:         }
128: 
129:         $this->idx->exchangeArray( $idx );
130:         return $this;
131:     }
132: 
133:     /**
134:      * Set checking idx is unique.
135:      *
136:      * Prevents from sending more than one message with the same idx.
137:      * When this parameter is set and message with the same idx was
138:      * already sent error 53 is returned.
139:      *
140:      * @param bool $check
141:      * @return $this
142:      */
143:     public function setCheckIDx( $check ) {
144:         if ( $check == true ) {
145:             $this->params[ "check_idx" ] = "1";
146:         } else if ( $check == false ) {
147:             $this->params[ "check_idx" ] = "0";
148:         }
149: 
150:         return $this;
151:     }
152: 
153:     /**
154:      * Set affiliate code.
155:      *
156:      * @param string $partner affiliate code
157:      * @return $this
158:      */
159:     public function setPartner( $partner ) {
160:         $this->params[ "partner_id" ] = $partner;
161:         return $this;
162:     }
163: 
164:     /**
165:      *
166:      * Set expiration date.
167:      *
168:      * Message expiration date (in unix timestamp) is a date after which message won't be
169:      * delivered if it wasn't delivered yet. The difference between date sent and expiration
170:      * date can't be less than 1 hour and more than 12 hours. Time will be set with
171:      * tolerance +/- 5 minutes.
172:      *
173:      * @param int $date in timestamp
174:      * @return $this
175:      */
176:     public function setDateExpire( $date ) {
177:         $this->params[ "expiration_date" ] = $date;
178:         return $this;
179:     }
180: 
181:     /**
182:      * Set name of the sender.
183:      *
184:      * To send SMS as ECO use sender name `ECO`.
185:      * To send SMS as 2Way use sender name `2Way`.
186:      *
187:      * Only verified names are being accepted.
188:      *
189:      * @param string $sender sender name or eco or 2way
190:      * @return $this
191:      */
192:     public function setSender( $sender ) {
193:         $this->params[ "from" ] = $sender;
194:         return $this;
195:     }
196: 
197:     /**
198:      * Set protection from send multipart messages.
199:      *
200:      * If the message will contain more than 160 chars (single message) it won't be
201:      * sent and return error
202:      *
203:      * @param bool $single
204:      * @return $this
205:      */
206:     public function setSingle( $single ) {
207:         if ( $single == true ) {
208:             $this->params[ "single" ] = "1";
209:         } else if ( $single == false ) {
210:             $this->params[ "single" ] = "0";
211:         }
212: 
213:         return $this;
214:     }
215: 
216:     /**
217:      * Set protection from sending messages containing special characters.
218:      *
219:      * @param bool $noUnicode if true turn on protection
220:      * @return $this
221:      */
222:     public function setNoUnicode( $noUnicode ) {
223:         if ( $noUnicode == true ) {
224:             $this->params[ "nounicode" ] = "1";
225:         } else if ( $noUnicode == false ) {
226:             $this->params[ "nounicode" ] = "0";
227:         }
228: 
229:         return $this;
230:     }
231: 
232:     /**
233:      * Set SMS message data coding.
234:      *
235:      * This parameter allows to send WAP PUSH messages.
236:      *
237:      * Example: bin
238:      *
239:      * @param string $dataCoding
240:      * @return $this
241:      */
242:     public function setDataCoding( $dataCoding ) {
243:         $this->params[ "datacoding" ] = $dataCoding;
244:         return $this;
245:     }
246: 
247:     /**
248:      * Set SMS message in flash mode.
249:      *
250:      * Flash SMS are automatically presented on the mobile screen and
251:      * have to be saved to be default stored in inbox.
252:      *
253:      * @param bool $flash
254:      * @return $this
255:      */
256:     public function setFlash( $flash ) {
257:         if ( $flash == true ) {
258:             $this->params[ "flash" ] = "1";
259:         } else if ( $flash == false && isset( $this->params[ "flash" ] ) ) {
260:             unset( $this->params[ "flash" ] );
261:         }
262: 
263:         return $this;
264:     }
265: 
266:     /**
267:      * Set normalize SMS text.
268:      *
269:      * Removing dialectic characters from message.
270:      *
271:      * @param bool $normalize
272:      * @return $this
273:      */
274:     public function setNormalize( $normalize ) {
275: 
276:         if ( $normalize == true ) {
277:             $this->params[ "normalize" ] = "1";
278:         } else if ( $normalize == false && isset( $this->params[ "normalize" ] ) ) {
279:             unset( $this->params[ "normalize" ] );
280:         }
281: 
282:         return $this;
283:     }
284: 
285:     /**
286:      * Set higher priority of sending message.
287:      * Prohibited for bulk messages.
288:      *
289:      * @param bool $fast if true set higher priority otherwise normal priority
290:      * @return $this
291:      */
292:     public function setFast( $fast ) {
293:         if ( $fast == true ) {
294:             $this->params[ "fast" ] = "1";
295:         } else if ( $fast == false && isset( $this->params[ "fast" ] ) ) {
296:             unset( $this->params[ "fast" ] );
297:         }
298: 
299:         return $this;
300:     }
301: 
302:     /**
303:      * Set personalized parameters to bulk messages.
304:      *
305:      * @param int $i
306:      * @param string|string[] $text
307:      * @return $this
308:      * @throws \OutOfRangeException
309:      */
310:     public function SetParam($i, $text) {
311: 
312:         if ( $i > 3 || $i < 0 ) {
313:             throw new \OutOfRangeException;
314:         }
315: 
316:         $value = is_array($text) ? implode('|', $text) : $text;
317:         $this->params['param'.($i+1)] = urlencode( $value );
318: 
319:         return $this;
320:     }
321: 
322:     /**
323:      * Set template
324:      * @param $name
325:      * @return $this
326:      */
327:     public function setTemplate($name)
328:     {
329:         $this->params['template'] = urlencode($name);
330: 
331:         return $this;
332:     }
333: }
334: 
SMSAPI Api Client API documentation generated by ApiGen