PHP:函数没有正确执行返回

时间:2017-12-30 23:17:56

标签: php

这个PHP脚本运行正常。虽然它没有正确地将值返回给调用函数(function buy_notes)。

  

错误消息“PHP注意:未定义的变量:注释”。

$server_output也没关系。 RETURN上似乎缺少或错误指定了某些内容。 有什么想法吗?

<?php
      $invester_id = "516xxxx";
      $authkey = "09CHxxxxxxxxxxxxxxxxxx";
      define("DEBUG_LENDING_API", false);
      $buy = buy_notes($invester_id, $authkey);
      print_r($buy);die;

      function buy_notes($invester_id, $authkey){
        $buy_notes_url = "https://api.lendingclub.com/api/investor/v1/accounts/$invester_id/trades/buy";
        $note[] = array("loanId" => "96188415", "orderId" => "157984483", "noteId" => "146150819", "bidPrice" => "14.37");
        //print_r(array_values($note)). "<br>";
        //exit;
        $datas = array("aid" => $invester_id, "notes" => $note);
        $buy_notes = call_curl($buy_notes_url, $authkey, json_encode($datas));
        $notes = json_decode($notes['data']);
        return $notes;
      }
      function call_curl($url, $authkey, $post = "0"){
       $ContentType = "application/json";
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0" );
       if($post != "0"){
         curl_setopt($ch,CURLOPT_POST, 1);
         curl_setopt($ch,CURLOPT_POSTFIELDS, $post);
       }
       //curl_setopt ( $ch, CURLOPT_AUTOREFERER, true );
       //curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
       $headers = array();
       $headers[] = "Authorization: $authkey";
       $headers[] = "Content-type: $ContentType";
       $headers[] = "Accept: $ContentType";
       //$headers[] = "X-LC-Application-Key: $invester_id";
       //$headers[] = "X-LC-Application-Key: ''";
       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
       $server_output = curl_exec ($ch);
       echo $server_output. "<br>";
       //exit;
       $info = curl_getinfo($ch);
       curl_close ($ch);
       if(DEBUG_LENDING_API == true){
         return array("data" => $server_output, "response" => $info);
       }else{
         return json_decode($server_output);
       }
      }
    ?>

0 个答案:

没有答案