|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/namascar_app/panel.namascar.app/app/Helpers/ |
Upload File : |
<?php
namespace App\Helpers;
use Postal;
use App\Models\Sms_cdr;
use App\Models\Otp_session;
use Exception;
class MyHelper
{
static function haversineGreatCircleDistance(
$latitudeFrom,
$longitudeFrom,
$latitudeTo,
$longitudeTo,
$earthRadius = 6371000
) {
// convert from degrees to radians
$latFrom = deg2rad($latitudeFrom);
$lonFrom = deg2rad($longitudeFrom);
$latTo = deg2rad($latitudeTo);
$lonTo = deg2rad($longitudeTo);
$latDelta = $latTo - $latFrom;
$lonDelta = $lonTo - $lonFrom;
$angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
return $angle * $earthRadius;
}
static function sentOTP($mobile)
{
$OTP = rand(1111, 9999);
$message_content = urlencode("Dear Student, use OTP code $OTP to verify your account, Edukrypt APP");
$smsLoad = array(
"username" => "amitpopli",
"password" => "amitpopli",
"from" => "EDUKYT",
"pe_id" => "1201160957975132087",
"template_id" => "1207162141508403142",
"to" => ["$mobile"],
"text" => $message_content,
"coding" => "0"
);
$curl = curl_init();
curl_setopt_array(
$curl,
array(
CURLOPT_URL => 'https://web.smsgw.in/smsapi/jsonapi.jsp',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($smsLoad),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
)
);
$response = curl_exec($curl);
curl_close($curl);
$header = json_decode($response);
// failed =================================
if (isset($header->Error->ErrorCode)) {
// $resPonse = array(
// "status" => false,
// "code" => 204,
// "message" => "Something wen wrong, please try again!",
// );
// echo json_encode($resPonse);
$log = array(
'to' => $mobile,
'text' => urldecode($message_content),
'status' => 0,
'sender_id' => 'EDUKYT',
'template_id' => '1207162141508403142',
'created_at' => date('Y-m-d H:i:s')
);
Sms_cdr::create($log);
return false;
}
$OtpSession = array(
'phone' => $mobile,
'otp' => $OTP,
'message_id' => $header->data->msgid,
);
Otp_session::create($OtpSession);
// success ====================
$log = array(
'to' => $mobile,
'text' => urldecode($message_content),
'status' => 1,
'message_id' => $header->data->msgid,
'sender_id' => 'EDUKYT',
'template_id' => '1207162141508403142',
'created_at' => date('Y-m-d H:i:s')
);
Sms_cdr::create($log);
return $OtpSession;
}
public static function sendMailPostal($to, $subject, $html)
{
// Create a new Postal client using the server key you generate in the web interface
$client = new Postal\Client('https://postal.balancepost.in', 'Kbf5womv34i4BSwfiFe4F1Lp');
// Create a new message
$message = new Postal\Send\Message();
// Add some recipients
$message->to($to);
// $message->to('vashu.kulshrestha@gmail.com');
// $message->cc('mike@example.com');
// $message->bcc('secret@awesomeapp.com');
// Specify who the message should be from. This must be from a verified domain
// on your mail server.
$message->from('namascar@edukrypt.app');
// Set the subject
$message->subject($subject);
// Set the content for the e-mail
// $message->plainBody('Hello world!');
$message->htmlBody($html);
// Add any custom headers
// $message->header('MIME-Version', '1.0');
// $message->header('Content-type', 'text/html');
// $message->header('charset', 'UTF-8');
// Attach any files
// $message->attach('textmessage.txt', 'text/plain', 'Hello world!');
// Send the message and get the result
try {
$result = $client->send->message($message);
return true;
} catch (Exception) {
return false;
}
// Loop through each of the recipients to get the message ID
// foreach ($result->recipients() as $email => $message) {
// $email; // The e-mail address of the recipient
// $message->id; // The message ID
// $message->token; // The message's token
// }
}
}