Tutorials
SENDING SMS
This method provides a way to send the message (SMS) via XML using account details.
These are the standard request parameters that are needed when using the EgoSms XML Api
Contains the user information.
Contains the message information.
The account username.
The account password.
The phone number the message is being sent to.
This represents the message you are sending out. The message source must have a maximum of 160 characters.
This represents who the message is coming from. Sender can have a maximum of 11 characters.
SendSms
Egotest
xxxxx
256788200915
welcome to Egosms
Egosms
SendSms
Egotest
xxxxx
256788200915
First message
test
256788200915
Second message
test
256707811116
Third message
test
256702662127
Forth message
test
OK
---
---
Failed
---
Occurs when there is a syntax error in your XML code.
Occurs if there are insuffient funds of your Egosms Account.
Occurs if either your username or password is wrong.
Occurs if the account being used does not exist or is inactive
Occurs if either the password or username is empty.
SendSms
Egotest
xxxxx
256702662127
test mtn
test
';
//use curl to post the xml information
$ch = curl_init('https://www.egosms.co/api/v1/xml/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml'
));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
curl_close($ch);
echo $ch_result;
?>
/**
* Java API for Egosms Balance inquiry using JSON
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
public class CheckBalanceJSON {
public static void main(String args[]) {
try {
/**
* Egosms url for Balance inquiry using JSON
*/
URL url = new URL("https://www.egosms.co/api/v1/json/");
/**
* Opening the connection to the egosms JSON url
*/
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection) con;
/**
* Setting the request method to POST
*/
http.setRequestMethod("POST");
http.setDoOutput(true);
/**
* User name and password for a registered Egosms user
*/
String username = "Egosmstest";
String password = "egotest";
/**
* Passing the method(Balance), username and password in JSON format The method,
* username and password are appended to the url as parameters when sending the
* data
*/
byte[] out = ("{\"method\":\"Balance\"," + "\"userdata\":" + "{" + "\"username\":\"" + username + "\","
+ "\"password\":\"" + password + "\"" + "}" + "}").getBytes(StandardCharsets.UTF_8);
int length = out.length;
//For Testing purposes
String outString = new String(out);
System.out.println("Content to send : " + outString);
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
http.connect();
try (OutputStream os = http.getOutputStream()) {
os.write(out);
}
/**
* Setting the input stream to read the response data
*/
BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));
String line = null;
/**
* Printing the response data
*/
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Tutorials
SENDING SMS