UploadFiles.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. require_once __DIR__.'/../../../vendor/autoload.php';
  3. use TencentCloud\Essbasic\V20201222\EssbasicClient;
  4. use TencentCloud\Essbasic\V20201222\Models\UploadFilesRequest;
  5. use TencentCloud\Essbasic\V20201222\Models\Caller;
  6. use TencentCloud\Essbasic\V20201222\Models\UploadFile;
  7. use TencentCloud\Common\Exception\TencentCloudSDKException;
  8. use TencentCloud\Common\Credential;
  9. use TencentCloud\Common\Profile\ClientProfile;
  10. use TencentCloud\Common\Profile\HttpProfile;
  11. try {
  12. // 实例化一个证书对象,入参需要传入腾讯云账户secretId,secretKey
  13. $cred = new Credential("********************************", "********************************");
  14. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  15. $httpProfile = new HttpProfile();
  16. $httpProfile->setReqMethod("POST"); // post请求(默认为post请求)
  17. $httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)
  18. $httpProfile->setEndpoint("file.ess.tencent.cn"); // 指定接入地域域名(默认就近接入)
  19. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  20. $clientProfile = new ClientProfile();
  21. $clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为HmacSHA256)
  22. $clientProfile->setHttpProfile($httpProfile);
  23. $client = new EssbasicClient($cred, "ap-guangzhou", $clientProfile);
  24. $req = new UploadFilesRequest();
  25. $req->setBusinessType("FLOW");
  26. $caller = new Caller();
  27. $caller->setOperatorId("********************************");
  28. $req->setCaller($caller);
  29. $file = new UploadFile();
  30. $base64_content = chunk_split(base64_encode(file_get_contents("/***/aaa.pdf")));
  31. $file->setFileBody($base64_content);
  32. $file->setFileName("aaa.pdf");
  33. $req->FileInfos = [];
  34. array_push($req->FileInfos, $file);
  35. $resp = $client->UploadFiles($req);
  36. // 输出json格式的字符串回包
  37. print_r($resp->toJsonString());
  38. }
  39. catch(TencentCloudSDKException $e) {
  40. echo $e;
  41. }