dtvdz911959
2018-11-25 06:34
浏览 43
已采纳

使用curl获取成功消息后更新数据库中的值

i am getting below message after passing values in url with curl:

{"AddManifestDetails":[{"AuthKey":"Valid","ReturnMessage":"successful",}]

If ReturnMessage is successful , than i want to update values in database, i tried below code :

<?php

$data = 
array (
'OrderNo' => $order_id,
'AirWayBillNO' => $resultc[0]['awb'],
);

$url = "http://114.143.206.69:803/StandardForwardStagingService.svc/AddManifestDetails";

$data = json_encode($data);
$curl = curl_init($url);

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$curl_response = curl_exec($curl);
curl_close($curl);
echo $curl_response ."
";
$res=json_decode($curl_response);

foreach ($res->curl_response as $values) 
{
if($values->ReturnMessage=='successful')
    {
      $usql="update  do_order set tracking_id='".$resultc[0]['awb']."',shipping_name='xpress', where order_id='".$order_id."'";       
      $result=$db_handle->executeUpdate($usql);  
      echo "1";die;
    }
    else
    {
      echo $values->ReturnMessage;die;
    }
}

Here is full code : https://pastebin.com/EvcEY0xp

Result :

Notice: Undefined property: stdClass::$curl_response

Warning: Invalid argument supplied for foreach()

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douying9296 2018-11-25 06:49
    已采纳

    $res will already contain decoded response from curl request, which will have only 1 property - AddManifestDetails.

    Try following:

    <?php
    
    $data = 
    array (
    'OrderNo' => $order_id,
    'AirWayBillNO' => $resultc[0]['awb'],
    );
    
    $url = "http://114.143.206.69:803/StandardForwardStagingService.svc/AddManifestDetails";
    
    $data = json_encode($data);
    $curl = curl_init($url);
    
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    
    $curl_response = curl_exec($curl);
    curl_close($curl);
    echo $curl_response ."
    ";
    $res=json_decode($curl_response);
    
    if($res->AddManifestDetails[0]->ReturnMessage=='successful')
    {
        $usql="update  do_order set tracking_id='".$resultc[0]['awb']."',shipping_name='xpress' where order_id='".$order_id."'";       
        $result=$db_handle->executeUpdate($usql);  
        echo "1";
        die;
    }
    else
    {
        echo $res->AddManifestDetails[0]->ReturnMessage;
        die;
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题