c1
This commit is contained in:
157
www/first.loc/api/queryMainPost.php
Normal file
157
www/first.loc/api/queryMainPost.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
error_reporting(0);
|
||||
header('Access-Control-Allow-Origin:*');
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Methods: POST");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
|
||||
function checkJSON($string) {
|
||||
$result = [
|
||||
'is_valid' => false,
|
||||
'type' => null,
|
||||
'error' => null
|
||||
];
|
||||
|
||||
$decoded = json_decode($string);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$result['is_valid'] = true;
|
||||
$result['type'] = gettype($decoded);
|
||||
} else {
|
||||
$result['error'] = json_last_error_msg();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
// Получаем данные
|
||||
$data = json_decode(file_get_contents("php://input"));
|
||||
|
||||
|
||||
|
||||
include_once "Class/function.php";
|
||||
|
||||
$arr= json_decode($data -> data,true);
|
||||
|
||||
$kag=$arr['kag'];
|
||||
$param_api=$arr['kag']['param_api'];
|
||||
|
||||
|
||||
|
||||
$url='https://marketplace.book-online.ru/api/shipment_barcodes/';
|
||||
|
||||
//переворачиваем дату для яндекса
|
||||
$date_query_strtotime=strtotime($arr['date_query']);
|
||||
$date_query_dmy=date('d-m-Y',$date_query_strtotime);
|
||||
|
||||
if($kag['firma']==0){
|
||||
$post_data=json_encode(['date'=> $date_query_dmy,'kag'=>$kag['kag']]);
|
||||
|
||||
}else{
|
||||
$post_data=json_encode(['date'=> $arr['date_query'],'kag'=>$kag['kag']]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$headers = Array("Authorization: fi9tzpIHgp84E1Pf45rMzR/hy8lA2zE5", 'Content-Type: "application/json"');
|
||||
|
||||
$data_json=getSSLPage($url,$post_data,$headers);
|
||||
|
||||
//echo $data_json;
|
||||
|
||||
|
||||
$check = checkJSON($data_json);
|
||||
|
||||
if (!$check['is_valid']) {
|
||||
$data_=json_encode(['data_json'=>'','error'=>$data_json,'post_data'=>$post_data,'result'=>1,]);
|
||||
echo $data_;
|
||||
|
||||
die('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(is_numeric($data_json) and $data_json>=400){
|
||||
http_code($data_json);
|
||||
}
|
||||
|
||||
|
||||
include_once "Class/Database.php";
|
||||
//include_once "Class/DatabasePGSQL.php";
|
||||
include_once "Class/MainClass.php";
|
||||
|
||||
$database = new Database();
|
||||
//$database = new Database();//PGSQL
|
||||
$db = $database->getConnection();
|
||||
|
||||
$user=0;
|
||||
|
||||
$param=[
|
||||
'date_query' => $arr['date_query'],
|
||||
'data_json' => $data_json,
|
||||
'user' => $user,
|
||||
'kag'=> $arr['kag']
|
||||
];
|
||||
|
||||
$data=json_decode($data_json,true);
|
||||
|
||||
$main_class = new MainClass($db);
|
||||
//$main_class->WrFile($param);
|
||||
|
||||
if(isset($data['error']) and strlen($data['error'])){
|
||||
$result=null;
|
||||
|
||||
}else{
|
||||
$result=$main_class->wrDatabase($param);
|
||||
|
||||
//передается несколько актов
|
||||
|
||||
for($i=0;$i<count($data);$i++){
|
||||
$param1=[
|
||||
'idoper'=>$data[$i]['id'],
|
||||
'kag'=> $arr['kag'],
|
||||
];
|
||||
|
||||
//очень важно------------------>
|
||||
$data[$i]['idoper']=$data[$i]['id'];
|
||||
$data[$i]['id']=$result['result'][$data[$i]['id']];//id (в нем содержится idoper) меняется на id строки
|
||||
$data[$i]['data_collect']=$main_class->DataCollect($param1); //результаты сканирования актов
|
||||
$data[$i]['date_query']=$arr['date_query'];
|
||||
$data[$i]['date_q']=$date_query_dmy;
|
||||
$data[$i]['data_json']=['barcodes'=>$data[$i]['barcodes'],'id'=>$data[$i]['idoper']];
|
||||
//unset($data[$i]['barcodes']);
|
||||
//<------------------очень важно
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(!$result['result']){
|
||||
$data_=json_encode(['data_json'=>$data,'server_error'=>$data['error'],'post_data'=>$post_data,'result'=>0, 'id'=>0,'date_query'=>$arr['date_query'],'data_collect'=>[],'method'=>$url,'param'=>$param]);
|
||||
}else{
|
||||
$data_=json_encode(['data_json'=>$data,'server_error'=>$data['error'],'post_data'=>$post_data,'result'=>1,'id'=>$result['ids'],'idoper'=>$result['idoper'], 'date_query'=>$arr['date_query'],'data_collect'=>$data_collect,'method'=>$url,'param'=>$param]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
echo $data_;
|
||||
|
||||
}catch (Exception $err){
|
||||
$data_=json_encode(['data_json'=>'','server_error'=>$err,'post_data'=>'','result'=>1,]);
|
||||
|
||||
echo $data_;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user