Advertisement
wzul

mastamobileapi.php

Jan 8th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <?php
  2.  
  3. define("APIURL", 'https://mastamobile.com/autosms/sendAPI.php?');
  4.  
  5. class MastaMobile {
  6.  
  7.     var $array;
  8.  
  9.     function __construct() {
  10.         $this->array = array();
  11.         return $this;
  12.     }
  13.  
  14.     public function setDeviceID($deviceID) {
  15.         $this->array['deviceId'] = $deviceID;
  16.         return $this;
  17.     }
  18.  
  19.     public function setToPhone($toPhone) {
  20.         $this->array['toPhone'] = $toPhone;
  21.         return $this;
  22.     }
  23.  
  24.     public function setMessage($message) {
  25.         $this->array['message'] = $message;
  26.         return $this;
  27.     }
  28.  
  29.     public function process($deviceID = '', $toPhone = '', $message = '') {
  30.         if (!empty($deviceID) && !empty($toPhone) && !empty($message)) {
  31.             $this->array['deviceId'] = $deviceID;
  32.             $this->array['toPhone'] = $toPhone;
  33.             $this->array['message'] = $message;
  34.         }
  35.  
  36.         // Only compatible with WordPress. Else, return false
  37.         if (function_exists('wp_safe_remote_post')) {
  38.             // Send this payload to MastaMobile for processing
  39.             $response = wp_safe_remote_post(APIURL, $this->prepareMM($this->array));
  40.             $status = json_decode(wp_remote_retrieve_body($response), true);
  41.             if ($status['status'] == 'success') {
  42.                 return true;
  43.             } else {
  44.                 return false;
  45.             }
  46.         } else {
  47.             return false;
  48.         }
  49.     }
  50.  
  51.     private function prepareMM($data) {
  52.         $args = array();
  53.         $args['method'] = 'POST';
  54.         $args['body'] = http_build_query($data);
  55.         return $args;
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement