WokerTask/vendor/tencentcloud/tencentcloud-sdk-php/examples/ecc/v20181213/ecc_ocr.php

53 lines
60 KiB
PHP
Raw Normal View History

2023-12-27 14:06:33 +08:00
<?php
require_once __DIR__.'/../../../vendor/autoload.php';
// 导入对应产品模块的client
use TencentCloud\Ecc\V20181213\EccClient;
// 导入要请求接口对应的Request类
use TencentCloud\Ecc\V20181213\Models\EHOCRRequest;
use TencentCloud\Ecc\V20181213\Models\EHOCRResponse;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Common\Credential;
// 导入可选配置类
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
try {
// 实例化一个证书对象入参需要传入腾讯云账户secretIdsecretKey
// 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。
// 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
//$cred = new Credential("", "");
$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"), getenv("TENCENTCLOUD_SECRET_KEY"));
// 实例化一个http选项可选的没有特殊需求可以跳过
$httpProfile = new HttpProfile();
//$httpProfile->setReqMethod("post"); // post请求(默认为post请求)
$httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)
$httpProfile->setEndpoint("ecc.ap-shanghai.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)
// 实例化一个client选项可选的没有特殊需求可以跳过
$clientProfile = new ClientProfile();
$clientProfile->setSignMethod("HmacSHA256"); // 指定签名算法(默认为HmacSHA256)
$clientProfile->setHttpProfile($httpProfile);
$client = new EccClient($cred, "ap-shanghai", $clientProfile);
// 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。
$req = new EHOCRRequest();
$req->InputType=1;
$req->Image = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQ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mIOSurDYN+COgYYRjFkkKra7BYwQK4oRgITCGEUiEkJITCxgILBSmQEIJCAwgINBbWMtWHHtBdXZTc/dzjfBKsNb5R0sDz+jgjeQYkkWSQrsrsAGiLGAAy1ISCEwsMAGhIYqwxFjSlBgASLGgAxFzbAcp+iLOAnoovH6tdwvP6POrbGhCZAsrcfn7+fHRVlh6raVtR0SWI6wSEgiEAkKymgkGCBgIYIpiwMESArUkgRAOUYIkiAigDBkYA5/R51boSMllcB0NWYN2GOgrLD1W1LbXZWSyuwgkSAwEkoAgYiQZAESDRSESEghFMoEQYQDxTDQAMECJCArQwdDn1vkUdSIUlqmHbiOgCMnrsrWyuxAWV2EkhJIQQJIYSSEkhJIGSLAYQGAhCCSEgIYQGSLAQgMgFdaHN6XNrfAKtUiK2RqOTZkjfMGeOvQtMdJGCh67ABoLGgqvEAaAMIsMBDAExVjQAaChwixgCEgJigNBYSiEwWMtTn7+dW8GDK6xnaPoMe/EUYuhXHQzDJHfRliWI6yQBghCIhUwMBWCQhEDASSAMgDJASRIRAwRTBEkUhCymAhOd0MVazBVqMuS2VPT4dmKNKWVDgWF64ehKrV2EmcGkZ4miUQvlCmk54XzMavmeGk5jF8oU0zOa0TPIvlML5nhoFELxRKtOeF4oFa
$resp = $client->EHOCR($req);
// 输出json格式的字符串回包
print_r($resp->toJsonString());
// 也可以取出单个值。
// 你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义
print_r($resp->TotalCount);
}
catch(TencentCloudSDKException $e) {
echo $e;
}