php - 如何打印从 API 生成的多个运单 pdf - Laravel
问题描述
目前,我得到了下面的代码,它按预期工作。它会在浏览器中弹出pdf运单。但是我现在想要实现的是,如何同时打印多张运单?我想在传递参数中传递更多运单号。
print_awb(630019709029);
function print_awb($awbs)
{
$url = 'http://custom_api_awb.com!print.action';
$billCode = $awbs;
$data = array('billcode' => $billCode, 'account' => 'TESTACC', 'password' => 'ACC123', 'customercode' => 'CUST1',);
$t = array('logistics_interface' => json_encode($data), 'msg_type' =>
'1', 'data_digest' => '12345');
$s = curl_init();
curl_setopt($s,CURLOPT_URL,$url);
curl_setopt($s,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
curl_setopt($s,CURLOPT_POSTFIELDS,http_build_query($t));
header('Content-type: application/pdf');
$r = curl_exec($s);
curl_close($s);
print'<pre>';print_r($r);print'</pre>';
}
这是我尝试过的代码。我试图转换数组中的传递参数。但它只是输出空白的pdf。我期待它打印两个运单。任何指针?
$awbs = array('630019709029','630019479435');
print_awb($awbs);
function print_awb($awbs)
{
for($i=0; $i<count($awbs); $i++)
{
$url = 'http://custom_api_awb.com!print.action';
$billCode = $awbs;
$data = array('billcode' => $billCode, 'account' => 'TESTACC', 'password' => 'ACC123', 'customercode' => 'CUST1',);
$t = array('logistics_interface' => json_encode($data), 'msg_type' =>
'1', 'data_digest' => '12345');
$s = curl_init();
curl_setopt($s,CURLOPT_URL,$url);
curl_setopt($s,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
curl_setopt($s,CURLOPT_POSTFIELDS,http_build_query($t));
header('Content-type: application/pdf');
$r = curl_exec($s);
curl_close($s);
print'<pre>';print_r($r);print'</pre>';
}
}
解决方案
推荐阅读
- c# - 用于 API 测试的模拟数据库
- python-3.x - python selenium find_elements 输出不正确
- visual-studio-code - Vscode:vim插件 - 超出最大调用堆栈大小
- javascript - 多个表格行中的日期
- javascript - 动态调整前元素标签的大小
- redis - Redis AOF 重写文件和 RDB 一样吗?
- typescript - 提取作为参数传递的承诺类型
- font-awesome - eKoopmans / html2pdf.js 中的 Font Awesome 未显示
- html - 如何制作响应式水平卡片?
- node.js - socket.broadcast.to().emit() 返回未定义