Overview

Namespaces

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

Classes

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