IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/SendSmsApi.php

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Http;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
use GuzzleHttp\Exception\ClientException;
use Auth;

/**
 * Description of SMS Api
 *
 * @author HKCL
 */
class SendSmsApi {

    static function getUserNumber($phone_number, $message,$school,$tempid) {
        if(isset($tempid)){
            Log::info($phone_number);
            Log::info($message);
            Log::info($tempid);
            if($school->idCountry == 1)
            {
                if($school->idSchool == 135 || $school->idSchool == 140 || $school->idSchool == 160 || $school->idSchool == 159 || $school->idSchool == 139 || $school->idSchool == 183 || $school->idSchool == 181){
                    self::initiateSmsGuzzleGet($phone_number, $message,$school,$tempid);
                }else{
                    self::initiateSmsActivation($phone_number, $message,$school,$tempid);
                    self::initiateSmsGuzzle($phone_number, $message,$school,$tempid);
                }
            }
            else if($school->idCountry == 3) self::initiateSmsSrilankaActivation($phone_number, $message,$school,$tempid);
            //self::initiateSmsGuzzle($phone_number, $message,$school,$tempid);
        }
        return redirect()->back()->with('message', 'Message has been sent successfully');
    }

    static function initiateForgotPassword($phone_number, $message) {
        $client = new Client();
    
        $loginID = "T1forgetpass";
        $password = "654321";
        $senderid = "JIJENT";
        $response = $client->post('http://hindit.co.in/API/pushsms.aspx?loginID='.$loginID.'&password='.$password.'&mobile='.$phone_number.'&text='.$message.'&senderid='.$senderid.'&route_id=2&Unicode=0&IP=x.x.x.x&Template_id=1707163237471353463');
        $response = json_decode($response->getBody(), true);
        return redirect()->back()->with('message', 'Message has been sent successfully');
    }

    static function initiateLoginPassword($phone_number, $message) {
        $client = new Client();
        $loginID = "T1forgetpass";
        $password = "654321";
        $senderid = "JIJENT";
        $response = $client->post('http://hindit.co.in/API/pushsms.aspx?loginID='.$loginID.'&password='.$password.'&mobile='.$phone_number.'&text='.$message.'&senderid='.$senderid.'&route_id=2&Unicode=0&IP=x.x.x.x&Template_id=1707163237471353463');
        $response = json_decode($response->getBody(), true);
        return redirect()->back()->with('message', 'Message has been sent successfully');
    }

    static function initiateErrorLoginPassword($phone_number, $message) {
        try{
            $client = new Client();
            $loginID = "T1forgetpass";
            $password = "654321";
            $senderid = "JIJENT";
            $response = $client->post('http://hindit.co.in/API/pushsms.aspx?loginID='.$loginID.'&password='.$password.'&mobile='.$phone_number.'&text='.$message.'&senderid='.$senderid.'&route_id=2&Unicode=0&IP=x.x.x.x&Template_id=1707163237471353463');
            $response = json_decode($response->getBody(), true);
            return 1;
        }catch(ClientException $e){
            return 0;
        }
    }

    static function initiateSmsSrilankaActivation($phone_number, $message,$school,$tempid) {
        $isError = 0;
        $errorMessage = true;
      
        $MSISDN = $phone_number;
	    $SRC = "SendTest";
	    $MESSAGE = ( urldecode($message));
	    $AUTH = "1944|78AsbII9B5Kobc335zbd0OoIc15UiLsw9rDSZnuN";  //Replace your Access Token
	
	    $msgdata = array("recipient"=>$MSISDN, "sender_id"=>$SRC, "message"=>$MESSAGE);

			$curl = curl_init();
			
			//IF you are running in locally and if you don't have https/SSL. then uncomment bellow two lines
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
			
			curl_setopt_array($curl, array(
			  CURLOPT_URL => "https://sms.send.lk/api/v3/sms/send",
			  CURLOPT_CUSTOMREQUEST => "POST",
			  CURLOPT_POSTFIELDS => json_encode($msgdata),
			  CURLOPT_HTTPHEADER => array(
				"accept: application/json",
				"authorization: Bearer $AUTH",
				"cache-control: no-cache",
				"content-type: application/x-www-form-urlencoded",
			  ),
			));

			$response = curl_exec($curl);
			$err = curl_error($curl);

			curl_close($curl);

			if ($err) {
                return array('error' => 1, 'message' => $err);
			} else {
                return array('error' => 0);
			}
    }

    static function initiateSmsActivation($phone_number, $message,$school,$tempid) {
        $isError = 0;
        $errorMessage = true;
        $loginID = $school->smsUsername;
        $password = $school->smsPassword;
        $senderid = $school->smsSenderId;
      
        //Preparing post parameters
        $postData = array(
            'loginID' => $loginID,
            'password' => $password,
            'mobile' => $phone_number,
            'message' => $message,
         //   'gwid' => 2,
         //   'fl' => 0
        );

        $url = 'http://hindit.co.in/API/pushsms.aspx?loginID='.$loginID.'&password='.$password.'&mobile='.$phone_number.'&text='.$message.'&senderid='.$senderid.'&route_id=2&Unicode=0&IP=x.x.x.x&Template_id='.$tempid;
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => false,
            CURLOPT_POSTFIELDS => $postData
        ));


        //Ignore SSL certificate verification
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


        //get response
        $output = curl_exec($ch);

        //Print error if any
        if (curl_errno($ch)) {
            $isError = true;
            $errorMessage = curl_error($ch);
        }
        curl_close($ch);


        if ($isError) {
            return array('error' => 1, 'message' => $errorMessage);
        } else {
            return array('error' => 0);
        }
    }

    static function initiateSmsGuzzle($phone_number, $message,$school,$tempid) {
        $client = new Client();
    
        $loginID = $school->smsUsername;
        $password = $school->smsPassword;
        $senderid = $school->smsSenderId;
        $response = $client->post('http://hindit.co.in/API/pushsms.aspx?loginID='.$loginID.'&password='.$password.'&mobile='.$phone_number.'&text='.$message.'&senderid='.$senderid.'&route_id=2&Unicode=0&IP=x.x.x.x&Template_id='.$tempid);
        $response = json_decode($response->getBody(), true);
    }


    static function initiateSmsGuzzleGet($phone_number, $message,$school,$tempid){
        $client = new Client();
        $params = [
            'query' => [
               'user' => "MJEDUT",
               'authkey' => "92yvEjptEOT0s",
               'sender' => "MJEDUT",
               'mobile' => $phone_number,
               'text' => $message,
               'entityid' => "1001604334761950863",
               'templateid' => $tempid,
               'rpt' => "1",
            ]
        ];
        $response = $client->request('GET','https://hindit.net.in/api/pushsms',$params);
        return $response = json_decode($response->getBody(), true);
    }

}

Copyright © 2021 - 2025 IMMREX7