Overview

Namespaces

  • None
  • PHP
  • tschiemer
    • Aspsms
      • Http
      • Soap
      • Xml

Classes

  • AbstractClient
  • AbstractSimpleClient
  • Request
  • Response
  • SimpleClient
  • Strings

Exceptions

  • ServiceException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace tschiemer\Aspsms;
  4: 
  5: /**
  6:  * Shared request object used for request abstraction.
  7:  * 
  8:  * @version 1.1.0
  9:  * @package aspsms
 10:  * @license LGPL v3 http://www.gnu.org/licenses/lgpl-3.0.txt 
 11:  * @copyright 2013 Philip Tschiemer, <tschiemer@filou.se>
 12:  * @link https://github.com/tschiemer/aspsms-php
 13:  */
 14: class Request
 15: {   
 16:     /**
 17:      * Request name
 18:      * @var string
 19:      */
 20:     var $requestName = NULL;
 21:     
 22:     /**
 23:      * @var array
 24:      */
 25:     var $fields = array();
 26:     
 27:     public function __construct($data = array())
 28:     {
 29:         foreach($data as $k => $v)
 30:         {
 31:             $this->set($k, $v);
 32:         }
 33:     }
 34:     
 35:     public function setRequestName($name)
 36:     {
 37: //        if ( ! in_array($name, array(
 38: //            'getVersion',
 39: //            'getCredits',
 40: //            'getStatusCodeDescription',
 41: //
 42: //            'sendText',
 43: //            'sendWapPush',
 44: //
 45: //            'sendToken',
 46: //            'verifyToken',
 47: //
 48: //            'getDeliveryStatus',
 49: //
 50: //            'checkOriginator',
 51: //            'sendOriginatorCode',
 52: //            'unlockOriginator',
 53: //
 54: //            'sendPicture',
 55: //            'sendLogo',
 56: //            'sendGroupLogo',
 57: //            'sendRingtone',
 58: //            'sendVCard',
 59: //            'sendBinaryData'
 60: //        )))
 61: //        
 62:         $this->requestName = $name;
 63:     }
 64:     
 65:     /**
 66:      * Getter
 67:      * @return string
 68:      */
 69:     public function getRequestName()
 70:     {
 71:         return $this->requestName;
 72:     }
 73:     
 74:     public function set($key,$value)
 75:     {
 76:         if (method_exists($this, 'set'.$key))
 77:         {
 78:             $this->{'set'.$key}($value);
 79:         }
 80:         else
 81:         {
 82:             $this->fields[$key] = $value;
 83:         }
 84:     }
 85:     
 86:     public function get($key)
 87:     {
 88:         if (isset($this->fields[$key]))
 89:         {
 90:             return $this->fields[$key];
 91:         }
 92:         return NULL;
 93:     }
 94:     
 95:     public function getFieldsAsArray()
 96:     {
 97:         return $this->fields;
 98:     }
 99:     
100:     public function getFieldsAsObject()
101:     {
102:         $obj = new \stdClass();
103:         foreach($this->getFieldsAsArray() as $key => $value)
104:         {
105:             $obj->$key = $value;
106:         }
107:         
108:         return $obj;
109:     }
110:     
111:     public function extractArray($fieldList = array())
112:     {
113:         $filtered = array_intersect_key($this->fields, $fieldList);
114:         
115:         $r = array_merge($fieldList,$filtered);
116:         
117:         return $r;
118:     }
119:     
120:     public function extractObject($fieldList = array())
121:     {
122:         $obj = new \stdClass();
123:         foreach($this->extractArray($fieldList) as $key => $value)
124:         {
125:             $obj->$key = $value;
126:         }
127:         
128:         return $obj;
129:     }
130:     
131:     public function setStatusCode($statusCode)
132:     {
133:         if (is_int($statusCode))
134:         {
135:             $this->fields['StatusCode'] = 'StatusCode:'.$statusCode;
136:         }
137:         else
138:         {
139:             $this->fields['StatusCode'] = $statusCode;
140:         }
141:     }
142:     
143:     public function setTransactionReferenceNumbers($trackingnr)
144:     {
145:         if (is_array($trackingnr))
146:         {
147:             $this->fields['TransactionReferenceNumbers'] = implode(';',$trackingnr);
148:         }
149:         else
150:         {
151:             $this->fields['TransactionReferenceNumbers'] = strval($trackingnr);
152:         }
153:     }
154:     
155:     /**
156:      * Set recipients of message.
157:      * 
158:      * String Format:
159:      *  ("<RECIPIENT_NR>" + {":<TRACKING_NR>"} ";" .. )+ 
160:      * Eg:
161:      *   00417777777
162:      *   00417777777;00417777777;004177777777
163:      *   00417777777:84612004;00417777777:74183874783
164:      * 
165:      * Array Format:
166:      *  <TRACKING_NR> => <RECIPIENT_NR>
167:      * 
168:      * @param string|array $recipients
169:      */
170:     public function setRecipients($recipients)
171:     {
172:         if (is_array($recipients))
173:         {
174:             $tmp = array();
175:             foreach($recipients as $track => $nr)
176:             {
177:                 $tmp[] = $nr.':'.$track;
178:             }
179:             $this->fields['Recipients'] = implode(';',$tmp);
180:         }
181:         else
182:         {
183:             $this->fields['Recipients'] = $recipients;
184: //            if (preg_match_all('/(?:([^;]+):([^;]+);?+)/',$recipients,$m))
185: //            {
186: //                $this->Recipients = $recipients;
187: //            }
188: //            elseif (preg_match_all('/([^;]+);?/',$recipients,$m))
189: //            {
190: ////                $tmp = explode(';',$recipients);
191: ////                $this->setRecipients($tmp);
192: //                $this->Recipients = $recipients;
193: //            }
194:         }
195:     }
196:     
197:     /**
198:      * Sets intended delivery time.
199:      * 
200:      * Formats:
201:      *  string      ddmmyyyyhhmmss
202:      *  int         unit timestamp
203:      *  DateTime    
204:      * 
205:      * @param int|string|\DateTime $datetime
206:      * @see \Aspsms\Request::setTimeZone()
207:      */
208:     public function setDeferredDeliveryTime($datetime)
209:     {
210:         if (is_int($datetime))
211:         {
212:             $this->fields['DeferredDeliveryTime'] = date('dmYHis',$datetime);
213:         }
214:         elseif ($datetime instanceof \DateTime)
215:         {
216:             $this->fields['DeferredDeliveryTime'] = $datetime->format('dmYHis');
217:         }
218:         else
219:         {
220:             $this->fields['DeferredDeliveryTime'] = strval($sec);
221:         }
222:     }
223:     
224:     /**
225:      * @param boolean $flash
226:      */
227:     public function setFlashingSMS($flash)
228:     {
229:         $this->fields['FlashingSMS'] = $flash ? 'True' : '';
230:     }
231:     
232:     /**
233:      * Sets timezone to use when sending a deferred sms
234:      * Offset to GMT
235:      * 
236:      * @see setDeferredDeliveryTime()
237:      * @param int|string|DateTimeZone $timezone
238:      */
239:     public function setTimeZone($timezone)
240:     {
241:         if ($timezone instanceof \DateTimeZone)
242:         {
243:             $this->fields['TimeZone'] = strval($timezone->getOffset());
244:         }
245:         else
246:         {
247:             $this->fields['TimeZone'] = strval(intval($timezone));
248:         }
249:     }
250:     
251:     /**
252:      * Two modes:
253:      *  1. simple:
254:      *      SMS.URLNonDeliveryNotification = "http://www.mysite.com/sms/notdelivered.asp?ID="
255:      *      When the TransactionReferenceNumber is e.g. 3152, the URL will be loaded like this: 
256:      *      http://www.mysite.com/sms/notdelivered.asp?ID=3152
257:      * 
258:      *  2. detailed:
259:      *      http://www.yourhost.com/Delivered.asp?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>
260:      * 
261:      *      <RCPNT> (Recipient, Mobilenumber)
262:      *      <SCTS> (Servicecenter Timestamp, Submissiondate)
263:      *      <DSCTS> (Delivery Servicecenter Timestamp, Notificationdate)
264:      *      <RSN> (Reasoncode)
265:      *      <DST> (Deliverystatus)
266:      *      <TRN> (Transactionreferencenummer)
267:      *
268:      * @param string $url
269:      */
270:     public function setURLDeliveryNotification($url)
271:     {
272:         $this->fields['URLDeliveryNotification'] = strval($url);
273:     }
274:     
275:     /**
276:      * @see setURLDeliveryNotification()
277:      * @param string $url
278:      */
279:     public function setURLNonDeliveryNotification($url)
280:     {
281:         $this->fields['URLNonDeliveryNotification'] = strval($url);
282:     }
283:     
284:     /**
285:      * @see setURLDeliveryNotification()
286:      * @param string $url
287:      */
288:     public function setURLBufferedMessageNotification($url)
289:     {
290:         $this->fields['URLBufferedMessageNotification'] = strval($url);
291:     }
292:     
293:     /**
294:      * Official doc:
295:      * 
296:      * If MessageData is set, the placeholder <VERIFICATIONCODE> will be
297:      * substituted with the verification code. If MessageData is not defined,
298:      * or if MessageData does not contain the placeholder <VERIFICATIONCODE>,
299:      * only the verification code is sent.
300:      * 
301:      * @param string $data
302:      */
303:     public function setMessageData($data)
304:     {
305:         $this->fields['MessageData'] = strval($data);
306:     }
307:     
308:     /**
309:      * Official doc:
310:      * 
311:      * Explicitly specifies the verification code to be sent to the user.
312:      * 
313:      * @param string $ref
314:      */
315:     public function setTokenReference($ref)
316:     {
317:         $this->fields['TokenReference'] = strval($ref);
318:     }
319:     
320:     /**
321:      * Official doc:
322:      * 
323:      * Specifies the validity period of a Token in minutes.
324:      * If not specified, the TokenValidity is 5 minutes by default.
325:      * 
326:      * @param int $minutes
327:      */
328:     public function setTokenValidity($minutes = 5)
329:     {
330:         $this->fields['TokenValidity'] = strval(intval($minutes));
331:     }
332:     
333:     /**
334:      * Official doc:
335:      * 
336:      * Used to have the ASPSMS generate a verification code by mask. The mask can contain the following special characters:
337:      *
338:      *  # : a digit
339:      *  A : an alphabetic character
340:      *  N : an alphanumeric character
341:      *
342:      *  All other characters are taken literally. If not specified, the Mask is "NNNN" by default.
343:      *
344:      * @param string $mask
345:      */
346:     public function setTokenMask($mask)
347:     {
348:         $this->fields['TokenMask'] = strval($mask);
349:     }
350:     
351:     /**
352:      * Official doc:
353:      * 
354:      * Explicitly specifies the verification code to be sent to the user.
355:      * 
356:      * @param string $code
357:      */
358:     public function setVerificationCode($code)
359:     {
360:         $this->fields['VerificationCode'] = strval($code);
361:     }
362:     
363:     
364:     /**
365:      * Official doc:
366:      * 
367:      * Specifies, if the verification code comparison is case sensitive:
368:      *  1 : case sensitive
369:      *  0 : not case sensitive
370:      *  If not specified, TokenCaseSensitive is 0 by default.
371:      *
372:      * @param boolean $is_sensitive
373:      */
374:     public function setTokenCaseSensitive($is_sensitive = FALSE)
375:     {
376:         $this->fields['TokenCaseSensitive'] = $is_sensitive ? '1' : '0';
377:     }
378: }
aspsms-php API documentation generated by ApiGen 2.8.0