68 lines
2.5 KiB
PHP
68 lines
2.5 KiB
PHP
<?php
|
|
|
|
function perform_whatsapp_request($url,$method,$data){
|
|
// log_message('INFO',"PerformWhatsappRequest : request url = ".$url);
|
|
// log_message('INFO',"PerformWhatsappRequest : request data type = ".$data);
|
|
// log_message('INFO',"PerformWhatsappRequest : method = ".$method);
|
|
|
|
}
|
|
|
|
function perform_http_request_old($method, $url, $data = false) {
|
|
$username = "ck_935889d13267b63c2341168e42ffafe3c1ee831a";
|
|
$password = "cs_6ce1321c3f08049dfb3c8098ea21137796446bc4";
|
|
$encodekey = base64_encode($username.':'.$password);
|
|
$headers = array(
|
|
'Content-Type:application/json',
|
|
'Authorization: Basic '. $encodekey
|
|
);
|
|
try{
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
switch ($method) {
|
|
case "POST":
|
|
curl_setopt($curl, CURLOPT_POST, true);
|
|
if ($data) {
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
}
|
|
break;
|
|
case "PUT":
|
|
curl_setopt($curl, CURLOPT_PUT, 1);
|
|
break;
|
|
default:
|
|
if ($data) {
|
|
// print_r($data);die();
|
|
$url = sprintf("%s?%s", $url, http_build_query((array)$data));
|
|
}
|
|
}
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //If SSL Certificate Not Available, for example, I am calling from http://localhost URL
|
|
curl_setopt( $curl,CURLOPT_SSL_VERIFYPEER, true );
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, true);
|
|
$result = curl_exec($curl);
|
|
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
$curl_errno= curl_errno($curl);
|
|
if($curl_errno){
|
|
if ($http_status==503){
|
|
$error = "HTTP Status == 503 <br/> Curl Errno returned $curl_errno <br/>";
|
|
}
|
|
else{ $error = "Curl Errno returned $curl_errno <br/>"; }
|
|
$error_msg = curl_error($curl);
|
|
}else{
|
|
$error = "";
|
|
$error_msg = "";
|
|
}
|
|
curl_close($curl);
|
|
$response = (array) json_decode($result);
|
|
}catch (Exception $e) {
|
|
$error = "Exception Errno returned".$e->getCode()." <br/>";
|
|
$error_msg = $e->getMessage();
|
|
$response = array();
|
|
|
|
}
|
|
$final = array( "response"=>$response,"error"=>$error,"error_msg"=>$error_msg);
|
|
return $final;
|
|
}
|
|
?>
|