腾讯云公众人物识别API使用,附宝塔安装composer教程

最近做了个公众人物识别的小程序。用到腾讯云API的公众人物识别接口。记录下过程。 首先就是给服务器安装SDK了。我用的是PHP 腾讯云API SDK3.0的安装教程可以看官方这里 https://github.com/TencentCloud/tencentcloud-sdk-php 不知道是不是我操作的问题,安装好composer后,默认存在了root目录下,导致地址识别不到autoload.php文件。
解决办法就是把这个vendor文件夹复制一份到php5.6(我的站点用的是5.6版本,如果你的是php7就放到7的目录)下,如下图
++++++++++++++++++++++++++++++++++ 通过以上步骤,服务器的文件配置就做好了。下面主要讲下,API的star.php(自己随意命名啊)文件如何写。
<?php
$urlBase64 = $_POST['ImageBase64'];
require_once 'vendor/autoload.php';
use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Tiia\V20190529\TiiaClient;
use TencentCloud\Tiia\V20190529\Models\DetectCelebrityRequest;
try {

    $cred = new Credential("你的密匙ID", "你的密匙KEY");
    $httpProfile = new HttpProfile();
    $httpProfile->setEndpoint("tiia.tencentcloudapi.com");
      
    $clientProfile = new ClientProfile();
    $clientProfile->setHttpProfile($httpProfile);
    $client = new TiiaClient($cred, "ap-guangzhou", $clientProfile);

    $req = new DetectCelebrityRequest();
    
    $params = array(
        "ImageBase64" => $urlBase64
    );
    $req->fromJsonString(json_encode($params));

    $resp = $client->DetectCelebrity($req);

    print_r($resp->toJsonString());
}
catch(TencentCloudSDKException $e) {
    echo $e;
}

?>
写好后,吧文件传到服务器站点目录下就大功告成了。