首页 > 解决方案 > 如何打印从 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>';

    }
}

标签: phplaravelpdf

解决方案


推荐阅读