Skip to content

Instantly share code, notes, and snippets.

@riza
Last active January 31, 2018 19:28
Show Gist options
  • Save riza/3e6ef3b8631074522dfd3454ec5803ed to your computer and use it in GitHub Desktop.
Save riza/3e6ef3b8631074522dfd3454ec5803ed to your computer and use it in GitHub Desktop.
IletisimMakinasi icin SMS Sınıfı
<?php
class SMS {
private $api = "https://live.iletisimmakinesi.com/api/";
private $userName = "";
private $userPass = "";
private $customerCode = "";
private $apiKey = "";
private $vendorCode = "";
private $authToken;
private $originatorId = "";
function __construct() {
$this->getAuthToken();
}
private function getAuthToken() {
$fields = [
"userName" => $this->userName,
"userPass" => $this->userPass,
"customerCode" => $this->customerCode,
"apiKey" => $this->apiKey,
"vendorCode" => $this->vendorCode
];
$response = $this->doRequest("UserGatewayWS/functions/authenticate",$fields);
$response = simplexml_load_string($response) or die("Error: Cannot create object");
if($response->STATUS->NAME == "NO_ERROR")
{
$this->authToken = $response->CONTENT->AUTHORIZATION_WITH_TOKEN->TOKEN_NO;
return $this->authToken;
}
return false;
}
private function doRequest($url,$fields) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->api.$url."?".http_build_query($fields),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return "cURL Error #:" . $err;
} else {
return $response;
}
}
public function send($field) {
$fields = [
"token" => trim($this->authToken),
"phoneNumbers" => json_encode(array($field["phoneNumber"])),
"templateText" => $field["smsBody"],
"originatorId" => $this->originatorId,
"isUTF8Allowed" => $field["utf8"],
"validityPeriod" => $field["validityPeriod"],
"usingIvtboxOptoutSMS" => $field["usingIvtboxOptoutSMS"]
];
$response = $this->doRequest("SMSGatewayWS/functions/sendSMS",$fields);
}
}
// $sms = new SMS();
// $sms->send([
// "phoneNumber" => "554xxxxxxx",
// "smsBody" => "deneme",
// "utf8" => "true",
// "validityPeriod" => 60,
// "usingIvtboxOptoutSMS" => "false"
// ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment