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

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

这是我的代码,我把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);

  1. And try and conect it here
  1. $key = 'xxx';
  2. $secret = 'xxx';
  3. $workspace = ' xxx';
  4. $resource = 'templates/xxx/output';
  5. $documentData = $data;
  6. $data1 = [
  7. 'key' => $key,
  8. 'resource' => $resource,
  9. 'workspace' => $workspace
  10. ];
  11. ksort($data1);
  12. $signature = hash_hmac('sha256', implode('', $data1), $secret);
  13. $client = new \GuzzleHttp\Client([
  14. 'base_uri' => 'https://us1.pdfgeneratorapi.com/api/v3/'
  15. ]);
  16. /**
  17. * Authentication params sent in headers
  18. */
  19. $response = $client->request('POST', $resource, [
  20. 'body' => $documentData,
  21. 'query' => [
  22. 'format' => 'pdf',
  23. 'output' => 'base64'
  24. ],
  25. 'headers' => [
  26. 'X-Auth-Key' => $key,
  27. 'X-Auth-Workspace' => $workspace,
  28. 'X-Auth-Signature' => $signature,
  29. 'Accept' => 'application/json',
  30. 'Content-Type' => 'application/json; charset=utf-8',
  31. ]
  32. ]);
  33. /**
  34. * Authentication params sent in query string
  35. */
  36. $response = $client->request('POST', $resource, [
  37. 'body' => $documentData,
  38. 'query' => [
  39. 'key' => $key,
  40. 'workspace' => $workspace,
  41. 'signature' => $signature,
  42. 'format' => 'pdf',
  43. 'output' => 'base64'
  44. ]
  45. ]);
  46. $contents = $response->getBody()->getContents();
  1. I thought this would generate my doc
  1. {
  2. "response": "JVBERi0xLjcKJeLjz9MKNyAwIG9iago8PCAvVHlwZSA...",
  3. "meta": {
  4. "name": "a2bd25b8921f3dc7a440fd7f427f90a4.pdf",
  5. "display_name": "a2bd25b8921f3dc7a440fd7f427f90a4",
  6. "encoding": "base64",
  7. "content-type": "application\/pdf"
  8. }
  9. }

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

暂无答案!

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

相关问题