112 lines
4.8 KiB
PHP
112 lines
4.8 KiB
PHP
<?php
|
|
|
|
class CET_SALESPD
|
|
{
|
|
public static function pushwithcetsalespdapi_bkup($fields,$data,$flag)
|
|
{
|
|
log_message('ERROR','#### pushwithcetsalespdapi Helper FNS');
|
|
$fields['data'] = $data;
|
|
$pdid = $fields['pdid'];
|
|
$headers = array('Content-Type: application/json');
|
|
$ch = curl_init();
|
|
if($flag == 1){ //sectionurl
|
|
$log_msg = "PullSalesPDData api ";
|
|
$url = 'https://demo.devopsmcfinance.com/cet_salespd/api/PullSalesPdData';
|
|
$output_data = json_encode( $fields );
|
|
}else if($flag == 2){ // imgurl
|
|
$merged_headers = array_merge($headers,array('Content-Encoding : gzip','Vary: Accept-Encoding'));
|
|
$url = 'https://demo.devopsmcfinance.com/cet_salespd/api/PullSalesPdPhotographsData';
|
|
$log_msg = " PullSalesPdPhotographsData api (".$data[0]['img_name'].")";
|
|
// (gzencode(json_encode($data), 9))
|
|
$output_data = gzencode(json_encode($fields), 9);
|
|
}
|
|
else if($flag == 3){ // imgurl
|
|
$url = 'https://demo.devopsmcfinance.com/cet_salespd/api/PullSalesPdPhotographsData';
|
|
$log_msg = " PullSalesPdPhotographsData api (".$data[0]['img_name'].")";
|
|
$output_data = json_encode( $fields );
|
|
}
|
|
// print_r($fields);die;
|
|
log_message('ERROR',"Flag ".$flag.$log_msg." Request Format : ".$output_data);
|
|
curl_setopt( $ch,CURLOPT_URL, $url);
|
|
curl_setopt( $ch,CURLOPT_POST, true );
|
|
curl_setopt( $ch,CURLOPT_HTTPHEADER, $flag == 2 ? $merged_headers : $headers );
|
|
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
|
|
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
|
|
curl_setopt( $ch,CURLOPT_POSTFIELDS, $output_data);
|
|
$result = curl_exec($ch );
|
|
$response = json_decode($result);
|
|
log_message('ERROR',"CET APP PDID (".$pdid.") ".$log_msg." curl result : ".json_encode($result)." response :".json_encode($response));
|
|
//log_message('ERROR',"CET APP PDID (".$pdid.") ".$log_msg." response :".$response->status."/".$response->message);
|
|
// // MYLOG::logFunction(null,($pdid)->info("CET APP ".$log_msg,array('api_result' => $result));
|
|
// echo "res".$response->status;
|
|
// echo $response->message;
|
|
// log_message('ERROR',"result : ".$result);
|
|
// log_message('ERROR',"result : ".json_encode($result));
|
|
curl_close( $ch );
|
|
|
|
}
|
|
|
|
public static function pushwithcetsalespdapi($fields,$data,$flag)
|
|
{
|
|
log_message('ERROR','#### pushwithcetsalespdapi Helper FNS '.$fields['pdid']);
|
|
$fields['data'] = $data;
|
|
$pdid = $fields['pdid'];
|
|
$headers = array('Content-Type: application/json');
|
|
try{
|
|
$ch = curl_init();
|
|
$output_data = json_encode( $fields );
|
|
// print_r($output_data);die();
|
|
log_message('ERROR',"PullSalesPDData api Request Format : ".$output_data);
|
|
curl_setopt( $ch,CURLOPT_URL, CET_SALESPD_INTEGRATION_URL);
|
|
curl_setopt( $ch,CURLOPT_POST, true );
|
|
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
|
|
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
|
|
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
|
|
curl_setopt( $ch,CURLOPT_POSTFIELDS, $output_data);
|
|
$result = curl_exec($ch );
|
|
$response = json_decode($result);
|
|
log_message('ERROR',"CET APP SALES PDID (".$pdid.") "."PullSalesPDData api response :".json_encode($response));
|
|
curl_close( $ch );
|
|
}
|
|
catch (Exception $e) {
|
|
$response = array();
|
|
log_message('ERROR', "CET APP SALES PDID (".$pdid.") ERR : " . $e->getMessage());
|
|
}
|
|
return $response;
|
|
|
|
}
|
|
// multipart/form-data;
|
|
public static function pushwithcetphotographapi($fields,$index)
|
|
{
|
|
log_message('ERROR','#### pushwithcetphotographapi Helper FNS '.$fields['pdid']);
|
|
$CI =&get_instance();
|
|
$img = $fields['img'];
|
|
$pdid = $fields['pdid'];
|
|
$img = str_replace('data:image/png;base64,', '', $img);
|
|
$img = str_replace(' ', '+', $img);
|
|
$data = base64_decode($img);
|
|
$file = $CI->external_path.'/tmp/temp'. $index .date('Y-m-d_h-i-s') .'.png';
|
|
$curlFile = curl_file_create($file);
|
|
$success = file_put_contents($file, $data);
|
|
$headers = array('Content-Type: multipart/form-data');
|
|
// $headers = array('Content-Type: application/json');
|
|
$ch = curl_init();
|
|
// $url = 'https://apitest.pdgenie.com/file_receive.php';
|
|
$log_msg = " PullSalesPdPhotographsData api (".$fields['img_name'].")";
|
|
$fields['img'] = $curlFile;
|
|
curl_setopt( $ch,CURLOPT_URL, CET_SALESPD_INTEGRATION_IMG_URL);
|
|
curl_setopt( $ch,CURLOPT_POST, true );
|
|
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
|
|
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
|
|
// curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
|
|
$result=curl_exec($ch);
|
|
$response = json_decode($result);
|
|
log_message('ERROR',"###CET APP SALES PDID (".$pdid.") ".$log_msg."response :".json_encode($response));
|
|
curl_close( $ch );
|
|
unlink($file);
|
|
return $response;
|
|
}
|
|
}
|
|
|
|
?>
|