Time for Action: Integrating with Clickatell to Send
SMS Notifications
1. The first step in Clickatell integration is to authenticate and get a session ID.
We can use this session ID in all further requests. Let us start our SMSGateway
class with some basic variables and initialization functions.
class SMSGateway
{
private $apiURL;
private $apiId;
private $sessionId;
public $lastCommand;
public $lastResult;
public function __construct()
{
$this->apiURL = "http://api.clickatell.com/http/";
}
??? ??? ??? ???
Chapter 6
[ 105 ]
public function Init($username, $password, $apiId)
{
$this->apiId = $apiId;
$params['user'] = $username;
$params['password'] = $password;
$params['api_id'] = $this->apiId;
$command = 'auth';
if ($this->Request($command, $params))
{
return true;
}
}
}
?>
2. The request function takes the name of the command and an array of
parameters to pass. We will make a HTTP GET request to the Clickatell API
URL and process the response string. The basic pattern of the response string
is two parts separated by a colon. The first part is the status code and the
second part is the value. So for authentication, we will get "OK: Session ID".
Pages:
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148