从外部API获取状态并显示在网页中

时间:2018-02-22 11:24:10

标签: php api

我正在尝试调用webservice APi并在我们的网页中显示该结果。我正在尝试下面的代码,但它没有取得状态

    <table class="tbl-qa" border="1">
          <thead>
            <tr>            
              <th class="table-header">ID</th>
              <th class="table-header">ORDERID</th>            
              <th class="table-header">Status</th>           
            </tr>
          </thead>
          <tbody id="table-body">



          <?php
$tabindex = 1;

if (!empty($orderrecords))
    {
    foreach($orderrecords as $k => $v)
        {
?>

                <?php
        $hide = '';
        $data['username'] = '';
        $data['password'] = '';
        $data['awb'] = '890927143';
        $url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order=' . $orderrecords[$k]["order_id"] . '&username=admin&password=admin123';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        curl_close($ch);
        $res = explode("\n", $output);
        if (!isset($res[13]))
            {
            $res[13] = null;
            }

        $status = $res[13];
?>         

              <tr value="" <?php
        echo $hide; ?> class="table-row" id="table-row-<?php
        echo $orderrecords[$k]["id"]; ?>" tabindex="<?php
        echo $tabindex; ?>">

              <td><input type="checkbox" onclick="assignorderids('<?php
        echo $orderrecords[$k]["order_id"]; ?>')" name="assigneeid" id="assigneeid-<?php
        echo $orderrecords[$k]["order_id"]; ?>" value="<?php
        echo $orderrecords[$k]["order_id"]; ?>"></td>

                <td>

                <?php
        echo $orderrecords[$k]["order_id"]; ?>

                </td>

             <td><?php
        echo $status; ?></td>

              </tr>
            <?php
        $tabindex++;
        }
    } ?>
          </tbody>
        </table>

如果您需要更多信息,请与我们联系。我正在使用php mysqli ....

我正在尝试使用localhost ....我是否需要在服务器中尝试使其正常工作?

1 个答案:

答案 0 :(得分:1)

根据您提供的数据,SSL证书似乎无效。 也许尝试在你的cUrl中设置它

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);