Хелп над проверить api example.php
[PHP]<?php
include_once('class.BulkSms.php');
$bulkSms = new BulkSms( 'user', 'user', '351' );
if( $bulkSms->sendSms("test message", "961234567") ){
echo "Message Sent: <br>
Status Code: ".$bulkSms->status_code ." <br>
Status Description: ".$bulkSms->status_description."<br><br>";
}
else{
echo "Error Sending Message: <br>
Status Code: ".$bulkSms->status_code ." <br>
Status Description: ".$bulkSms->status_description."<br><br>";
}
echo "Credits Remaining: ".$bulkSms->getCredits();
?>[/PHP]
bulksms_api_2.php
[PHP]<?php
/************************************************************\
*
* BulkSms version 0.9, modified 11-Dez-08
* By Nuno Chaves
* nunochave@sapo.pt
*
* Class for sending messages from
http://bulksms.vsms.net/ * uses bulksms Version 2.0 API reference.
*
/************************************************************\
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software
* Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*/
class BulkSms{
private $host;
private $user;
private $pass;
private $countryCode;
private $port;
public $status_code;
public $status_description;
public $smsQuote;
function BulkSms( $user, $pass, $countryCode='351', $host='bulksms.vsms.net', $port='5567' ){
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->countryCode = $countryCode;
$this->port = $port;
}
/*
* $msg - message to send
* $mobilePhone - destination phone without the international code
* $quote - if true stores sms send cost in credits on class public var smsQuote
*
* the message is encoded with urlencode to be sent. see
http://en.wikipedia.org/wiki/Short_message_service#GSM for chars supported.
*
* send URL =>
http://bulksms.vsms.net:5567/eapi/submissi...sdn=12345678901 *
* ERROR CODES
* 0: In progress (a normal message submission, with no error encountered so far).
* 1: Scheduled.
* 22: Internal fatal error
* 23: Authentication failure
* 24: Data validation failed
* 25: You do not have sufficient credits
* 26: Upstream credits not available
* 27: You have exceeded your daily quota
* 28: Upstream quota exceeded
* 40: Temporarily unavailable
*
* */
function sendSms( $msg, $mobilePhone, $quote=false ){
$this->status_code = 0;
$this->smsQuote = 0;
$this->status_description = "";
$ch = curl_init();
if( !$quote )
curl_setopt($ch, CURLOPT_URL, 'http://'.$this->host.':'.$this->port.'/eapi/submission/send_sms/2/2.0');
else curl_setopt($ch, CURLOPT_URL, 'http://'.$this->host.':'.$this->port.'/eapi/submission/quote_sms/2/2.0');
curl_setopt ($ch, CURLOPT_POST, 1);
$post_fields = 'username='.$this->user.'&password='.$this->pass.'&message='.urlencode($msg).'&msisdn='.$this->countryCode.$mobilePhone;
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response_string = curl_exec($ch);
curl_close($ch);
$arrResponse = explode('|',$response_string);
if( !$quote ){
$this->status_code = $arrResponse[0];
$this->status_description = $arrResponse[1];
}
else{
$this->status_code = $arrResponse[0];
$this->smsQuote = $arrResponse[2];
}
if( $this->status_code == 0 ) return true;
else return false;
}
// returns float value with sms send cost in credits
function getSmsQuote( $msg, $mobilePhone ){
if( $this->sendSms( $msg, $mobilePhone, true ) )
return $this->smsQuote;
else return 0;
}
function getCredits(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://'.$this->host.':'.$this->port.'/eapi/user/get_credits/1/1.1');
curl_setopt ($ch, CURLOPT_POST, 1);
$post_fields = 'username='.$this->user.'&password='.$this->pass;
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response_string = curl_exec($ch);
curl_close($ch);
$arrResponse = explode('|',$response_string);
if( $arrResponse[0] == 0 ) return $arrResponse[1];
else return -1;
}
}
?>[/PHP]