<?php
class main_class {

	function getEncryptedKey($data, $enc_text) {

		foreach($data as $key => $value) {
			$value 		= preg_replace('/\s+/', '',$value);
			$str = $key."=".$value;	
			$str1 .= $str."&";		
		}

		$parameterStr = substr($str1, 0, strlen($str1)-1);
		
		$hash_key = $this->hash_key;

		$hashSha256		= hash('sha256', $hash_key . $parameterStr);	

		//print "<br>".$parameterStr;	
		//print "<br>hashSha256: ".$hashSha256;
		//print "<br>enc_text: ".$enc_text;
		//exit;
		
		if($hashSha256 == $enc_text) { 
			return 0;
		} else { 
			return 1;
		}
	}

	function genRandString($length = 0) {

		$otp1 	= rand(0, 9);
		$otp2 	= rand(0, 9);
		$otp3 	= rand(0, 9);
		$otp4 	= rand(0, 9);
		$otp 	= $otp1.$otp2.$otp3.$otp4;
		$cdate  = date("Y-m-d H:i:s");
		$id 	= md5(date("Y-m-d H:i:s"));
		$charset 	= $id.$otp;
        $str = '';
        $count = strlen($charset);
        while ($length-- > 0) {
            $str .= $charset[mt_rand(0, $count-1)];
        }
		return $str;
    }



	public function send_welcome_mail($name, $referID, $emailAdd, $password) {

		$url 		 = "http://localhost/MyBooster/mailer/API_welcome_mailv2.php?";
		$dataString  = "receiverName=". urlencode($name);
		$dataString  = $dataString."&receiverID=".$referID;
		$dataString  = $dataString."&receiverMailID=".$emailAdd;
		$dataString  = $dataString."&password=".$password;

		$url 		= $url.$dataString;

		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_VERBOSE, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($ch);
		$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

		return $output;
	}


	public function send_password_mail($name, $referID, $password, $emailAdd) {

		$url 		 = "http://localhost/MyBooster/mailer/API_mailer_forgot_password.php?";
		$dataString  = "name=". urlencode($name);
		$dataString  = $dataString."&referID=".$referID;
		$dataString  = $dataString."&password=".$password;
		$dataString  = $dataString."&email_address=".$emailAdd;

		$url 		= $url.$dataString;

		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_VERBOSE, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($ch);
		$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

		return $output;
	}


	public function sendOTP_special_Twilio($mobileNo, $message){

	// $mobileNo = "+918652501652";
	// $message = "Teest Curl Messages PHP";

	$params['To'] = $mobileNo;
	$params['From'] = "+18013168126";
	$params['Body'] = $message;

	$dataString = http_build_query($params);
	//echo $dataString ;exit;
	$sid = "ACbc2f22ce4f428286fc7a0dd888680d49";
	$token = "06260212b8ccfec1e5e08b5b2d5304d8";

	$curl = curl_init();

	curl_setopt_array($curl, array(
	  CURLOPT_URL => "https://api.twilio.com/2010-04-01/Accounts/ACbc2f22ce4f428286fc7a0dd888680d49/Messages.json",
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => "",
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 30,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => "POST",
	  CURLOPT_POSTFIELDS =>$dataString ,
	  CURLOPT_HTTPHEADER => array(
	    "cache-control: no-cache",
	    "content-type: application/x-www-form-urlencoded",
	  ),
	));
	curl_setopt($curl, CURLOPT_USERPWD, $sid . ":" . $token);

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

	curl_close($curl);

	$result = json_decode($response,true);

		if ($result['status']=='queued') {
		  return 1;
		} else {
		  return 0;
		}

	}

	public function sendOTP_special($serviceID, $OTPResponse) {

		$recharge_sms_username = '2000182442';
        $recharge_sms_password = 'Mybooster@5050';

		$PARAMETERS["method"]	 	= "sendMessage";
		$PARAMETERS["userid"] 		= $recharge_sms_username;	
		$PARAMETERS["password"] 	= $recharge_sms_password;				
		$PARAMETERS["v"] 		= "1.1";				
		$PARAMETERS["msg_type"] 	= "TEXT";				
		$PARAMETERS["auth_scheme"] 	= "PLAIN";
		$PARAMETERS["send_to"] 		= $serviceID;
		$PARAMETERS["msg"] 		= $OTPResponse;						

		foreach($PARAMETERS as $key=>$val) {
			$request.= $key."=".urlencode($val);
			$request.= "&";
		}

		$request 	= substr($request, 0, strlen($request)-1);
		$request = $request."&mask=MyBstr";
		
		$url 		= "http://enterprise.smsgupshup.com/GatewayAPI/rest?".$request;

		$ch 		= curl_init($url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$curl_scraped_page = curl_exec($ch);
		curl_close($ch);
		$curlres 	= explode("|",$curl_scraped_page);
		
		if( trim($curlres[0]) == 'success' ) {
			return $response = 1;
		} else {
			return $response = 0;
		}
	}


	public function send_SMS_ID($mobileNumber, $message) {

		$username = "laxmikant@vervegs.com";
		$hash     = "618ff3bc1a3206444ff3a681510fd5327d071ec08a22b5b7712e91c3c3833149";

		// Config variables. Consult http://api.textlocal.in/docs for more info.
		//$test = "0";

		// Data for text message. This is the text message data.
		$sender  = "MYBSTR"; // This is who the message appears to be from.
		$numbers = $mobileNumber; // A single number or a comma-seperated list of numbers
		
		// A single number or a comma-seperated list of numbers
		$message = urlencode($message);
		$data    = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers;
		$ch      = curl_init('http://api.textlocal.in/send/?');
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$result = curl_exec($ch); // This is the result from the API
		curl_close($ch);

	}




	public function sendOTP($serviceID, $OTPResponse) {
		
		/*$url = "http://bhashsms.com/api/sendmsg.php?";
		$data_string.= "user=niteshbisawa";
		$data_string.= "&pass=nitesh@123";
		$data_string.= "&sender=Ezeelo";
		$data_string.= "&phone=".$serviceID;
		$data_string.= "&text=".$OTPResponse;
		$data_string.= "&priority=ndnd";
		$data_string.= "&stype=normal";

		$urlMain = $url;
		
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_URL, $urlMain);                                                                     
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                      
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
		 
		$result = curl_exec($ch);*/

		//print "<pre>";
		//print_r($result);
		//print "</pre>";


		
		//print "<br>serviceID: ".$serviceID ."<br>OTP: ". $OTPResponse;
		//exit;

		$recharge_sms_username = '2000176386';
        $recharge_sms_password = 'GUUm6X';

		//$recharge_sms_username = '2000174791';
		//$recharge_sms_password = 'CFNzDB';

		$PARAMETERS["method"]	 	= "sendMessage";
		//$PARAMETERS["userid"] 	= "2000146441";	
		$PARAMETERS["userid"] 		= $recharge_sms_username;	
		//$PARAMETERS["password"] 	= "Fwzso6wlO";				
		$PARAMETERS["password"] 	= $recharge_sms_password;				
		$PARAMETERS["v"] 		= "1.1";				
		$PARAMETERS["msg_type"] 	= "TEXT";				
		$PARAMETERS["auth_scheme"] 	= "PLAIN";
		$PARAMETERS["send_to"] 		= $serviceID;
		//$PARAMETERS["msg"] 		= $message;
		$PARAMETERS["msg"] 		= $OTPResponse;						

		foreach($PARAMETERS as $key=>$val) {
			$request.= $key."=".urlencode($val);
			$request.= "&";
		}

		$request 	= substr($request, 0, strlen($request)-1);
		$request = $request."&mask=BBT";
		//print "<br>Request: ".$url 		= "http://enterprise.smsgupshup.com/GatewayAPI/rest?method=sendMessage&userid=2000146441&password=Fwzso6wlO&v=1.1&msg_type=TEXT&auth_scheme=PLAIN&send_to=919820035912&msg=Your+one+time+Password+is+8902.";
		
		$url 		= "http://enterprise.smsgupshup.com/GatewayAPI/rest?".$request;

		$ch 		= curl_init($url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$curl_scraped_page = curl_exec($ch);
		curl_close($ch);
		$curlres 	= explode("|",$curl_scraped_page);
		
		if( trim($curlres[0]) == 'success' ) {
			return $response = 1;
		} else {
			return $response = 0;
		}
		
	}

	public function createUserID()
	{
		$length         = 30;
		$useLetters     = true;
		$useNumbers     = true;
		$useMixedCase	= false;

		$uppercase    = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'];
		$lowercase    = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];
		$numbers      = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
		$symbols      = ['`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '\\', '|', '/', '[', ']', '{', '}', '"', "'", ';', ':', '<', '>', ',', '.', '?'];

		$characters   = [];
		$user_id  = '';

		if ($useLetters) {
			if ($useMixedCase) {
				$characters = array_merge($characters, $lowercase, $uppercase);
			} else {
				$characters = array_merge($characters,  $lowercase);
			}
		}

		if ($useNumbers) {
			$characters = array_merge($characters, $numbers);
		}

		for ($i = 0; $i < $length; $i++) {
				$user_id  .= $characters[mt_rand(0, count($characters) - 1)];
		}

		$user_id   = substr_replace($user_id, "-",9,0);
		$user_id   = substr_replace($user_id, "-",14,0);
		$user_id   = substr_replace($user_id, "-",18,0);
	    $user_id   = substr_replace($user_id, "-",22,0);
		$user_id   = substr_replace($user_id, "-",27,0);

	   
		return $user_id ;

	}




}
?>

