PHP code example of ghasedaksms / php
1. Go to this page and download the library: Download ghasedaksms/php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ghasedaksms / php example snippets
$ghasedaksms = new GhasedaksmsApi('your_api_key');
$sendDate = new DateTimeImmutable('now');
$lineNumber = '3000****';
$receptor = '0912*******';
$message = 'test';
try {
$response = $ghasedaksms->sendSingle(new SingleMessageDTO(
sendDate: $sendDate,
lineNumber: $lineNumber,
receptor: $receptor,
message: $message
));
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
$sendDate = new DateTimeImmutable('now');
$lineNumber = '3000****';
$receptor = ['0912*******','0919*******'];
$message = 'test';
try {
$response = $ghasedaksms->sendBulk(new BulkMessageDTO(
sendDate: $sendDate,
lineNumber: $lineNumber,
receptors: $receptor,
message: $message
));
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
$sendDate = new DateTimeImmutable('now');
$lineNumber = '3000****';
$receptor1 = '0912*******';
$receptor2 = '0912*******';
$message1 = 'test1';
$message2 = 'test2';
try {
$response = $ghasedaksms->sendPairToPair(new PairToPairMessageDTO(
[
new SingleMessageDTO(
sendDate: $sendDate,
lineNumber: $lineNumber,
receptor: $receptor1,
message: $message1
),
new SingleMessageDTO(
sendDate: $sendDate,
lineNumber: $lineNumber,
receptor: $receptor2,
message: $message2
)
]
));
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
$sendDate = new DateTimeImmutable('now');
try {
$response = $ghasedaksms->sendOtp(new OtpMessageDTO(
sendDate: $sendDate,
receptors: [
new ReceptorDTO(
mobile: '0912*******',
clientReferenceId: '1'
)
],
templateName: 'newOtp',
inputs: [
new InputDTO(
param: 'Code',
value: 'value'
),
new InputDTO(
param: 'Name',
value: 'value'
)
]
));
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
$sendDate = new DateTimeImmutable('now');
try {
$response = $ghasedaksms->sendOtpWithParams(new OtpMessageWithParamsDTO(
sendDate: $sendDate,
receptors: [
new ReceptorDTO(
mobile: '0912*******',
clientReferenceId: '1'
)
],
templateName: 'newOtp',
param1: 'param1',
param2: 'param2'
));
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
try {
$response = $ghasedaksms->checkSmsStatus(new CheckSmsStatusDTO(
ids: ['246*****'],
type: 1
));
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
try {
$response = $ghasedaksms->getAccountInformation();
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
try {
$response = $ghasedaksms->getReceivedSMSes(
new GetReceivedSMSesDTO(
lineNumber: '3000****'
)
);
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
$startDate = new DateTimeImmutable('now');
$endDate = $startDate->modify('+3 days');
try {
$response = $ghasedaksms->getReceivedSMSesPaging(
new GetReceivedSMSesPagingDTO(
lineNumber: '3000****',
startDate: $startDate,
endDate: $endDate,
pageIndex: 0,
pageSize: 10
)
);
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}
try {
$response = $ghasedaksms->getOtpTemplateParameters(
new GetOtpTemplateParametersDTO(
templateName: 'newOtp'
)
);
var_dump($response);
} catch (Exceptions\GhasedakSMSException $e) {
var_dump($e->getMessage());
}