WordChange.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\queue\redis;
  3. use app\extra\tools\CodeExtend;
  4. use app\model\saas\SaasWordChange;
  5. use Webman\RedisQueue\Consumer;
  6. use yzh52521\EasyHttp\Http;
  7. class WordChange implements Consumer
  8. {
  9. public $queue = "word-change";
  10. public $connection = "default";
  11. public function consume($data): bool
  12. {
  13. print_r($data);
  14. $change = (new SaasWordChange)->where("key",md5($data['key']))->findOrEmpty();
  15. if ($change->isEmpty()) return true;
  16. if ($change['status'] == 1) return true;
  17. if ($data['ext'] !== 'pdf') {
  18. $pathUri = [];
  19. for ($i = 1; $i <= $data['total']; $i ++) {
  20. $pathUri[$i] = "https://".sConf("storage.cos_http_domain")."/".$data['key']."?ci-process=doc-preview&dstType=png&imageDpi=300&page={$i}";
  21. }
  22. $resp = Http::asJson()->withHeaders(['x-api-key' => "your-api-key-here"])->post("http://127.0.0.1:3000/api/images-to-pdf",[
  23. "imageUrls" => array_values($pathUri),
  24. "pdfName" => "upload_".CodeExtend::uniqidDate(18),
  25. "options" => [
  26. "compression" => false,
  27. "quality" => 100
  28. ]
  29. ])->array();
  30. echo getDateFull()."==={$data['key']}===word转码\n";
  31. print_r($resp);
  32. $path = $resp['data']['pdfUrl'];
  33. $change->status = 1;
  34. $change->path = $path;
  35. $change->save();
  36. }
  37. return true;
  38. }
  39. }