<?php 
/*##############################################
Version : 1.0.1
Owner : BUYbot
Support : 011-49095741
Email : support@buynxt.in
File Created On : 20-10-2021
Team : BUYbot API Tech
###############################################*/

function buybotsender($datatosend=null){
	if($datatosend)
	{
		$WAdata = array();		
		$WAdata['access_key']=BUYbotKEY;
		$WAdata['Contact_No']=$datatosend['sendto'];
		$WAdata['parameters']=makeparambold($datatosend['param']);
		if($datatosend['img']!=''){$WAdata['image']=$datatosend['img'];}else{$WAdata['image']=BUYbotIMG;}
		if($datatosend['video']!=''){$WAdata['video']=$datatosend['video'];}else{$WAdata['video']=BUYbotVIDEO;}
		$WAdata['Url']='';
		if($datatosend['btnurl']!=''){$WAdata['btnurl']=$datatosend['btnurl'];}else{$WAdata['btnurl']='';}
		if($datatosend['doc']!=''){$WAdata['doc']=$datatosend['doc'];}else{$WAdata['doc']=BUYbotDOC;}
		$WAdata['template']=$datatosend['template'];
		sendToBuybot($WAdata);
	}
}

function makeparambold($param){
	$newdata=array(); $i=0;	foreach($param as $item){$newdata[$i]='*'.$item.'*';$i++;} return $newdata; }

function sendToBuybot($wad){
	print_r(json_encode($wad));
		$url = BUYbotURL;
		$headerkey=BUYbotKEY;		
		$curlOptions = array( CURLOPT_RETURNTRANSFER => TRUE);
		$curlOptions[CURLOPT_CUSTOMREQUEST] = 'POST';
		$curlOptions[CURLOPT_URL] = $url;
		$requestHeaders = array('Authorization: $headerkey','Content-Type: application/json','Accept: application/json');
		$curlOptions[CURLOPT_POSTFIELDS] = json_encode($wad);
		$curlOptions[CURLOPT_HTTPHEADER] = $requestHeaders;
		$curl = curl_init();
		curl_setopt_array($curl, $curlOptions);
		$response = curl_exec($curl);
		curl_close($curl);
		print_r($response);
}	

?>