to send SMS Reports from Piwik.
About Clockwork:
- Clockwork gives you fast, reliable high quality worldwide SMS delivery, over 450 networks in every corner of the globe.
- Cost per SMS message is around ~0.08USD (0.06EUR).
- Most countries and networks are supported but we suggest you check the latest position on their coverage map here.
';
}
public function verifyCredential($apiKey)
{
$this->getCreditLeft($apiKey);
return true;
}
public function sendSMS($apiKey, $smsText, $phoneNumber, $from)
{
$from = substr($from, 0, self::MAXIMUM_FROM_LENGTH);
$smsText = self::truncate($smsText, self::MAXIMUM_CONCATENATED_SMS);
$additionalParameters = array(
'To' => str_replace('+', '', $phoneNumber),
'Content' => $smsText,
'From' => $from,
'Long' => 1,
'MsgType' => self::containsUCS2Characters($smsText) ? 'UCS2' : 'TEXT',
);
$this->issueApiCall(
$apiKey,
self::SEND_SMS_RESOURCE,
$additionalParameters
);
}
private function issueApiCall($apiKey, $resource, $additionalParameters = array())
{
$accountParameters = array(
'Key' => $apiKey,
);
$parameters = array_merge($accountParameters, $additionalParameters);
$url = self::BASE_API_URL
. $resource
. '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
try {
$result = Http::sendHttpRequestBy(
Http::getTransportMethod(),
$url,
$timeout,
$userAgent = null,
$destinationPath = null,
$file = null,
$followDepth = 0,
$acceptLanguage = false,
$acceptInvalidSslCertificate = true
);
} catch (Exception $e) {
$result = self::ERROR_STRING . " " . $e->getMessage();
}
if (strpos($result, self::ERROR_STRING) !== false) {
throw new APIException(
'Clockwork API returned the following error message : ' . $result
);
}
return $result;
}
public function getCreditLeft($apiKey)
{
return $this->issueApiCall(
$apiKey,
self::CHECK_CREDIT_RESOURCE
);
}
}