<?php

namespace App\Services\Vendor\Tencent;

use App\Services\Service;
use TencentCloud\Cms\V20190321\CmsClient;
use TencentCloud\Cms\V20190321\Models\AudioModerationRequest;
use TencentCloud\Cms\V20190321\Models\ImageModerationRequest;
use TencentCloud\Cms\V20190321\Models\TextModerationRequest;
use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;

class SecureService extends Service
{
//    EvilFlag  0：正常 1：可疑
//    EvilType  100：正常
//            20001：政治
//            20002：色情
//            20006：涉毒违法
//            20007：谩骂
//            20105：广告引流
//            24001：暴恐
//            21000：综合
    private $client;

    public function __construct()
    {
        $cred = new Credential('AKIDMXdeS40dLsBdw4QxahdNWyEJ9PbjkceL', 'oGbw73lcMzSkvvj07bsxnPn0ykJjyysa');
        $httpProfile = new HttpProfile();
        $httpProfile->setEndpoint("cms.tencentcloudapi.com");

        $clientProfile = new ClientProfile();
        $clientProfile->setHttpProfile($httpProfile);
        $this->client = new CmsClient($cred, "ap-guangzhou", $clientProfile);
    }

    public function text(string $text)
    {

        $req = new TextModerationRequest();
        $req->fromJsonString(json_encode(
            ['Content' => base64_encode($text)]
        ));

        $resp = $this->client->TextModeration($req);

        dump($resp->toJsonString());
    }

    public function image(string $url)
    {
        $req = new ImageModerationRequest();
        $req->fromJsonString(json_encode([
            'FileUrl' => $url,
        ]));
        $resp = $this->client->ImageModeration($req);
        dump($resp->toJsonString());
    }

    public function voice(string $url)
    {
        $req = new AudioModerationRequest();
        $req->fromJsonString(json_encode([
            'FileUrl' => $url,
        ]));
        $resp = $this->client->AudioModeration($req);
        dump($resp->toJsonString());
    }
}
