to send SMS Reports from Piwik.
About ASPSMS.com:
- ASPSMS provides fast and reliable high quality worldwide SMS delivery, over 900 networks in every corner of the globe.
- Cost per SMS message depends on the target country and starts from ~0.06USD (0.04EUR).
- Most countries and networks are supported but we suggest you check the latest position on their supported networks list here.
- For sending an SMS, you need so-called ASPSMS credits, which are purchased in advance. The ASPSMS credits do not expire.
- Payment by bank transfer, various credit cards such as Eurocard/Mastercard, Visa, American Express or Diners Club, PayPal or Swiss Postcard.
';
}
public function getCredentialFields()
{
return array(
array(
'type' => 'text',
'name' => 'username',
'title' => 'MobileMessaging_UserKey'
),
array(
'type' => 'text',
'name' => 'password',
'title' => 'General_Password'
),
);
}
public function verifyCredential($credentials)
{
$this->getCreditLeft($credentials);
return true;
}
public function sendSMS($credentials, $smsText, $phoneNumber, $from)
{
$from = substr($from, 0, self::MAXIMUM_FROM_LENGTH);
$smsText = self::truncate($smsText, self::MAXIMUM_CONCATENATED_SMS);
$additionalParameters = array(
'Recipients' => array($phoneNumber),
'MessageText' => $smsText,
'Originator' => $from,
'AffiliateID' => '227830',
);
$this->issueApiCall(
$credentials,
self::SEND_SMS_RESOURCE,
$additionalParameters
);
}
private function issueApiCall($credentials, $resource, $additionalParameters = array())
{
$accountParameters = array(
'UserName' => $credentials['username'],
'Password' => $credentials['password'],
);
$parameters = array_merge($accountParameters, $additionalParameters);
$url = self::BASE_API_URL
. $resource;
$timeout = self::SOCKET_TIMEOUT;
try {
$result = Http::sendHttpRequestBy(
Http::getTransportMethod(),
$url,
$timeout,
$userAgent = null,
$destinationPath = null,
$file = null,
$followDepth = 0,
$acceptLanguage = false,
$acceptInvalidSslCertificate = true,
$byteRange = false,
$getExtendedInfo = false,
$httpMethod = 'POST',
$httpUserName = null,
$httpPassword = null,
$requestBody = json_encode($parameters)
);
} catch (Exception $e) {
throw new APIException($e->getMessage());
}
$result = @json_decode($result, true);
if (!$result || $result['StatusCode'] != 1) {
throw new APIException(
'ASPSMS API returned the following error message : ' . $result['StatusInfo']
);
}
return $result;
}
public function getCreditLeft($credentials)
{
$credits = $this->issueApiCall(
$credentials,
self::CHECK_CREDIT_RESOURCE
);
return Piwik::translate('MobileMessaging_Available_Credits', array($credits['Credits']));
}
}