Skip to content

Instantly share code, notes, and snippets.

@testman42
Forked from blackbfm-zz/sendfreesms.php
Last active December 19, 2023 07:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save testman42/7604480 to your computer and use it in GitHub Desktop.
Save testman42/7604480 to your computer and use it in GitHub Desktop.
<?php
//=========================================================================
// Skripta za posiljanje sms preko Simobilove Klape / Najdi.si / Tusmobil
// Verzija 2.40 (c) blackclw @ slo-tech
//=========================================================================
// Pošiljanje:
// SendFreeSms("ponudnik", "uporabniskoime", "geslo", "stevilka", "sporocilo")
//
// Preverjanje stanja:
// SendFreeSms("ponudnik", "uporabniskoime", "geslo", "stevilka", "sporocilo", False)
//
// Namesto ponudnika vpišeš "klapa" / "najdi" / "tusmobil". Funkcija ob uspešno poslanem smsu
// vrne število preostalih sporočil ali pa vrže error:
// -1 splošna napaka
// -2 prazno / predolgo sporočilo
// -3 napačna telefonska številka
//=========================================================================
//ini_set('display_errors', 'On');
//error_reporting(E_ALL);
function SendFreeSms($SmsProvider, $SmsUser, $SmsPwd, $SmsNum, $SmsMsg, $Send = True)
{
$ValidNetworks = array("070", "064", "031", "041", "051", "071", "030", "040");
$KlapaMaxLen = 280;
$NajdiMaxLen = 160;
$TusmobilMaxLen = 140;
if (((!is_numeric($SmsNum)) || (strlen($SmsNum) != 9) || (!in_array(substr($SmsNum,0,3), $ValidNetworks))) && ($Send)) {
return -3;
}
$Cookies = "";
$ch = curl_init();
//curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $Cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $Cookies);
if ($SmsProvider == "klapa") {
if (((strlen($SmsMsg) == 0) || (strlen($SmsMsg) >= $KlapaMaxLen)) && ($Send)) {
return -2;
}
try {
curl_setopt($ch, CURLOPT_URL, "http://klapa.simobil.net/klapa/send.php");
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/id=\"__VIEWSTATE\" value=\"(.*)\" \/>/", $response, $parsed_viewstate);
preg_match("/id=\"__EVENTVALIDATION\" value=\"(.*)\" \/>/", $response, $parsed_eventvalidation);
$PostData = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=" . urlencode($parsed_viewstate[1]) .
"&__VIEWSTATEENCRYPTED=&__EVENTVALIDATION=" . urlencode($parsed_eventvalidation[1]) .
"&ctl00%24ContentPlaceHolder%24txtUsername=" . $SmsUser .
"&ctl00%24ContentPlaceHolder%24txtPassword=" . $SmsPwd . "&ctl00%24ContentPlaceHolder%24btnLogin=PRIJAVITE+SE";
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
$lasturl = curl_getinfo($ch);
curl_setopt($ch, CURLOPT_URL, $lasturl['url']);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/name=\"authTicket\" value=\"(.*)\"\/>/", $response, $KlapaAuthTicket);
if (empty($KlapaAuthTicket)) { throw new Exception(); }
curl_setopt($ch, CURLOPT_URL, "http://klapa.simobil.net/klapa/send.php");
$PostData = "authTicket=" . urlencode($KlapaAuthTicket[1]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/Preostalo .*?tevilo sporo.*?il: (\d+)<\/span>/u", $response, $SmsCredit);
$SmsCredit = $SmsCredit[1];
if (!$Send) { return $SmsCredit; }
if ($SmsCredit == 0) { return 0; }
curl_setopt($ch, CURLOPT_URL, "http://klapa.simobil.net/klapa/send_msg.php ");
$PostData = "recipient=&number.1001=386" . substr($SmsNum, 1,8) . "&text=" . urlencode($SmsMsg) . "&js_enabled=true&sendit=true";
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/Preostalo .*?tevilo sporo.*?il: (\d+)<\/span>/u", $response, $SmsCredit);
curl_close($ch);
return $SmsCredit[1];
} catch (Exception $e) {
return -1;
}
}
elseif ($SmsProvider == "najdi") {
if (((strlen($SmsMsg) == 0) || (strlen($SmsMsg) >= $NajdiMaxLen)) && ($Send)) {
return -2;
}
try {
curl_setopt($ch, CURLOPT_URL, "https://id.najdi.si/j_spring_security_check");
curl_setopt($ch, CURLOPT_POST, true);
$PostData = "j_username=" . $SmsUser . "&j_password=" . $SmsPwd;
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
curl_setopt($ch, CURLOPT_URL, "http://www.najdi.si/auth/login.jsp?sms=1&target_url=http%3A%2F%2Fwww.najdi.si%2Findex.jsp");
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/(\d+) \/ \d+</", $response, $SmsCredit);
preg_match("/\d+ \/ (\d+)</", $response, $SmsCreditMax);
if (empty($SmsCredit)) { throw new Exception(); }
$SmsCredit = $SmsCredit[1];
$SmsCreditMax = $SmsCreditMax[1];
$SmsCredit = $SmsCreditMax - $SmsCredit;
if (!$Send) { return $SmsCredit; }
if ($SmsCredit == 0) { return 0; }
preg_match("/sms_message_(\d+)/", $response, $NajdiSmsID);
$NajdiSmsID = $NajdiSmsID[1];
$SendMsgUrl = "http://www.najdi.si/sms/smsController.jsp?sms_action=4&sms_so_ac_" . $NajdiSmsID . "=" . substr($SmsNum, 1, 2) .
"&sms_so_l_" . $NajdiSmsID . "=" . urlencode(substr($SmsNum, 3, 3) . " " . substr($SmsNum, 6, 3) ) . "&myContacts=&sms_message_" .
$NajdiSmsID . "=" . urlencode($SmsMsg);
curl_setopt($ch, CURLOPT_URL, $SendMsgUrl);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/\"msg_left\":(\d+)/", $response, $SmsCredit);
curl_close($ch);
return $SmsCredit[1];
} catch (Exception $e) {
return -1;
}
}
elseif ($SmsProvider == "tusmobil") {
if (((strlen($SmsMsg) == 0) || (strlen($SmsMsg) >= $TusmobilMaxLen)) && ($Send)) {
return -2;
}
try {
if (!is_dir("tusmobil_session")) { mkdir("tusmobil_session"); }
$CookiesFile = dirname(__FILE__) . "/tusmobil_session/" . md5($SmsUser);
curl_setopt($ch, CURLOPT_COOKIEFILE, $CookiesFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $CookiesFile);
function FBGetSignedRequest(&$ch) {
curl_setopt($ch, CURLOPT_URL, "https://www.facebook.com/pages/Tu%C5%A1mobil-doo/183068912838?sk=app_142611112521439");
$response = curl_exec($ch);
preg_match("/signedRequest\":\"(.*?)\"}/", $response, $AppSignedRequest);
if (empty($AppSignedRequest)) { return -1; }
if (strpos($response, "login_form") !== False) { return -1; }
$AppSignedRequest = $AppSignedRequest[1];
return $AppSignedRequest;
}
$AppSignedRequest = FBGetSignedRequest($ch);
if ($AppSignedRequest == -1) {
curl_setopt($ch, CURLOPT_URL, "https://www.facebook.com");
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
curl_setopt($ch, CURLOPT_URL, "https://www.facebook.com/login.php?login_attempt=1");
curl_setopt($ch, CURLOPT_POST, true);
$PostData = "email=" . urlencode($SmsUser) . "&pass=" . urlencode($SmsPwd) . "&persistent=1";
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
$AppSignedRequest = FBGetSignedRequest($ch);
}
curl_setopt($ch, CURLOPT_URL, "https://moj.tusmobil.si/fbsms/index.php");
curl_setopt($ch, CURLOPT_POST, true);
$PostData = "signed_request=" . $AppSignedRequest;
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/danes .*?e (\d+) od \d+ sporo.*?il/", $response, $SmsCredit);
if (empty($SmsCredit)) { throw new Exception(); }
$SmsCredit = $SmsCredit[1];
if (!$Send) { return $SmsCredit; }
if ($SmsCredit == 0) { return 0; }
curl_setopt($ch, CURLOPT_URL, "https://moj.tusmobil.si/fbsms/message.php");
curl_setopt($ch, CURLOPT_POST, true);
$PostData = "prefix=" . substr($SmsNum, 1, 2) . "&number=" . urlencode(substr($SmsNum, 3, 3) . " " . substr($SmsNum, 6, 3) ) .
"&message=" . urlencode($SmsMsg). "&signed_request=" . $AppSignedRequest;
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
$response = curl_exec($ch);
if (curl_errno($ch) != 0) { throw new Exception(); }
preg_match("/danes .*?e (\d+) od \d+ sporo.*?il/", $response, $SmsCredit);
$SmsCredit = $SmsCredit[1];
return $SmsCredit;
} catch (Exception $e) {
return -1;
}
}
curl_close($ch);
};
$user = $_POST["user"];
$pass = $_POST["pass"];
$sporocilo1 = $_POST["msg"];
$sporocilo = str_replace(str_split("šč枊ČĆŽ"), str_split("scczSCCZ"), $sporocilo1);
$stevilke = explode( "," , $_POST["phone"] );
foreach ($stevilke as $i) {
$num1 = str_replace(" ", "", $i);
$num = trim($num1);
$output1 = SendFreeSms("najdi", $user, $pass, $num, $sporocilo);
switch ($output1)
{
case "-1":
echo "Splosna napaka...<br />";
break;
case "-2":
echo "Prazno / predolgo sporocilo...<br />\n";
break;
case "-3":
echo "Napacna telefonska stevilka...<br />\n";
break;
default:
echo "Sporocilo poslano. Na voljo se " . $output1 . " SMSov<br />\n";
break;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment