Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.23 KB | None | 0 0
  1. ######################### FOR SENDING SMS ###########################
  2.                             $json_url = "http://api.ebulksms.com:8080/sendsms.json";
  3.                             $username = 'martafricanaltd@gmail.com';
  4.                             $apikey = '2bc9a4c7e451cb0529e1a31779e1a99c553f3017';
  5.                             $sendername = "MartAfrican";
  6.                             $recipients = "+96171238330";    
  7.                             $flash = 0;
  8.                             $messagetext = "Hi, is enquiring about your product on martafricana";
  9.  
  10.  
  11.                             $gsm = array();    
  12.                             $country_code = '961';    
  13.                             $arr_recipient = explode(',', $recipients);    
  14.                             foreach ($arr_recipient as $recipient) {        
  15.                                 $mobilenumber = trim($recipient);        
  16.                                 if (substr($mobilenumber, 0, 1) == '0'){            
  17.                                     $mobilenumber = $country_code . substr($mobilenumber, 1);        
  18.                                 }        
  19.                                 elseif (substr($mobilenumber, 0, 1) == '+'){            
  20.                                     $mobilenumber = substr($mobilenumber, 1);        
  21.                                 }        
  22.                                 $generated_id = uniqid('int_', false);        
  23.                                 $generated_id = substr($generated_id, 0, 30);        
  24.                                 $gsm['gsm'][] = array('msidn' => $mobilenumber, 'msgid' => $generated_id);    
  25.                             }    
  26.                             $message = array(
  27.                                 'sender' => $sendername,        
  28.                                 'messagetext' => $messagetext,        
  29.                                 'flash' => "{$flash}",    
  30.                             );
  31.                        
  32.                             $request = array( 'SMS' => array(            
  33.                                 'auth' => array(                
  34.                                     'username' => $username,                
  35.                                     'apikey' => $apikey            
  36.                                 ),            
  37.                                 'message' => $message,            
  38.                                 'recipients' => $gsm    
  39.                             ));    
  40.  
  41.                             $json_data = json_encode($request);    
  42.                             if ($json_data) {      
  43.                                
  44.                                 if (is_array($json_data)) {        
  45.                                     $json_data = http_build_query($json_data, '', '&');    
  46.                                 }  
  47.  
  48.                                 $params = array('http' => array(            
  49.                                     'method' => 'POST',            
  50.                                     'content' => $json_data)    
  51.                                 );
  52.  
  53.                                 $headers = array('Content-Type: application/json');
  54.                                 if ($headers !== null) {        
  55.                                     $params['http']['header'] = $headers;    
  56.                                 }
  57.                                 $ctx = stream_context_create($params);    
  58.                                 $fp = fopen($json_url, 'rb', false, $ctx);    
  59.                                
  60.                                 echo "<script type='text/javascript'>alert('$params');</script>";
  61.                                 echo "<script type='text/javascript'>alert('$ctx');</script>";
  62.                                
  63.                                 echo "<script type='text/javascript'>alert('$fp');</script>";    
  64.                                
  65.                                
  66.  
  67.                                
  68.                                 if (!$fp) {        
  69.                                     //return "Error: gateway is inaccessible";  
  70.                                     echo "<script type='text/javascript'>alert('gateway inaccessible');</script>";
  71.                                 }
  72.                                 else {
  73.                                     try {        
  74.                                         $response = stream_get_contents($fp);      
  75.                                         $result = json_decode($response);
  76.                                         echo "<script type='text/javascript'>alert('$response');</script>";    
  77.                                     }
  78.                                     catch (Exception $e) {        
  79.                                         $response = $e->getMessage();        
  80.                                         echo "<script type='text/javascript'>alert('$response');</script>";    
  81.                                     }
  82.                                 }
  83.                             }
  84.                             ############ END FOR SENDING SMS ###############
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement