有人知道pdfgeneratorapi.com的诀窍吗?我正试图通过服务器链接从api数据生成pdf,但不断出错

zi8p0yeb  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(251)

这是我的代码,我把KnackAPI拉到这里
//抓取记录以填充模板$response=requests::get('https://api.knack.com/v1/objects/“.$knack\u object\u id./records/”.$knack\u record\u id,$headers)$data=json_decode($response->body);

And try and conect it here
$key = 'xxx';
  $secret = 'xxx';
  $workspace = ' xxx';
  $resource = 'templates/xxx/output';
  $documentData =  $data;

  $data1 = [
    'key' => $key,
    'resource' => $resource,
    'workspace' => $workspace
  ];
  ksort($data1);

  $signature = hash_hmac('sha256', implode('', $data1), $secret);

  $client = new \GuzzleHttp\Client([
      'base_uri' => 'https://us1.pdfgeneratorapi.com/api/v3/'
  ]);

  /**
   * Authentication params sent in headers
   */
  $response = $client->request('POST', $resource, [
    'body' => $documentData,
    'query' => [
      'format' => 'pdf',
      'output' => 'base64'
    ],
    'headers' => [
      'X-Auth-Key' => $key,
      'X-Auth-Workspace' => $workspace,
      'X-Auth-Signature' => $signature,
      'Accept' => 'application/json',
      'Content-Type' => 'application/json; charset=utf-8',
    ]
  ]);

  /**
   * Authentication params sent in query string
   */
  $response = $client->request('POST', $resource, [
    'body' => $documentData,
    'query' => [
      'key' => $key,
      'workspace' => $workspace,
      'signature' => $signature,
      'format' => 'pdf',
      'output' => 'base64'
    ]
  ]);

  $contents = $response->getBody()->getContents();
I thought this would generate my doc
{
  "response": "JVBERi0xLjcKJeLjz9MKNyAwIG9iago8PCAvVHlwZSA...",
  "meta": {
    "name": "a2bd25b8921f3dc7a440fd7f427f90a4.pdf",
    "display_name": "a2bd25b8921f3dc7a440fd7f427f90a4",
    "encoding": "base64",
    "content-type": "application\/pdf"
  }
}

我想连接这两个API并返回一个文档。这将返回一个500错误。我从网站上获得了大部分代码,但我相信我把它理解错了

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题