class VerificationHelper { private $conn; public function __construct($dbConnection) { $this->conn = $dbConnection; } public function generateKey($length) { $key = ''; for ($i = 0; $i < $length; $i++) { $key .= random_int(0, 9); } return $key; } public function sendTextMobile($number, $message) { $payload = json_encode([ 'api_key' => 'hJ9tjUnczCU2AEtlRWZJxXdf81uqx39suWala1bVHMe8HwbMuiK0uLV5BmOMU5QG', 'recipient_number' => '+88' . $number, 'message' => $message, 'mask_id' => 8809612441432 ]); $ch = curl_init('https://my.text360.net/api/user/send/otp'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_HTTPHEADER => ['Content-Type: application/json'] ]); $response = curl_exec($ch); curl_close($ch); return $response; } public function addNewToken($SopnoID, $ver_type, $ver_refer) { $token = $this->generateKey(7); $code = $this->generateKey(7); $sql = "INSERT INTO `gUser_vcode` (`ver_type`, `ver_refer`, `code`, `token`, `state`, `SopnoID`, `pay_state`, `receive_t`) VALUES ('$ver_type', '$ver_refer', '$code', '$token', 0, '$SopnoID', 0, '')"; return $this->conn->query($sql) ? $code : false; } public function sendWhatsAppGreeting($jsonData, $phoneNumber) { $data = json_decode($jsonData, true); $receiverN = ($data['phone_code'] === '+88' ? '88' : $data['phone_code']) . $data['mobile']; $message = [ 'templateName' => 'ghorami_verify', 'receiverN' => $receiverN, 'message_text' => '', 'mtype' => '', 'recipient_type' => '', 'wr_type' => '' ]; $postData = http_build_query([ 'message' => json_encode($message), 'mobile' => $phoneNumber ]); $ch = curl_init('https://whatsapp.ghorami.com/api/wm_send.php'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData, CURLOPT_RETURNTRANSFER => true ]); $result = curl_exec($ch); curl_close($ch); return $result ?: 'Warning'; } public function sendVerificationEmail($jsonData, $email) { $data = json_decode($jsonData, true); $subject = $data['subject']; $from = 'verify@ghorami.com'; $html = '

' . htmlspecialchars($data['title']) . '

' . nl2br(htmlspecialchars($data['message'])) . '

' . htmlspecialchars($data['info']) . '

Contact support at ghorami.com/contact

'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type:text/html;charset=UTF-8\r\n"; $headers .= "From: $from"; return mail($email, $subject, $html, $headers); } } /** require_once 'dbconnect.php'; $helper = new VerificationHelper($conn); // Generate token & send SMS $token = $helper->addNewToken('SOP123', 'phone', 'registration'); $helper->sendTextMobile('01712345678', "Your verification code is $token"); // Send WhatsApp greeting $helper->sendWhatsAppGreeting($json_payload, '01712345678'); // Send Email $helper->sendVerificationEmail($json_payload, 'user@example.com'); **/