"M24020076", //合約單號 "BillDate" => 20210420, //簽約日期 "TypeId" => "SO", // "FOrgId" => "1000", "OrgId" => "1000", "ModeId" => "M", // T汰改 M新梯 "BizPartnerId" => "M24020076", //客戶代碼 "CurrId" => "TWD", "CurrOAmount" => 1, "CurrLAmount" => 1, "PersonId" => "M0225", //業務人員 "DueToId" => "M24020076", //債務方 "TradeConditionId" => "", "TaxId" => "ST005", "CreditorCompId" => "1001", "CreditorOrgId" => "1000", // "CompId" => "1001", // "CreditorCurrOAmount" => 1, // "CreditorCurrLAmount" => 1 ]; // //salSalesOrderDetail // $SubOrder_row = []; for ($i = 0; $i < 3; $i++) { if ($i == 0) { $row = [ // "SupplyCompId" => "1001", // "SupplyOrgId" => "1000", "TaxId" => "ST005", "RequirementDate" => 20210420, //出貨日期 "ConsignmentDate" => 20210420, //發貨日期 // "DispatchCompId" => "1001", // "DispatchOrgId" => "1000", "BillNo" => "M24020076", //合約號 "RowCode" => $i, //全部筆數排列 "ItemType" => 1, "MaterialId" => "A40001", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) "SUnitId" => "SET", "SQuantity" => 1, //交易數量 "SPrice" => 50000 //交易價格 ]; } if ($i == 1) { $row = [ // "SupplyCompId" => "1001", // "SupplyOrgId" => "1000", "TaxId" => "ST005", "RequirementDate" => 20210420, //出貨日期 "ConsignmentDate" => 20210420, //發貨日期 // "DispatchCompId" => "1001", // "DispatchOrgId" => "1000", "BillNo" => "M24020076", //合約號 "RowCode" => $i, //全部筆數排列 "ItemType" => 1, "MaterialId" => "A40008", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) "SUnitId" => "SET", "SQuantity" => 1, //交易數量 "SPrice" => 700000 //交易價格 ]; } if ($i == 2) { $row = [ // "SupplyCompId" => "1001", // "SupplyOrgId" => "1000", "TaxId" => "ST005", "RequirementDate" => 20210420, //出貨日期 "ConsignmentDate" => 20210420, //發貨日期 // "DispatchCompId" => "1001", // "DispatchOrgId" => "1000", "BillNo" => "M24020076", //合約號 "RowCode" => $i, //全部筆數排列 "ItemType" => 0, "MaterialId" => "4MH00669", //1.設備(A40001)、2.安裝(A4008)、3.作番號(作番) "SUnitId" => "SET", "SQuantity" => 1, //交易數量 "SPrice" => 0 //交易價格 ]; } $SubOrder_row[] = $row; } // // $salOrderStagePay_row = []; // // // for ($i = 0; $i < 2; $i) { // // // if ($i == 0) { // // // $row = [ // // // "BillNo" => "M24010201", // // // "RowCode" => 1, // // // "RowNo" => 1, // // // "PayStage" => "簽約", //收款階段 // // // "PlanPercentage" => 0.10, //計劃收款比例(%) // // // "PlanPayAmt" => 100000, //計劃收款金額 // // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 // // // "UnWriteOffOAmount" => 100000 //未核銷金額 // // // ]; // // // } // // // if ($i == 1) { // // // $row = [ // // // "BillNo" => "M24010201", // // // "RowCode" => 1, // // // "RowNo" => 1, // // // "PayStage" => "貨抵工地", //收款階段 // // // "PlanPercentage" => 0.40, //計劃收款比例(%) // // // "PlanPayAmt" => 100000, //計劃收款金額 // // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 // // // "UnWriteOffOAmount" => 100000 //未核銷金額 // // // ]; // // // } // // // if ($i == 2) { // // // $row = [ // // // "BillNo" => "M24010201", // // // "RowCode" => 1, // // // "RowNo" => 1, // // // "PayStage" => "試車完工", //收款階段 // // // "PlanPercentage" => 0.30, //計劃收款比例(%) // // // "PlanPayAmt" => 100000, //計劃收款金額 // // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 // // // "UnWriteOffOAmount" => 100000 //未核銷金額 // // // ]; // // // } // // // if ($i == 3) { // // // $row = [ // // // "BillNo" => "M24010201", // // // "RowCode" => 1, // // // "RowNo" => 1, // // // "PayStage" => "交車", //收款階段 // // // "PlanPercentage" => 0.20, //計劃收款比例(%) // // // "PlanPayAmt" => 100000, //計劃收款金額 // // // "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 // // // "UnWriteOffOAmount" => 100000 //未核銷金額 // // // ]; // // // } // // // $salOrderStagePay_row[] = $row; // // // } $salOrderStagePay_row = []; $roww = [ "PayStage" => "簽約", //收款階段 "PlanPercentage" => 0.5, //計劃收款比例(%) "PlanPayAmt" => 375000, //計劃收款金額 "PlanPayDate" => 20240101, //計劃收款日期 1.第一筆都是簽約日 "BillNo" => "M24020076", "RowCode" => 1, "RowNo" => 1, "UnWriteOffOAmount" => 375000 //未核銷金額 ]; $roww2 = [ "PayStage" => "貨抵工地", "PlanPercentage" => 0.5, "PlanPayAmt" => 375000, "PlanPayDate" => 20240101, "BillNo" => "M24020076", "RowCode" => 2, "RowNo" => 2, "UnWriteOffOAmount" => 375000 ]; $salOrderStagePay_row[] = $roww; $MainSalesOrder = [ "name" => "MainSalesOrder", 'rows' => [$MainSalesOrder_row] ]; $SubOrder = [ "name" => "SubOrder", "rows" => $SubOrder_row ]; $salOrderStagePay = [ "name" => "salOrderStagePay", "rows" => $salOrderStagePay_row ]; $APIbody = []; $APIbody[] = $MainSalesOrder; $APIbody[] = $SubOrder; $APIbody[] = $salOrderStagePay; // $data = file_get_contents('test copy.json'); // $arr = json_decode($data, true); // echo "
";
// print_r($data);
// echo "
"; // echo "
";
// print_r(json_encode($APIbody, JSON_UNESCAPED_UNICODE));
// echo "
"; // exit(); $header = [ "CHI_Authorization :" . $validation, "GroupId:TEST" ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_url); // 设置请求的URL curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($APIbody, JSON_UNESCAPED_UNICODE)); $response = curl_exec($ch); if ($response === false) { echo 'Curl error: ' . curl_error($ch); } else { $result = json_decode($response, true); // 若 API 傳入失敗。 if ($result['Status'] == 'Erroe') { echo 'API傳入失敗,' . $result['ErrorMsg']; print_r($result); } else { // print_r($result); print_r($result); } print_r($result); } curl_close($ch);