SecureService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Services\Vendor\Tencent;
  3. use App\Services\Service;
  4. use TencentCloud\Cms\V20190321\CmsClient;
  5. use TencentCloud\Cms\V20190321\Models\AudioModerationRequest;
  6. use TencentCloud\Cms\V20190321\Models\ImageModerationRequest;
  7. use TencentCloud\Cms\V20190321\Models\TextModerationRequest;
  8. use TencentCloud\Common\Credential;
  9. use TencentCloud\Common\Profile\ClientProfile;
  10. use TencentCloud\Common\Profile\HttpProfile;
  11. class SecureService extends Service
  12. {
  13. // EvilFlag 0:正常 1:可疑
  14. // EvilType 100:正常
  15. // 20001:政治
  16. // 20002:色情
  17. // 20006:涉毒违法
  18. // 20007:谩骂
  19. // 20105:广告引流
  20. // 24001:暴恐
  21. // 21000:综合
  22. private $client;
  23. public function __construct()
  24. {
  25. $cred = new Credential('AKIDMXdeS40dLsBdw4QxahdNWyEJ9PbjkceL', 'oGbw73lcMzSkvvj07bsxnPn0ykJjyysa');
  26. $httpProfile = new HttpProfile();
  27. $httpProfile->setEndpoint("cms.tencentcloudapi.com");
  28. $clientProfile = new ClientProfile();
  29. $clientProfile->setHttpProfile($httpProfile);
  30. $this->client = new CmsClient($cred, "ap-guangzhou", $clientProfile);
  31. }
  32. public function text(string $text)
  33. {
  34. $req = new TextModerationRequest();
  35. $req->fromJsonString(json_encode(
  36. ['Content' => base64_encode($text)]
  37. ));
  38. $resp = $this->client->TextModeration($req);
  39. dump($resp->toJsonString());
  40. }
  41. public function image(string $url)
  42. {
  43. $req = new ImageModerationRequest();
  44. $req->fromJsonString(json_encode([
  45. 'FileUrl' => $url,
  46. ]));
  47. $resp = $this->client->ImageModeration($req);
  48. dump($resp->toJsonString());
  49. }
  50. public function voice(string $url)
  51. {
  52. $req = new AudioModerationRequest();
  53. $req->fromJsonString(json_encode([
  54. 'FileUrl' => $url,
  55. ]));
  56. $resp = $this->client->AudioModeration($req);
  57. dump($resp->toJsonString());
  58. }
  59. }