564 lines
21 KiB
PHP
564 lines
21 KiB
PHP
<?php
|
|
|
|
class Re_patient extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
|
|
var $url_download;
|
|
|
|
public function index()
|
|
{
|
|
echo "RE Patient API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 10;
|
|
|
|
$sdate = $prm["start_date"] . '%';
|
|
$edate = $prm["end_date"] . '%';
|
|
$search = '%' . $prm["search"] . '%';
|
|
$page = $prm['page'];
|
|
$group_id = 0;
|
|
if (isset($prm['group_id'])) $group_id = $prm['group_id'];
|
|
|
|
$company_id = 0;
|
|
$q_company = "";
|
|
if (isset($prm['company_id'])) {
|
|
$company_id = $prm['company_id'];
|
|
if ($company_id > 0 ) {
|
|
$q_company = " and T_OrderHeaderCorporateID = $company_id ";
|
|
}
|
|
}
|
|
$q_search = " and
|
|
( M_PatientName LIKE ?
|
|
or T_OrderHeaderLabNumber like ?
|
|
)";
|
|
if ($prm["search"] == "" ) $q_search = "";
|
|
if ($page == null)
|
|
$page = 1;
|
|
|
|
$offset = ($page - 1) * $max_rst;
|
|
|
|
$max_rst = 9999;
|
|
$offset = 0;
|
|
|
|
$q_group = "";
|
|
if ($group_id != 0 ) {
|
|
$sql = "select T_WorklistDetailNat_TestID Nat_TestID
|
|
from t_worklistdetailv2
|
|
where T_WorklistDetailT_WorklistID = $group_id
|
|
";
|
|
$qry = $this->db_smartone->query($sql);
|
|
$rows = $qry->result_array();
|
|
$nat_test_ids = "0";
|
|
foreach($rows as $r) {
|
|
$nat_test_ids .= ", " . $r["Nat_TestID"];
|
|
}
|
|
$q_group = " and T_TestNat_TestID in ( $nat_test_ids ) ";
|
|
}
|
|
|
|
//janji hasil hari ini T_OrderHeaderID
|
|
/* $sql = "select T_OrderPromiseT_OrderHeaderID
|
|
from t_orderpromise
|
|
where T_OrderPromiseIsActive = 'Y' and date(T_OrderPromiseDateTime) = ?";
|
|
$qry = $this->db_smartone->query($sql, array($sdate));
|
|
$promise_ids = "0";
|
|
if ($qry) {
|
|
$xrows = $qry->result_array();
|
|
if ( count($xrows) > 0 ) {
|
|
$xids = array();
|
|
foreach($xrows as $r) $xids[] = $r["T_OrderPromiseT_OrderHeaderID"];
|
|
$promise_ids = join(",",$xids);
|
|
}
|
|
}
|
|
*/
|
|
$order_ids = 0;
|
|
$sql = "select T_OrderHeaderID
|
|
from t_orderheader
|
|
where T_OrderHeaderIsActive = 'Y' and date(T_OrderHeaderDate) BETWEEN ? AND ?";
|
|
$qry = $this->db_smartone->query($sql, array($sdate,$edate));
|
|
$order_ids = $promise_ids;
|
|
if ($qry) {
|
|
$xrows = $qry->result_array();
|
|
if ( count($xrows) > 0 ) {
|
|
$xids = array();
|
|
foreach($xrows as $r) $xids[] = $r["T_OrderHeaderID"];
|
|
$order_ids = join(",",$xids);
|
|
}else{
|
|
$order_ids = 0;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT *,
|
|
CONCAT('[', GROUP_CONCAT(DISTINCT CONCAT('\"', T_OrderHeaderDate, '\"') SEPARATOR ','), ']') order_promise
|
|
FROM (
|
|
select T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderDate,
|
|
'' T_OrderHeaderLabNumberExt, T_OrderHeaderDiagnose,
|
|
M_PatientID, M_PatientNoReg, fn_global_patient_name(M_PatientID) M_PatientName,
|
|
M_PatientDOB, T_OrderHeaderM_PatientAge, M_PatientHP, M_PatientGender M_SexName, '' M_PatientNote,
|
|
da.M_DoctorID doctor_pj_id, fn_get_doctor_fullname(da.M_DoctorID) doctor_pj_name,
|
|
0 doctor_sender_id, '' doctor_sender_name,
|
|
'' M_MouID, '' M_MouName, CorporateID, CorporateName,
|
|
T_OrderHeaderFoNote, T_OrderHeaderSamplingNote, T_OrderHeaderResultNote,
|
|
la.M_LangID M_LangID, la.M_LangCode M_LangCode, la.M_LangName M_LangName, '' T_OrderHeaderLangIsSI,
|
|
la.M_LangID SecondM_LangID, la.M_LangCode SecondM_LangCode, la.M_LangName SecondM_LangName,
|
|
'' T_OrderHeaderAddOnSecondLangIsSI,
|
|
'N' T_OrderHeaderIsCito, '' as delivery,
|
|
'' T_OrderPromiseDateTime, '' is_history,
|
|
'N' T_OrderHeaderAddOnVerificationDone,
|
|
'N' T_OrderHeaderAddOnValidationDone, '' T_OrderHeaderAddOnRequestChangeDOB
|
|
from t_orderheader
|
|
JOIN t_orderdetail ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_orderheaderlang ON T_OrderHeaderLangT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
{$q_group}
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N'
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
left join m_doctor da on T_OrderHeaderPJM_DoctorID = da.M_DoctorID
|
|
JOIN corporate on T_OrderHeaderCorporateID = CorporateID
|
|
JOIN m_lang la ON T_OrderHeaderLangM_LangID = la.M_LangID
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderHeaderID in ( $order_ids )
|
|
{$q_company}
|
|
{$q_search}
|
|
order by FIELD(T_OrderHeaderIsCito, 'Y', 'N') ASC, T_OrderHeaderLabNumber
|
|
) x
|
|
GROUP BY T_OrderHeaderID
|
|
order by FIELD(T_OrderHeaderIsCito, 'Y', 'N') ASC, T_OrderHeaderLabNumber
|
|
";
|
|
if ($q_search == "" ) {
|
|
$query = $this->db_smartone->query($sql);
|
|
} else {
|
|
$query = $this->db_smartone->query($sql, [ $search, $search]);
|
|
}
|
|
// echo $this->db_smartone->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$tmp_ohnumber = [];
|
|
foreach ($rows as $k => $v)
|
|
{
|
|
$lang = [["id"=>0, "code"=>"ID", "is_si"=>"N"]];
|
|
if ($v['M_LangCode'] != "ID")
|
|
$lang[] = ["id"=>$v['M_LangID'], "code"=>$v['M_LangCode'], "is_si"=>$v['T_OrderHeaderLangIsSI']];
|
|
$sqltotal = "SELECT COUNT(T_OrderDetailID) as cnt_rst_a,
|
|
SUM(IF(T_OrderDetailResult <> '' AND T_OrderDetailResult IS NOT NULL, 1, 0)) as cnt_rst_b,
|
|
SUM(IF(T_OrderDetailVerification = 'Y', 1, 0)) as cnt_ver_n,
|
|
SUM(IF(T_OrderDetailValidation = 'Y', 1, 0)) as cnt_val_n
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N'
|
|
WHERE T_OrderDetailIsActive = 'Y' AND T_OrderDetailT_OrderHeaderID = {$v['T_OrderHeaderID']}
|
|
AND T_OrderDetailT_TestIsResult = 'Y'";
|
|
$sqltotal = $this->db_smartone->query($sqltotal)->row();
|
|
|
|
if($sqltotal->cnt_rst_b > 0 && $sqltotal->cnt_rst_b < $sqltotal->cnt_rst_a){
|
|
$rows[$k]['T_OrderHeaderAddOnValidationDone'] = 'P';
|
|
}elseif($sqltotal->cnt_rst_b > 0 && $sqltotal->cnt_rst_b == $sqltotal->cnt_rst_a){
|
|
$rows[$k]['T_OrderHeaderAddOnValidationDone'] = 'Y';
|
|
}
|
|
$rows[$k]['data'] = json_decode($v['data']);
|
|
$rows[$k]['lang'] = $lang;
|
|
$rows[$k]['delivery'] = JSON_DECODE($v['delivery']);
|
|
$rows[$k]['order_promise'] = JSON_DECODE($v['order_promise']);
|
|
|
|
foreach($rows[$k]['order_promise'] as $l => $w)
|
|
$rows[$k]['order_promise'][$l] = date('d-m-Y H:i', strtotime($w));
|
|
}
|
|
$tot_count = count( $rows );
|
|
|
|
$sql = "Select CorporateID, CorporateName
|
|
from t_orderheader
|
|
JOIN corporate ON CorporateID = T_OrderHeaderCorporateID AND CorporateIsActive = 'Y'
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderHeaderID in ( $order_ids )
|
|
GROUP BY CorporateID";
|
|
$query = $this->db_smartone->query($sql, array($qry) );
|
|
if ($query) {
|
|
$crows = $query->result_array();
|
|
$crows[] = array("CorporateID" => 0, "CorporateName" => "Semua");
|
|
}
|
|
else {
|
|
$this->sys_error_db("", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$result = array("total" => $tot_count,
|
|
"total_page" => ceil($tot_count/$max_rst),
|
|
"cur_page" => $page,
|
|
"records" => $rows,
|
|
"total_display" => sizeof($rows),
|
|
"q" => $this->db_smartone->last_query(),
|
|
"companies"=>$crows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("worklist rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function history()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "CALL sp_process_result_history(?)";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
|
|
if ($query)
|
|
{
|
|
$row = $query->row();
|
|
$history = json_decode($row->rst);
|
|
|
|
$this->sys_ok($history);
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error_db("RESULT HISTORY", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function save_note()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "UPDATE t_orderheader SET T_OrderHeaderResultNote = ?, T_OrderHeaderResultNoteM_UserID = ?
|
|
WHERE T_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, [$prm['note'], $this->sys_user['M_UserID'], $prm['order_id']]);
|
|
if ($query)
|
|
{
|
|
$this->sys_ok($prm['order_id']);
|
|
exit;
|
|
}
|
|
|
|
$this->sys_error_db("RESULT NOTE", $this->db_smartone);
|
|
}
|
|
|
|
public function info_req()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "CALL sp_process_result_reqs(?)";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
if ($query)
|
|
{
|
|
$row = $query->row();
|
|
$s_data = $row->data;
|
|
$s_data = str_replace("\n"," ",$s_data);
|
|
$this->sys_ok(json_decode($s_data));
|
|
exit;
|
|
}
|
|
|
|
$this->sys_error_db("RESULT REQ", $this->db_smartone);
|
|
}
|
|
|
|
function downloadLocal()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$nat_tests = [];
|
|
$test_refers = [];
|
|
|
|
|
|
$sql = "SELECT t_orderdetail.*, T_TestNat_TestID as Nat_TestID
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsPrice = 'Y'
|
|
JOIN nat_testrefer ON Nat_TestReferNat_TestID = T_TestNat_TestID
|
|
WHERE
|
|
T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderDetailT_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
if ($query)
|
|
{
|
|
$test_parents = $query->result_array();
|
|
if (count($test_parents) > 0)
|
|
{
|
|
foreach ($test_parents as $test_parent){
|
|
$sql = "SELECT t_orderdetail.*, T_TestNat_TestID as Nat_TestID
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = ? AND
|
|
T_OrderDetailIsActive = 'Y' AND
|
|
T_OrderDetailT_TestSasCode LIKE CONCAT(?,'%')";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id'],$test_parent['T_OrderDetailT_TestSasCode']]);
|
|
if ($query)
|
|
{
|
|
$tests = $query->result_array();
|
|
foreach ($tests as $test)
|
|
{
|
|
$nat_tests[] = $test['Nat_TestID'];
|
|
$test_refers[] = $test;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$sql = "SELECT t_orderdetail.*, T_TestNat_TestID as Nat_TestID
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsPrice = 'N'
|
|
JOIN nat_testrefer ON Nat_TestReferNat_TestID = T_TestNat_TestID
|
|
WHERE
|
|
T_OrderDetailIsActive = 'Y'
|
|
AND T_OrderDetailT_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
$test_single = $query->result_array();
|
|
foreach ($test_single as $test)
|
|
{
|
|
$sql = "SELECT t_orderdetail.*, T_TestNat_TestID as Nat_TestID
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = ? AND
|
|
T_OrderDetailIsActive = 'Y' AND
|
|
T_OrderDetailT_TestSasCode LIKE CONCAT(?, '%')";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id'],$test['T_OrderDetailT_TestSasCode']]);
|
|
if ($query)
|
|
{
|
|
$test_childs = $query->result_array();
|
|
foreach ($test_childs as $test_child)
|
|
{
|
|
if (!in_array($test_child['Nat_TestID'], $nat_tests)){
|
|
$test_insert[] = $test_child;
|
|
$nat_tests[] = $test_child['Nat_TestID'];
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$sql = "SELECT T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber,
|
|
T_OrderHeaderDate,
|
|
T_OrderHeaderDiagnose,
|
|
T_OrderHeaderFoNote,
|
|
m_patient.*,
|
|
corporate.*,
|
|
Mgm_McuNumber,
|
|
Mgm_McuLabel,
|
|
M_BranchIP,
|
|
M_BranchID
|
|
FROM t_orderheader
|
|
JOIN m_branch ON T_OrderHeaderM_BranchID = M_BranchID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN corporate ON T_OrderHeaderCorporateID = CorporateID
|
|
JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
|
|
WHERE T_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
//echo $this->db_smartone->last_query();
|
|
if(!$query)
|
|
{
|
|
$this->sys_error_db("GET ORDER", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$order = $query->row_array();
|
|
|
|
$samples = [];
|
|
$nat_tests_str = implode(",", $nat_tests);
|
|
$sql = " SELECT t_ordersample.*
|
|
FROM t_ordersample
|
|
JOIN t_orderdetail ON T_OrderSampleT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestNat_TestID IN ({$nat_tests_str})
|
|
WHERE
|
|
T_OrderSampleT_OrderHeaderID = ? AND
|
|
T_OrderSampleIsActive = 'Y' AND
|
|
T_OrderSampleReceive = 'Y'
|
|
GROUP BY T_OrderSampleID";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
//echo $this->db_smartone->last_query();
|
|
if ($query)
|
|
{
|
|
$samples = $query->result_array();
|
|
}
|
|
|
|
$sql = "SELECT * FROM t_orderpromises WHERE T_OrderPromisesT_OrderHeaderID = ? AND T_OrderPromisesIsActive = 'Y'";
|
|
$query = $this->db_smartone->query($sql, [$order['T_OrderHeaderID']]);
|
|
if(!$query)
|
|
{
|
|
$this->sys_error_db("GET ORDER PROMISES", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$order_promises = $query->result_array();
|
|
if(count($order_promises) == 0){
|
|
$order_promises = [];
|
|
}
|
|
|
|
$sql = "SELECT * FROM t_orderdetail_promise WHERE T_OrderDetailPromiseT_OrderHeaderID = ? AND T_OrderDetailPromiseIsActive = 'Y'";
|
|
$query = $this->db_smartone->query($sql, [$order['T_OrderHeaderID']]);
|
|
if(!$query)
|
|
{
|
|
$this->sys_error_db("GET ORDER DETAIL PROMISES", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$order_detail_promises = $query->result_array();
|
|
if(count($order_detail_promises) == 0){
|
|
$order_detail_promises = [];
|
|
}
|
|
|
|
$result = [
|
|
"order" => $order,
|
|
"tests" => $test_refers,
|
|
"samples" => $samples,
|
|
"order_promises" => $order_promises,
|
|
"order_detail_promises" => $order_detail_promises
|
|
];
|
|
$this->sys_ok($result);
|
|
|
|
}
|
|
|
|
|
|
function sendToLocal()
|
|
{
|
|
|
|
$prm = $this->sys_input;
|
|
$order = $prm['order'];
|
|
$tests = $prm['tests'];
|
|
$sql = "SELECT *
|
|
FROM t_orderheader
|
|
JOIN corporate ON T_OrderHeaderCorporateID = CorporateID
|
|
WHERE T_OrderHeaderID = ?
|
|
LIMIT 1";
|
|
$query = $this->db_smartone->query($sql, [$order['T_OrderHeaderID']]);
|
|
$order_corporate = $query->row_array();
|
|
$prm['order']['CorporateName'] = $order_corporate['CorporateName'];
|
|
$prm['order']['CorporateCode'] = $order_corporate['CorporateCode'];
|
|
$prm['order']['CorporateID'] = $order_corporate['CorporateID'];
|
|
$user_id = $this->sys_user['M_UserID']?$this->sys_user['M_UserID']:0;
|
|
$log_id = -1;
|
|
if ($order['M_BranchIP'] != '' && $order['M_BranchIP'] != null && count($tests) > 0)
|
|
{
|
|
$ip = $order['M_BranchIP'];
|
|
$url = "{$ip}/one-api-lab/tools/local/r_download_local";
|
|
$sql = "INSERT INTO cpone_log.log_local(
|
|
Log_LocalT_OrderHeaderID,
|
|
Log_LocalM_BranchID,
|
|
Log_LocalUrl,
|
|
Log_LocalData,
|
|
Log_LocalCreated,
|
|
Log_LocalCreatedUserID
|
|
) VALUES (
|
|
?, ?, ?, ?, NOW(), ?
|
|
)";
|
|
$query = $this->db_smartone->query($sql, [
|
|
$order['T_OrderHeaderID'],
|
|
$order['M_BranchID'],
|
|
$url,
|
|
json_encode($prm),
|
|
$user_id
|
|
]);
|
|
if (!$query)
|
|
{
|
|
$this->sys_error_db("INSERT LOG LOCAL", $this->db_smartone);
|
|
exit;
|
|
}
|
|
$log_id = $this->db_smartone->insert_id();
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error("Pastikan pemeriksaan sudah disetting di pengerjaan lokal dan pastikan IP lokal sudah di setting");
|
|
exit;
|
|
}
|
|
|
|
$md5 = md5(json_encode($prm));
|
|
$z_param = gzdeflate(
|
|
json_encode([
|
|
"md5" => $md5,
|
|
"data" => $prm,
|
|
]),
|
|
9
|
|
);
|
|
|
|
$sql = "UPDATE cpone_log.log_local SET Log_LocalStatus = 'P' WHERE Log_LocalID = ?";
|
|
$query = $this->db_smartone->query($sql, [$log_id]);
|
|
if (!$query)
|
|
{
|
|
$this->sys_error_db("UPDATE LOG LOCAL", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$response = $this->post($url, $z_param);
|
|
$j_response = json_decode($response, true);
|
|
$status = 'D';
|
|
$message = $response;
|
|
if (!$j_response) {
|
|
$message = "Error Json : $response";
|
|
$status = 'E';
|
|
}
|
|
if ($j_response["status"] == "ERR") {
|
|
$message = $j_response["message"];
|
|
$status = 'E';
|
|
}
|
|
$sql = "UPDATE cpone_log.log_local SET Log_LocalStatus = ?, Log_LocalResponse = ? WHERE Log_LocalID = ?";
|
|
$query = $this->db_smartone->query($sql, [$status, $message, $log_id]);
|
|
if (!$query)
|
|
{
|
|
$this->sys_error_db("UPDATE LOG LOCAL", $this->db_smartone);
|
|
exit;
|
|
}
|
|
if ($status == 'D')
|
|
{
|
|
$this->sys_ok($j_response["result"]);
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error($message);
|
|
}
|
|
exit;
|
|
}
|
|
|
|
function get($url, $timeout = 60, $c_timeout = 5)
|
|
{
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$result = curl_exec($ch);
|
|
$err_msg = curl_error($ch);
|
|
if ($err_msg != "") {
|
|
return json_encode(["status" => "ERR", "message" => $err_msg]);
|
|
}
|
|
return gzinflate($result);
|
|
}
|
|
|
|
function post($url, $data, $timeout = 180, $c_timeout = 5)
|
|
{
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Content-Type: application/json",
|
|
"Content-Length: " . strlen($data),
|
|
]);
|
|
$result = curl_exec($ch);
|
|
$err_msg = curl_error($ch);
|
|
if ($err_msg != "") {
|
|
return json_encode([
|
|
"status" => "ERR",
|
|
"message" => $err_msg,
|
|
"url" => $url,
|
|
"data" => json_decode($data, true),
|
|
]);
|
|
}
|
|
return gzinflate($result);
|
|
}
|
|
}
|