dongshuo2752
2018-08-28 13:13
浏览 134
已采纳

将curl响应保存到数据库中

I am getting this response

[{"id":15702671,"payment_id":15702666,"amount":20,"metadata":{},"source":{"id":"347862165","name":"Test Test","type":"collector"},"date_created":"2018-08-28T08:11:15.000-04:00","unique_sequence_number":null,"status":"approved"}]

This is my Code

$url = "https://api.mercadopago.com/v1/payments/".$paymeny_id."/refunds?access_token=TEST-4015220099523401-082300-232be80199d9b1a9b0bac72d6af99fd2-347862165";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
curl_close($ch);

how to save response value in variable ?

图片转代码服务由CSDN问答提供 功能建议

我收到此回复

  [{“id”  :15702671,“payment_id”:15702666,“amount”:20,“metadata”:{},“source”:{“id”:“347862165”,“name”:“Test Test”,“type”:“collector”  “},” DATE_CREATED “:” 2018-08-28T08:11:15.000-04:00" , “unique_sequence_number”:NULL, “状态”: “已批准”}] 
上  
  
 

这是我的代码

  $ url =“https://api.mercadopago.com/v1/payments/".$paymeny_id."/refunds?  access_token = TEST-4015220099523401-082300-232be80199d9b1a9b0bac72d6af99fd2-347862165“; 
 $ ch = curl_init(); 
curl_setopt($ ch,CURLOPT_URL,$ url); 
 $ output = curl_exec($ ch); 
curl_close($ ch  ); 
   
 
 

如何在变量中保存响应值?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douwei7471 2018-08-28 13:15
    已采纳

    try this

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $var = curl_exec($ch)
    

    Hope this works!

    to get the id

    $var = json_decode($var);
    $id = $var[0]->id;
    
    已采纳该答案
    打赏 评论
  • dqenv99518 2018-08-28 13:17

    you need to add CURLOPT_RETURNTRANSFER option in your curl object to get the response using curl as

    $url = "https://api.mercadopago.com/v1/payments/".$paymeny_id."/refunds?access_token=TEST-4015220099523401-082300-232be80199d9b1a9b0bac72d6af99fd2-347862165";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    
    打赏 评论

相关推荐 更多相似问题