drymoeuka282427675 2013-12-15 12:18
浏览 36
已采纳

了解API以及如何发送正确的CURL请求

I am trying to figure out how to use Pin Payments API, function get charge.

https://pin.net.au/docs/api/charges#get-charge

As you can see they provide an example of the request using CURL

curl https://test-api.pin.net.au/1/charges/ch_bZ3RhJnIUZ8HhfvH8CCvfA -u your-secret-api-key:

I am just not sure how do I convert that to PHP, how do I pass my API key and how to pass charge ID so that the URL understood by the server.

Please help me comple the code below:

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://test-api.pin.net.au/1/charges/ch_bZ3RhJnIUZ8HhfvH8CCvfA',

));
$resp = curl_exec($curl);
curl_close($curl);
  • 写回答

1条回答 默认 最新

  • duanne9313 2013-12-15 12:24
    关注
    1. Look up the u command line parameter: http://curl.haxx.se/docs/manpage.html
      It represents the username and the password being used for the request.

    2. Look up curl_setopt(). CURLOPT_USERPWD is the option for setting these credentials:

      curl_setopt($curl, CURLOPT_USERPWD, 'apikey:');
      
      // or
      
      curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL            => 'https://test-api.pin.net.au/1/charges/ch_bZ3RhJnIUZ8HhfvH8CCvfA',
        CURLOPT_USERPWD        => 'apikey:'
      ));
      

    Please pay attention to the trailing colon! It separates the username from the password, which is empty in this case.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献