0

这是我的代码

<?php //if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/libraries/REST_Controller.php";
require_once APPPATH."/libraries/echosign.php";

class Document_management extends Rest_Controller
{
  public function get_access_token_get()
  {    
    $echoSign = new EchoSign();

    $ch = curl_init('https://secure.echosign.com/api/rest/v2/auth/tokens');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($echoSign->echosign_creds));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

    $result = json_decode(curl_exec($ch));    

    curl_close($ch);    

    return $result->accessToken;
  }

  public function get_agreements_get()
  {
    $accessToken = array("Access-Token: ".$this->get_access_token_get());

    $ch = curl_init('https://secure.echosign.com:443/api/rest/v2/agreements');
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $accessToken);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);

    $result = json_decode(curl_exec($ch));

    curl_close($ch);

    $agreements = array(
        "agreementId"   => $result->userAgreementList[0]->agreementId,
        "name"          => $result->userAgreementList[0]->name,
    );    

    return $agreements;
  }

  public function get_form_data_get($headers, $agreements)
  {
    $filepath = APPPATH."files/".$agreements['name']."csv";

    $url = 'https://secure.echosign.com:443/api/rest/v2/agreements/'.$agreements['agreementId'].'/formData';

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);    
    //header("Content-type: text/csv");
    //header("Content-Disposition: attachment; filename=".$filepath);

    $result = curl_exec($ch);

    //echo "<pre>"; print_r($result); echo "</pre>"; exit();

    curl_close($ch);

  }

  public function download_file_get()
  {
    $headers = array("Access-Token: ".$this->get_access_token_get());

    $agreements = $this->get_agreements_get();

    $this->get_form_data_get($headers, $agreements);
  }


}

?>

浏览器中的输出只是以这种格式发送表单的RAW数据

"completed","email","role","first","last","title","company","agreementId","firstname","lastname" "2014-11-04 15:55:44","abe.taha@gmail.com","SIGNER","Abe","Taha","Web Developer","","2AAABLblqZhDrvBK47mPKPZW-VSAJKDHASFT42ESlPxOjYphH4C0A5_adasdasda6qnFCy2idJ8*","ABE","TAHA"

我不知道如何将流存储在变量中/甚至以某种方式将其分解以将其存储在数据库中。

我尝试使用 php://input 或 readfile 和其他选项来读取流,但不明白如何格式化数据

4

1 回答 1

1

看起来您正在使用 EchoSign REST API GET /agreements/{agreementId}/formData,并希望获得有关其输出的更多详细信息。上述调用会生成一个 CSV(逗号分隔文件)。

如果调用成功,此返回参数将包含逗号分隔的表单数据值,每条记录由换行符分隔。第一行将始终包含标题值 - 即所有列的键。

在密钥agreementId引用特定协议的情况下,该协议的每个签名者将有另一行,该行中的每个项目都是该签名者输入的表单值,对应于适当的标题。

于 2015-01-13T15:18:47.150 回答