Ejemplo n.º 1
0
 /**
  * Send a text message as SMS to Clicksend.com's queue, to have it sent to
  * the specified telephone number. On success the SMS is saved.
  * @param int|string $senderId
  * @param int|string $recipientId
  * @param string $recipientTelephoneNumber
  * @param string $message
  * @return string
  */
 public function send_SMS($senderId, $recipientId, $recipientTelephoneNumber, $message)
 {
     $recipientTelephoneNumber = '+61411111111';
     // Testing telephone number.
     $cSMS = curl_init('https://api.clicksend.com/rest/v2/send.json');
     curl_setopt($cSMS, CURLOPT_POST, TRUE);
     curl_setopt($cSMS, CURLOPT_USERPWD, 'stoykovnet:4558458E-4FDF-B6A1-DF57-F5F9BE1BD0F3');
     curl_setopt($cSMS, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($cSMS, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($cSMS, CURLOPT_POSTFIELDS, "&to={$recipientTelephoneNumber}" . "&message={$message}" . '&method=rest');
     $response = json_decode(curl_exec($cSMS));
     if ($response->recipientcount > 0) {
         $sctr = new SMS_Controller();
         $sctr->save_SMS($senderId, $recipientId, array('message' => $message, 'timestamp' => time()));
     }
     return $response->recipientcount;
 }
 /**
  * Process the following URI:
  * /api/v1/sms/ - to save an SMS.
  * 
  * When an SMS is saved a delivery confirmation SMS is sent back to sender.
  * @return mixed
  */
 private function process_sms_post()
 {
     // Convert sent post data to an array.
     $smsData = array();
     parse_str($this->file, $smsData);
     // Verify there is actually any content in the post data.
     if (isset($smsData['from']) && $smsData['from'] !== '' && isset($smsData['to']) && $smsData['to'] !== '' && isset($smsData['message']) && $smsData['message'] !== '' && isset($smsData['timestamp']) && $smsData['timestamp'] !== '') {
         // The sender and the recipient must be validated first.
         $smsUserCtr = new SMSUser_Controller();
         $sender = $smsUserCtr->get_smsuser_by_telephone($smsData['from']);
         $recipient = $smsUserCtr->get_smsuser_by_telephone($smsData['to']);
         if ($sender && $recipient) {
             // Save SMS if they're successfully validated.
             $sctr = new SMS_Controller();
             if ($sctr->save_SMS($sender->id, $recipient->id, $smsData)) {
                 // The SMS is received. Inform sender.
                 $cSend = new ClickSend_API();
                 return $cSend->send_delivery_confirmation($recipient->id, $sender->id, $sender->telephone);
             }
         }
     }
     return null;
 }