This commit is contained in:
weiz 2024-03-06 16:52:43 +08:00
parent bc52b30165
commit efb6c5a756
107 changed files with 8193 additions and 1 deletions

View File

@ -181,7 +181,7 @@ class RemoteRequestLogic extends BaseLogic
if (!empty($ambientTemperatureDevice)) {
$rangeData = self::requestRangeMonitorData($ambientTemperatureDevice);
if (!empty($rangeData)) {
$ambientTemperatureDevice['RangeMonitorData'] = $rangeData[0];
$ambientTemperatureDevice['RangeMonitorData'] = $rangeData[1];
} else {
$ambientTemperatureDevice['RangeMonitorData'] = [0,0,0,0,0,0,0];
}

View File

@ -0,0 +1,20 @@
<?php
namespace OSS\Credentials;
use OSS\Core\OssException;
class EnvironmentVariableCredentialsProvider implements CredentialsProvider
{
/**
* @return Credentials
* @throws OssException
*/
public function getCredentials()
{
$ak= getenv('OSS_ACCESS_KEY_ID');
$sk = getenv('OSS_ACCESS_KEY_SECRET');
$token = getenv('OSS_SESSION_TOKEN');
return new Credentials($ak, $sk, $token);
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace OSS\Model;
/**
* Class Owner
*
* ListObjects return owner list of classes
* The returned data contains two arrays
* One is to get the list of objects【Can be understood as the corresponding file system file list
* One is to get owner list
*
*/
class Owner
{
/**
* OwnerInfo constructor.
* @param $id string
* @param $displayName string
*/
public function __construct($id, $displayName)
{
$this->id = $id;
$this->displayName = $displayName;
}
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getDisplayName()
{
return $this->displayName;
}
private $id;
private $displayName;
}

View File

@ -0,0 +1,12 @@
<?php
namespace OSS\Signer;
use OSS\Http\RequestCore;
use OSS\Credentials\Credentials;
interface SignerInterface
{
public function sign(RequestCore $request, Credentials $credentials, array &$options);
public function presign(RequestCore $request, Credentials $credentials, array &$options);
}

View File

@ -0,0 +1,161 @@
<?php
namespace OSS\Signer;
use OSS\Core\OssUtil;
use OSS\Http\RequestCore;
use OSS\Credentials\Credentials;
class SignerV1 implements SignerInterface
{
public function sign(RequestCore $request, Credentials $credentials, array &$options)
{
// Date
if (!isset($request->request_headers['Date'])) {
$request->add_header('Date', gmdate('D, d M Y H:i:s \G\M\T'));
}
// Credentials information
if (!empty($credentials->getSecurityToken())) {
$request->add_header("x-oss-security-token", $credentials->getSecurityToken());
}
$headers = $request->request_headers;
$method = strtoupper($request->method);
$date = $headers['Date'];
$resourcePath = $this->getResourcePath($options);
$queryString = parse_url($request->request_url, PHP_URL_QUERY);
$query = array();
if ($queryString !== null) {
parse_str($queryString, $query);
}
$stringToSign = $this->calcStringToSign($method, $date, $headers, $resourcePath, $query);
// printf("sign str:%s" . PHP_EOL, $stringToSign);
$options['string_to_sign'] = $stringToSign;
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $credentials->getAccessKeySecret(), true));
$request->add_header('Authorization', 'OSS ' . $credentials->getAccessKeyId() . ':' . $signature);
}
public function presign(RequestCore $request, Credentials $credentials, array &$options)
{
$headers = $request->request_headers;
// Date
$expiration = $options['expiration'];
if (!isset($request->request_headers['Date'])) {
$request->add_header('Date', gmdate('D, d M Y H:i:s \G\M\T'));
}
$parsed_url = parse_url($request->request_url);
$queryString = isset($parsed_url['query']) ? $parsed_url['query'] : '';
$query = array();
if ($queryString !== null) {
parse_str($queryString, $query);
}
// Credentials information
if (!empty($credentials->getSecurityToken())) {
$query["security-token"] = $credentials->getSecurityToken();
}
$method = strtoupper($request->method);
$date = $expiration . "";
$resourcePath = $this->getResourcePath($options);
$stringToSign = $this->calcStringToSign($method, $date, $headers, $resourcePath, $query);
$options['string_to_sign'] = $stringToSign;
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $credentials->getAccessKeySecret(), true));
$query['OSSAccessKeyId'] = $credentials->getAccessKeyId();
$query['Expires'] = $date;
$query['Signature'] = $signature;
$queryString = OssUtil::toQueryString($query);
$parsed_url['query'] = $queryString;
$request->request_url = OssUtil::unparseUrl($parsed_url);
}
private function getResourcePath(array $options)
{
$resourcePath = '/';
if (strlen($options['bucket']) > 0) {
$resourcePath .= $options['bucket'] . '/';
}
if (strlen($options['key']) > 0) {
$resourcePath .= $options['key'];
}
return $resourcePath;
}
private function calcStringToSign($method, $date, array $headers, $resourcePath, array $query)
{
/*
SignToString =
VERB + "\n"
+ Content-MD5 + "\n"
+ Content-Type + "\n"
+ Date + "\n"
+ CanonicalizedOSSHeaders
+ CanonicalizedResource
Signature = base64(hmac-sha1(AccessKeySecret, SignToString))
*/
$contentMd5 = '';
$contentType = '';
// CanonicalizedOSSHeaders
$signheaders = array();
foreach ($headers as $key => $value) {
$lowk = strtolower($key);
if (strncmp($lowk, "x-oss-", 6) == 0) {
$signheaders[$lowk] = $value;
} else if ($lowk === 'content-md5') {
$contentMd5 = $value;
} else if ($lowk === 'content-type') {
$contentType = $value;
}
}
ksort($signheaders);
$canonicalizedOSSHeaders = '';
foreach ($signheaders as $key => $value) {
$canonicalizedOSSHeaders .= $key . ':' . $value . "\n";
}
// CanonicalizedResource
$signquery = array();
foreach ($query as $key => $value) {
if (in_array($key, $this->signKeyList)) {
$signquery[$key] = $value;
}
}
ksort($signquery);
$sortedQueryList = array();
foreach ($signquery as $key => $value) {
if (strlen($value) > 0) {
$sortedQueryList[] = $key . '=' . $value;
} else {
$sortedQueryList[] = $key;
}
}
$queryStringSorted = implode('&', $sortedQueryList);
$canonicalizedResource = $resourcePath;
if (!empty($queryStringSorted)) {
$canonicalizedResource .= '?' . $queryStringSorted;
}
return $method . "\n" . $contentMd5 . "\n" . $contentType . "\n" . $date . "\n" . $canonicalizedOSSHeaders . $canonicalizedResource;
}
private $signKeyList = array(
"acl", "uploads", "location", "cors",
"logging", "website", "referer", "lifecycle",
"delete", "append", "tagging", "objectMeta",
"uploadId", "partNumber", "security-token", "x-oss-security-token",
"position", "img", "style", "styleName",
"replication", "replicationProgress",
"replicationLocation", "cname", "bucketInfo",
"comp", "qos", "live", "status", "vod",
"startTime", "endTime", "symlink",
"x-oss-process", "response-content-type", "x-oss-traffic-limit",
"response-content-language", "response-expires",
"response-cache-control", "response-content-disposition",
"response-content-encoding", "udf", "udfName", "udfImage",
"udfId", "udfImageDesc", "udfApplication",
"udfApplicationLog", "restore", "callback", "callback-var", "qosInfo",
"policy", "stat", "encryption", "versions", "versioning", "versionId", "requestPayment",
"x-oss-request-payer", "sequential",
"inventory", "inventoryId", "continuation-token", "asyncFetch",
"worm", "wormId", "wormExtend", "withHashContext",
"x-oss-enable-md5", "x-oss-enable-sha1", "x-oss-enable-sha256",
"x-oss-hash-ctx", "x-oss-md5-ctx", "transferAcceleration",
"regionList", "cloudboxes", "x-oss-ac-source-ip", "x-oss-ac-subnet-mask", "x-oss-ac-vpc-id", "x-oss-ac-forward-allow",
"metaQuery", "resourceGroup", "rtc", "x-oss-async-process", "responseHeader"
);
}

View File

@ -0,0 +1,244 @@
<?php
namespace OSS\Signer;
use DateTime;
use OSS\Core\OssUtil;
use OSS\Http\RequestCore;
use OSS\Credentials\Credentials;
use OSS\OssClient;
class SignerV4 implements SignerInterface
{
public function sign(RequestCore $request, Credentials $credentials, array &$options)
{
// Date
if (!isset($request->request_headers['Date'])) {
$request->add_header('Date', gmdate('D, d M Y H:i:s \G\M\T'));
}
$timestamp = strtotime($request->request_headers['Date']);
if ($timestamp === false) {
$timestamp = time();
}
$datetime = gmdate('Ymd\THis\Z', $timestamp);
$date = substr($datetime, 0, 8);
$request->add_header("x-oss-date", $datetime);
if (!isset($request->request_headers['x-oss-content-sha256'])) {
$request->add_header("x-oss-content-sha256", 'UNSIGNED-PAYLOAD');
}
// Credentials information
if (!empty($credentials->getSecurityToken())) {
$request->add_header("x-oss-security-token", $credentials->getSecurityToken());
}
$headers = $request->request_headers;
$method = strtoupper($request->method);
$region = $options['region'];
$product = $options['product'];
$scope = $this->buildScope($date, $region, $product);
$resourcePath = $this->getResourcePath($options);
$additionalHeaders = $this->getCommonAdditionalHeaders($request, $options);
$queryString = parse_url($request->request_url, PHP_URL_QUERY);
$query = array();
if ($queryString !== null) {
parse_str($queryString, $query);
}
$canonicalRequest = $this->calcCanonicalRequest($method, $resourcePath, $query, $headers, $additionalHeaders);
$stringToSign = $this->calcStringToSign($datetime, $scope, $canonicalRequest);
// printf('canonical request:%s' . PHP_EOL, $canonicalRequest);
// printf('sign str:%s' . PHP_EOL, $stringToSign);
$options['string_to_sign'] = $stringToSign;
$signature = $this->calcSignature($credentials->getAccessKeySecret(), $date, $region, $product, $stringToSign);
$authorization = 'OSS4-HMAC-SHA256 Credential=' . $credentials->getAccessKeyId() . '/' . $scope;
$additionalHeadersString = implode(';', $additionalHeaders);
if ($additionalHeadersString !== '') {
$authorization .= ',AdditionalHeaders=' . $additionalHeadersString;
}
$authorization .= ',Signature=' . $signature;
$request->add_header('Authorization', $authorization);
}
public function presign(RequestCore $request, Credentials $credentials, array &$options)
{
if (!isset($request->request_headers['Date'])) {
$request->add_header('Date', gmdate('D, d M Y H:i:s \G\M\T'));
}
$timestamp = strtotime($request->request_headers['Date']);
if ($timestamp === false) {
$timestamp = time();
}
$datetime = gmdate('Ymd\THis\Z', $timestamp);
$expiration = $options['expiration'];
$date = substr($datetime, 0, 8);
$expires = $expiration - $timestamp;
$headers = $request->request_headers;
$method = strtoupper($request->method);
$region = $options['region'];
$product = $options['product'];
$scope = $this->buildScope($date, $region, $product);
$resourcePath = $this->getResourcePath($options);
$additionalHeaders = $this->getCommonAdditionalHeaders($request, $options);
$queryString = parse_url($request->request_url, PHP_URL_QUERY);
$query = array();
if ($queryString !== null) {
parse_str($queryString, $query);
}
if (!empty($credentials->getSecurityToken())) {
$query["x-oss-security-token"] = $credentials->getSecurityToken();
}
$query["x-oss-signature-version"] = 'OSS4-HMAC-SHA256';
$query["x-oss-date"] = $datetime;
$query["x-oss-expires"] = $expires;
$query["x-oss-credential"] = $credentials->getAccessKeyId() . '/' . $scope;
if (count($additionalHeaders) > 0) {
$query["x-oss-additional-headers"] = implode(";", $additionalHeaders);
}
$canonicalRequest = $this->calcCanonicalRequest($method, $resourcePath, $query, $headers, $additionalHeaders);
$stringToSign = $this->calcStringToSign($datetime, $scope, $canonicalRequest);
// printf('canonical request:%s' . PHP_EOL, $canonicalRequest);
// printf('sign str:%s' . PHP_EOL, $stringToSign);
$options['string_to_sign'] = $stringToSign;
$signature = $this->calcSignature($credentials->getAccessKeySecret(), $date, $region, $product, $stringToSign);
$query["x-oss-signature"] = $signature;
$queryStr = OssUtil::toQueryString($query);
$explodeUrl = explode('?', $request->request_url);
$index = count($explodeUrl);
if ($index === 1) {
$request->request_url .= '?' . $queryStr;
} else {
$baseUrl = $explodeUrl[0];
$request->request_url = $baseUrl . '?' . $queryStr;
}
}
private function getResourcePath(array $options)
{
$resourcePath = '/';
if (strlen($options['bucket']) > 0) {
$resourcePath .= $options['bucket'] . '/';
}
if (strlen($options['key']) > 0) {
$resourcePath .= $options['key'];
}
return $resourcePath;
}
private function getCommonAdditionalHeaders(RequestCore $request, array $options)
{
if (isset($options[OssClient::OSS_ADDITIONAL_HEADERS])) {
$addHeaders = array();
foreach ($options[OssClient::OSS_ADDITIONAL_HEADERS] as $key) {
$lowk = strtolower($key);
if ($this->isDefaultSignedHeader($lowk)) {
continue;
}
$addHeaders[$lowk] = '';
}
$headers = array();
foreach ($request->request_headers as $key => $value) {
$lowk = strtolower($key);
if (isset($addHeaders[$lowk])) {
$headers[$lowk] = '';
}
}
ksort($headers);
return array_keys($headers);
}
return array();
}
private function isDefaultSignedHeader($low)
{
if (strncmp($low, "x-oss-", 6) == 0 ||
$low === "content-type" ||
$low === "content-md5") {
return true;
}
return false;
}
private function calcStringToSign($datetime, $scope, $canonicalRequest)
{
/*
StringToSign
"OSS4-HMAC-SHA256" + "\n" +
TimeStamp + "\n" +
Scope + "\n" +
Hex(SHA256Hash(Canonical Request))
*/
$hashedRequest = hash('sha256', $canonicalRequest);
return "OSS4-HMAC-SHA256" . "\n" . $datetime . "\n" . $scope . "\n" . $hashedRequest;
}
private function calcCanonicalRequest($method, $resourcePath, array $query, array $headers, array $additionalHeaders)
{
/*
Canonical Request
HTTP Verb + "\n" +
Canonical URI + "\n" +
Canonical Query String + "\n" +
Canonical Headers + "\n" +
Additional Headers + "\n" +
Hashed PayLoad
*/
//Canonical Uri
$canonicalUri = str_replace(array('%2F'), array('/'), rawurlencode($resourcePath));
//Canonical Query
$querySigned = array();
foreach ($query as $key => $value) {
$querySigned[rawurlencode($key)] = rawurlencode($value);
}
ksort($querySigned);
$sortedQueryList = array();
foreach ($querySigned as $key => $value) {
if (strlen($value) > 0) {
$sortedQueryList[] = $key . '=' . $value;
} else {
$sortedQueryList[] = $key;
}
}
$canonicalQuery = implode('&', $sortedQueryList);
//Canonical Headers
$headersSigned = array();
foreach ($headers as $key => $value) {
$lowk = strtolower($key);
if (SignerV4::isDefaultSignedHeader($lowk) ||
in_array($lowk, $additionalHeaders)) {
$headersSigned[$lowk] = trim($value);
}
}
ksort($headersSigned);
$canonicalizedHeaders = '';
foreach ($headersSigned as $key => $value) {
$canonicalizedHeaders .= $key . ':' . $value . "\n";
}
//Additional Headers
$canonicalAdditionalHeaders = implode(';', $additionalHeaders);
$hashPayload = "UNSIGNED-PAYLOAD";
if (isset($headersSigned['x-oss-content-sha256'])) {
$hashPayload = $headersSigned['x-oss-content-sha256'];
}
$stringToSign = $method . "\n"
. $canonicalUri . "\n"
. $canonicalQuery . "\n"
. $canonicalizedHeaders . "\n"
. $canonicalAdditionalHeaders . "\n"
. $hashPayload;
return $stringToSign;
}
private function buildScope($date, $region, $product)
{
return $date . "/" . $region . "/" . $product . "/aliyun_v4_request";
}
private function calcSignature($secret, $date, $region, $product, $stringToSign)
{
$h1Key = hash_hmac("sha256", $date, "aliyun_v4" . $secret, true);
$h2Key = hash_hmac("sha256", $region, $h1Key, true);
$h3Key = hash_hmac("sha256", $product, $h2Key, true);
$h4Key = hash_hmac("sha256", "aliyun_v4_request", $h3Key, true);
return bin2hex(hash_hmac("sha256", $stringToSign, $h4Key, true));
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace OSS\Tests;
class AssumeRole extends StsBase
{
private $Action = "AssumeRole";
private $RoleArn;
private $RoleSessionName;
private $Policy;
private $DurationSeconds = "3600";
public function getAttributes()
{
return get_object_vars($this);
}
public function __set($name, $value)
{
$this->$name = $value;
}
public function __construct()
{
parent::__construct();
$this->RoleSessionName = "sts";
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace OSS\Tests;
require_once __DIR__ . '/Common.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
use OSS\Core\OssException;
class OssClientAsyncProcessObjectTest extends TestOssClientBase
{
private $bucketName;
private $client;
private $local_file;
private $object;
private $download_file;
protected function setUp(): void
{
parent::setUp();
$this->client = $this->ossClient;
$this->bucketName = $this->bucket;
$url = 'https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/video.mp4?spm=a2c4g.64555.0.0.515675979u4B8w&file=video.mp4';
$file_name = "video.mp4";
$fp = fopen($file_name, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$this->local_file = $file_name;
$this->object = "oss-example.mp4";
Common::waitMetaSync();
$this->client->uploadFile($this->bucketName, $this->object, $this->local_file);
}
protected function tearDown(): void
{
parent::tearDown();
unlink($this->local_file);
}
public function testAsyncProcessObject()
{
try {
$object = 'php-async-copy';
$process = 'video/convert,f_avi,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1'.
'|sys/saveas'.
',o_'.$this->base64url_encode($object).
',b_'.$this->base64url_encode($this->bucketName);
$result = $this->client->asyncProcessObject($this->bucketName, $this->object, $process);
}catch (OssException $e){
$this->assertEquals($e->getErrorCode(),"Imm Client");
$this->assertTrue(strpos($e->getErrorMessage(), "ResourceNotFound, The specified resource Attachment is not found") !== false);
}
}
private function base64url_encode($data)
{
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace OSS\Tests;
use OSS\Core\OssException;
use OSS\Credentials\StaticCredentialsProvider;
use OSS\Model\LifecycleConfig;
use OSS\Model\LifecycleRule;
use OSS\Model\LifecycleAction;
use OSS\OssClient;
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
class OssClientForcePathStyleTest extends TestOssClientBase
{
public function testForcePathStyle()
{
$config = array(
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4,
'hostType' => OssClient::OSS_HOST_TYPE_PATH_STYLE,
);
$this->ossClient = Common::getOssClient($config);
try {
$this->ossClient->getBucketInfo($this->bucket);
} catch (OssException $e) {
$this->assertEquals($e->getErrorCode(), "SecondLevelDomainForbidden");
$this->assertTrue(true);
}
try {
$object = "oss-php-sdk-test/upload-test-object-name.txt";
$this->ossClient->putObject($this->bucket, $object, 'hi oss');
} catch (OssException $e) {
$this->assertEquals($e->getErrorCode(), "SecondLevelDomainForbidden");
$this->assertTrue(true);
}
try {
$endpoint = Common::getEndpoint();
$endpoint = str_replace(array('http://', 'https://'), '', $endpoint);
$strUrl = $this->bucket . '.' . $endpoint . "/" . $object;
$signUrl = $this->ossClient->signUrl($this->bucket, $object, 3600);
$this->assertTrue(strpos($signUrl, $strUrl) !== false);
} catch (OssException $e) {
$this->assertFalse(true);
}
}
}

View File

@ -0,0 +1,326 @@
<?php
namespace OSS\Tests;
use OSS\Core\OssException;
use OSS\Credentials\StaticCredentialsProvider;
use OSS\Http\RequestCore;
use OSS\Http\ResponseCore;
use OSS\OssClient;
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
class OssClientPresignV4Test extends TestOssClientBase
{
protected $stsOssClient;
public function testObjectWithSignV4()
{
$object = "a.file";
$this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
$timeout = 3600;
try {
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout);
} catch (OssException $e) {
$this->assertFalse(true);
}
$request = new RequestCore($signedUrl);
$request->set_method('GET');
$request->add_header('Content-Type', '');
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertEquals(file_get_contents(__FILE__), $res->body);
sleep(1);
//testGetSignedUrlForPuttingObject
$object = "a.file";
$timeout = 3600;
try {
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "PUT");
$content = file_get_contents(__FILE__);
$request = new RequestCore($signedUrl);
$request->set_method('PUT');
$request->add_header('Content-Type', '');
$request->add_header('Content-Length', strlen($content));
$request->set_body($content);
$request->send_request();
$res = new ResponseCore($request->get_response_header(),
$request->get_response_body(), $request->get_response_code());
$this->assertTrue($res->isOK());
} catch (OssException $e) {
$this->assertFalse(true);
}
sleep(1);
// test Get SignedUrl For Putting Object From File
$file = __FILE__;
$object = "a.file";
$timeout = 3600;
$options = array('Content-Type' => 'txt');
try {
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "PUT", $options);
$request = new RequestCore($signedUrl);
$request->set_method('PUT');
$request->add_header('Content-Type', 'txt');
$request->set_read_file($file);
$request->set_read_stream_size(sprintf('%u', filesize($file)));
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertTrue($res->isOK());
} catch (OssException $e) {
$this->assertFalse(true);
}
sleep(1);
// test SignedUrl With Exception
$object = "a.file";
$timeout = 3600;
$options = array('Content-Type' => 'txt');
try {
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "POST", $options);
$this->assertTrue(false);
} catch (OssException $e) {
$this->assertTrue(true);
if (strpos($e, "method is invalid") == false) {
$this->assertTrue(false);
}
}
// test GetgenPreSignedUrl For GettingObject
$object = "a.file";
$this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
$expires = time() + 3600;
try {
$signedUrl = $this->ossClient->generatePresignedUrl($this->bucket, $object, $expires);
} catch (OssException $e) {
$this->assertFalse(true);
}
$request = new RequestCore($signedUrl);
$request->set_method('GET');
$request->add_header('Content-Type', '');
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertEquals(file_get_contents(__FILE__), $res->body);
sleep(1);
// test Get genPreSignedUrl Vs SignedUrl
$object = "object-vs.file";
$signedUrl1 = '245';
$signedUrl2 = '123';
$expiration = 0;
do {
usleep(500000);
$begin = time();
$expiration = time() + 3600;
$signedUrl1 = $this->ossClient->generatePresignedUrl($this->bucket, $object, $expiration);
$signedUrl2 = $this->ossClient->signUrl($this->bucket, $object, 3600);
$end = time();
} while ($begin != $end);
$this->assertEquals($signedUrl1, $signedUrl2);
$this->assertTrue(strpos($signedUrl1, 'x-oss-expires=') !== false);
$object = "a.file";
$options = array(
OssClient::OSS_HEADERS => array(
'name' => 'aliyun',
'email' => 'aliyun@aliyun.com',
'book' => 'english',
),
OssClient::OSS_ADDITIONAL_HEADERS => array("name", "email")
);
$this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__), $options);
$expires = time() + 3600;
try {
$signedUrl = $this->ossClient->generatePresignedUrl($this->bucket, $object, $expires, "GET", $options);
$request = new RequestCore($signedUrl);
$request->set_method('GET');
$request->add_header('Content-Type', '');
$request->add_header('name', 'aliyun');
$request->add_header('email', 'aliyun@aliyun.com');
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertEquals(file_get_contents(__FILE__), $res->body);
sleep(1);
} catch (OssException $e) {
print_r($e->getMessage());
$this->assertFalse(true);
}
try {
$signedUrl = $this->ossClient->generatePresignedUrl($this->bucket, $object, $expires);
} catch (OssException $e) {
$this->assertFalse(true);
}
$request = new RequestCore($signedUrl);
$request->set_method('GET');
$request->add_header('Content-Type', '');
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertEquals(file_get_contents(__FILE__), $res->body);
sleep(1);
}
public function testObjectWithStsClientSignV4()
{
$object = "a.file";
$this->stsOssClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
$timeout = 3600;
try {
$signedUrl = $this->stsOssClient->signUrl($this->bucket, $object, $timeout);
} catch (OssException $e) {
$this->assertFalse(true);
}
$request = new RequestCore($signedUrl);
$request->set_method('GET');
$request->add_header('Content-Type', '');
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertEquals(file_get_contents(__FILE__), $res->body);
sleep(1);
//testGetSignedUrlForPuttingObject
$object = "a.file";
$timeout = 3600;
try {
$signedUrl = $this->stsOssClient->signUrl($this->bucket, $object, $timeout, "PUT");
$content = file_get_contents(__FILE__);
$request = new RequestCore($signedUrl);
$request->set_method('PUT');
$request->add_header('Content-Type', '');
$request->add_header('Content-Length', strlen($content));
$request->set_body($content);
$request->send_request();
$res = new ResponseCore($request->get_response_header(),
$request->get_response_body(), $request->get_response_code());
$this->assertTrue($res->isOK());
} catch (OssException $e) {
$this->assertFalse(true);
}
sleep(1);
// test Get SignedUrl For Putting Object From File
$file = __FILE__;
$object = "a.file";
$timeout = 3600;
$options = array('Content-Type' => 'txt');
try {
$signedUrl = $this->stsOssClient->signUrl($this->bucket, $object, $timeout, "PUT", $options);
$request = new RequestCore($signedUrl);
$request->set_method('PUT');
$request->add_header('Content-Type', 'txt');
$request->set_read_file($file);
$request->set_read_stream_size(sprintf('%u', filesize($file)));
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertTrue($res->isOK());
} catch (OssException $e) {
$this->assertFalse(true);
}
sleep(1);
// test SignedUrl With Exception
$file = __FILE__;
$object = "a.file";
$timeout = 3600;
$options = array('Content-Type' => 'txt');
try {
$signedUrl = $this->stsOssClient->signUrl($this->bucket, $object, $timeout, "POST", $options);
$this->assertTrue(false);
} catch (OssException $e) {
$this->assertTrue(true);
if (strpos($e, "method is invalid") == false) {
$this->assertTrue(false);
}
}
// test GetgenPreSignedUrl For GettingObject
$object = "a.file";
$this->stsOssClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
$expires = time() + 3600;
try {
$signedUrl = $this->stsOssClient->generatePresignedUrl($this->bucket, $object, $expires);
} catch (OssException $e) {
$this->assertFalse(true);
}
try {
$request = new RequestCore($signedUrl);
$request->set_method('GET');
$request->add_header('Content-Type', '');
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertEquals(file_get_contents(__FILE__), $res->body);
sleep(1);
} catch (OssException $e) {
$this->assertFalse(true);
}
// test Get genPreSignedUrl Vs SignedUrl
$object = "object-vs.file";
do {
usleep(500000);
$begin = time();
$expiration = time() + 3600;
$signedUrl1 = $this->stsOssClient->generatePresignedUrl($this->bucket, $object, $expiration);
$signedUrl2 = $this->stsOssClient->signUrl($this->bucket, $object, 3600);
$end = time();
} while ($begin != $end);
$this->assertEquals($signedUrl1, $signedUrl2);
$this->assertTrue(strpos($signedUrl1, 'x-oss-expires=') !== false);
$object = "a.file";
$options = array(
OssClient::OSS_HEADERS => array(
'name' => 'aliyun',
'email' => 'aliyun@aliyun.com',
'book' => 'english',
),
OssClient::OSS_ADDITIONAL_HEADERS => array("name", "email")
);
$this->stsOssClient->putObject($this->bucket, $object, file_get_contents(__FILE__), $options);
$expires = time() + 3600;
try {
$signedUrl = $this->stsOssClient->generatePresignedUrl($this->bucket, $object, $expires, "GET", $options);
$request = new RequestCore($signedUrl);
$request->set_method('GET');
$request->add_header('Content-Type', '');
$request->add_header('name', 'aliyun');
$request->add_header('email', 'aliyun@aliyun.com');
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
$this->assertEquals(file_get_contents(__FILE__), $res->body);
sleep(1);
} catch (OssException $e) {
print_r($e->getMessage());
$this->assertFalse(true);
}
}
protected function tearDown(): void
{
$this->ossClient->deleteObject($this->bucket, "a.file");
parent::tearDown();
}
protected function setUp(): void
{
$config = array(
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4
);
$this->bucket = Common::getBucketName() . '-' . time();
$this->ossClient = Common::getOssClient($config);
$this->ossClient->createBucket($this->bucket);
Common::waitMetaSync();
$this->stsOssClient = Common::getStsOssClient($config);
Common::waitMetaSync();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,558 @@
<?php
namespace OSS\Tests;
use OSS\Http\RequestCore;
use OSS\Credentials\Credentials;
use OSS\Signer\SignerV1;
use OSS\Signer\SignerV4;
use OSS\Core\OssUtil;
class SignerTest extends \PHPUnit\Framework\TestCase
{
public function testSignerV1Header()
{
// case 1
$credentials = new Credentials("ak", "sk");
$request = new RequestCore("http://examplebucket.oss-cn-hangzhou.aliyuncs.com");
$request->set_method("PUT");
$bucket = "examplebucket";
$object = "nelson";
$request->add_header("Content-MD5", "eB5eJF1ptWaXm4bijSPyxw==");
$request->add_header("Content-Type", "text/html");
$request->add_header("x-oss-meta-author", "alice");
$request->add_header("x-oss-meta-magic", "abracadabra");
$request->add_header("x-oss-date", "Wed, 28 Dec 2022 10:27:41 GMT");
$request->add_header("Date", "Wed, 28 Dec 2022 10:27:41 GMT");
$signer = new SignerV1();
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
);
$signer->sign($request, $credentials, $signingOpt);
$signToString = "PUT\neB5eJF1ptWaXm4bijSPyxw==\ntext/html\nWed, 28 Dec 2022 10:27:41 GMT\nx-oss-date:Wed, 28 Dec 2022 10:27:41 GMT\nx-oss-meta-author:alice\nx-oss-meta-magic:abracadabra\n/examplebucket/nelson";
$this->assertEquals($signToString, $signingOpt['string_to_sign']);
$this->assertEquals('OSS ak:kSHKmLxlyEAKtZPkJhG9bZb5k7M=', $request->request_headers['Authorization']);
// case 2
$request2 = new RequestCore("http://examplebucket.oss-cn-hangzhou.aliyuncs.com?acl");
$request2->set_method("PUT");
$request2->add_header("Content-MD5", "eB5eJF1ptWaXm4bijSPyxw==");
$request2->add_header("Content-Type", "text/html");
$request2->add_header("x-oss-meta-author", "alice");
$request2->add_header("x-oss-meta-magic", "abracadabra");
$request2->add_header("x-oss-date", "Wed, 28 Dec 2022 10:27:41 GMT");
$request2->add_header("Date", "Wed, 28 Dec 2022 10:27:41 GMT");
$signer = new SignerV1();
$signingOpt2 = array(
'bucket' => $bucket,
'key' => $object,
);
$signer->sign($request2, $credentials, $signingOpt2);
$signToString = "PUT\neB5eJF1ptWaXm4bijSPyxw==\ntext/html\nWed, 28 Dec 2022 10:27:41 GMT\nx-oss-date:Wed, 28 Dec 2022 10:27:41 GMT\nx-oss-meta-author:alice\nx-oss-meta-magic:abracadabra\n/examplebucket/nelson?acl";
$this->assertEquals($signToString, $signingOpt2['string_to_sign']);
$this->assertEquals('OSS ak:/afkugFbmWDQ967j1vr6zygBLQk=', $request2->request_headers['Authorization']);
// case 3 with non-signed query
$request3 = new RequestCore("http://examplebucket.oss-cn-hangzhou.aliyuncs.com?acl&non-signed-key=value");
$request3->set_method("PUT");
$request3->add_header("Content-MD5", "eB5eJF1ptWaXm4bijSPyxw==");
$request3->add_header("Content-Type", "text/html");
$request3->add_header("x-oss-meta-author", "alice");
$request3->add_header("x-oss-meta-magic", "abracadabra");
$request3->add_header("x-oss-date", "Wed, 28 Dec 2022 10:27:41 GMT");
$request3->add_header("Date", "Wed, 28 Dec 2022 10:27:41 GMT");
$signingOpt3 = array(
'bucket' => $bucket,
'key' => $object,
);
$signer->sign($request3, $credentials, $signingOpt3);
$signToString = "PUT\neB5eJF1ptWaXm4bijSPyxw==\ntext/html\nWed, 28 Dec 2022 10:27:41 GMT\nx-oss-date:Wed, 28 Dec 2022 10:27:41 GMT\nx-oss-meta-author:alice\nx-oss-meta-magic:abracadabra\n/examplebucket/nelson?acl";
$this->assertEquals($signToString, $signingOpt3['string_to_sign']);
$this->assertEquals('OSS ak:/afkugFbmWDQ967j1vr6zygBLQk=', $request3->request_headers['Authorization']);
}
public function testSignerV1HeaderWithToken()
{
// case 1
$credentials = new Credentials("ak", "sk", "token");
$request = new RequestCore("http://examplebucket.oss-cn-hangzhou.aliyuncs.com");
$request->set_method("PUT");
$bucket = "examplebucket";
$object = "nelson";
$request->add_header("Content-MD5", "eB5eJF1ptWaXm4bijSPyxw==");
$request->add_header("Content-Type", "text/html");
$request->add_header("x-oss-meta-author", "alice");
$request->add_header("x-oss-meta-magic", "abracadabra");
$request->add_header("x-oss-date", "Wed, 28 Dec 2022 10:27:41 GMT");
$request->add_header("Date", "Wed, 28 Dec 2022 10:27:41 GMT");
$signer = new SignerV1();
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
);
$signer->sign($request, $credentials, $signingOpt);
$signToString = "PUT\neB5eJF1ptWaXm4bijSPyxw==\ntext/html\nWed, 28 Dec 2022 10:27:41 GMT\nx-oss-date:Wed, 28 Dec 2022 10:27:41 GMT\nx-oss-meta-author:alice\nx-oss-meta-magic:abracadabra\nx-oss-security-token:token\n/examplebucket/nelson";
$this->assertEquals($signToString, $signingOpt['string_to_sign']);
$this->assertEquals('OSS ak:H3PAlN3Vucn74tPVEqaQC4AnLwQ=', $request->request_headers['Authorization']);
$this->assertEquals('token', $request->request_headers['x-oss-security-token']);
// case 2
$request2 = new RequestCore("http://examplebucket.oss-cn-hangzhou.aliyuncs.com?acl");
$request2->set_method("PUT");
$request2->add_header("Content-MD5", "eB5eJF1ptWaXm4bijSPyxw==");
$request2->add_header("Content-Type", "text/html");
$request2->add_header("x-oss-meta-author", "alice");
$request2->add_header("x-oss-meta-magic", "abracadabra");
$request2->add_header("x-oss-date", "Wed, 28 Dec 2022 10:27:41 GMT");
$request2->add_header("Date", "Wed, 28 Dec 2022 10:27:41 GMT");
$signer = new SignerV1();
$signingOpt2 = array(
'bucket' => $bucket,
'key' => $object,
);
$signer->sign($request2, $credentials, $signingOpt2);
$signToString = "PUT\neB5eJF1ptWaXm4bijSPyxw==\ntext/html\nWed, 28 Dec 2022 10:27:41 GMT\nx-oss-date:Wed, 28 Dec 2022 10:27:41 GMT\nx-oss-meta-author:alice\nx-oss-meta-magic:abracadabra\nx-oss-security-token:token\n/examplebucket/nelson?acl";
$this->assertEquals($signToString, $signingOpt2['string_to_sign']);
$this->assertEquals("OSS ak:yeceHMAsgusDPCR979RJcLtd7RI=", $request2->request_headers['Authorization']);
// case 3 with non-signed query
$request3 = new RequestCore("http://examplebucket.oss-cn-hangzhou.aliyuncs.com?acl&non-signed-key=value");
$request3->set_method("PUT");
$request3->add_header("Content-MD5", "eB5eJF1ptWaXm4bijSPyxw==");
$request3->add_header("Content-Type", "text/html");
$request3->add_header("x-oss-meta-author", "alice");
$request3->add_header("x-oss-meta-magic", "abracadabra");
$request3->add_header("x-oss-date", "Wed, 28 Dec 2022 10:27:41 GMT");
$request3->add_header("Date", "Wed, 28 Dec 2022 10:27:41 GMT");
$signingOpt3 = array(
'bucket' => $bucket,
'key' => $object,
);
$signer->sign($request3, $credentials, $signingOpt3);
$signToString = "PUT\neB5eJF1ptWaXm4bijSPyxw==\ntext/html\nWed, 28 Dec 2022 10:27:41 GMT\nx-oss-date:Wed, 28 Dec 2022 10:27:41 GMT\nx-oss-meta-author:alice\nx-oss-meta-magic:abracadabra\nx-oss-security-token:token\n/examplebucket/nelson?acl";
$this->assertEquals($signToString, $signingOpt3['string_to_sign']);
$this->assertEquals('OSS ak:yeceHMAsgusDPCR979RJcLtd7RI=', $request2->request_headers['Authorization']);
}
public function testSignerV1Presign()
{
$credentials = new Credentials("ak", "sk");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/key?versionId=versionId");
$request->set_method("GET");
$bucket = "bucket";
$object = "key";
$signer = new SignerV1();
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'expiration' => 1699807420,
);
$signer->presign($request, $credentials, $signingOpt);
$parsed_url = parse_url($request->request_url);
$queryString = isset($parsed_url['query']) ? $parsed_url['query'] : '';
$query = array();
parse_str($queryString, $query);
$this->assertEquals('1699807420', $query['Expires']);
$this->assertEquals('ak', $query['OSSAccessKeyId']);
$this->assertEquals('dcLTea+Yh9ApirQ8o8dOPqtvJXQ=', $query['Signature']);
$this->assertEquals('versionId', $query['versionId']);
$this->assertEquals('/key', $parsed_url['path']);
}
public function testSignerV1PresignWithToken()
{
$credentials = new Credentials("ak", "sk", "token");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/key%2B123?versionId=versionId");
$request->set_method("GET");
$bucket = "bucket";
$object = "key+123";
$signer = new SignerV1();
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'expiration' => 1699808204,
);
$signer->presign($request, $credentials, $signingOpt);
$parsed_url = parse_url($request->request_url);
$queryString = isset($parsed_url['query']) ? $parsed_url['query'] : '';
$query = array();
parse_str($queryString, $query);
$this->assertEquals('1699808204', $query['Expires']);
$this->assertEquals('ak', $query['OSSAccessKeyId']);
$this->assertEquals('jzKYRrM5y6Br0dRFPaTGOsbrDhY=', $query['Signature']);
$this->assertEquals('versionId', $query['versionId']);
$this->assertEquals('token', $query['security-token']);
$this->assertEquals('/key%2B123', $parsed_url['path']);
}
public function testSignerV4Header()
{
// case 1
$credentials = new Credentials("ak", "sk");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/1234%2B-/123/1.txt");
$request->set_method("PUT");
$bucket = "bucket";
$object = "1234+-/123/1.txt";
$request->add_header("x-oss-head1", "value");
$request->add_header("abc", "value");
$request->add_header("ZAbc", "value");
$request->add_header("XYZ", "value");
$request->add_header("content-type", "text/plain");
$request->add_header("x-oss-content-sha256", "UNSIGNED-PAYLOAD");
$request->add_header("Date", gmdate('D, d M Y H:i:s \G\M\T', 1702743657));
$signer = new SignerV4();
$query = array();
$query["param1"] = "value1";
$query["+param1"] = "value3";
$query["|param1"] = "value4";
$query["+param2"] = "";
$query["|param2"] = "";
$query["param2"] = "";
$parsed_url = parse_url($request->request_url);
$parsed_url['query'] = OssUtil::toQueryString($query);;
$request->request_url = OssUtil::unparseUrl($parsed_url);
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'region' => 'cn-hangzhou',
'product' => 'oss',
);
$signer->sign($request, $credentials, $signingOpt);
$authPat = "OSS4-HMAC-SHA256 Credential=ak/20231216/cn-hangzhou/oss/aliyun_v4_request,Signature=e21d18daa82167720f9b1047ae7e7f1ce7cb77a31e8203a7d5f4624fa0284afe";
$this->assertEquals($authPat, $request->request_headers['Authorization']);
}
public function testSignerV4HeaderWithToken()
{
// case 1
$credentials = new Credentials("ak", "sk", "token");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/1234%2B-/123/1.txt");
$request->set_method("PUT");
$bucket = "bucket";
$object = "1234+-/123/1.txt";
$request->add_header("x-oss-head1", "value");
$request->add_header("abc", "value");
$request->add_header("ZAbc", "value");
$request->add_header("XYZ", "value");
$request->add_header("content-type", "text/plain");
$request->add_header("x-oss-content-sha256", "UNSIGNED-PAYLOAD");
$request->add_header("Date", gmdate('D, d M Y H:i:s \G\M\T', 1702784856));
$signer = new SignerV4();
$query = array();
$query["param1"] = "value1";
$query["+param1"] = "value3";
$query["|param1"] = "value4";
$query["+param2"] = "";
$query["|param2"] = "";
$query["param2"] = "";
$parsed_url = parse_url($request->request_url);
$parsed_url['query'] = OssUtil::toQueryString($query);;
$request->request_url = OssUtil::unparseUrl($parsed_url);
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'region' => 'cn-hangzhou',
'product' => 'oss',
);
$signer->sign($request, $credentials, $signingOpt);
$authPat = "OSS4-HMAC-SHA256 Credential=ak/20231217/cn-hangzhou/oss/aliyun_v4_request,Signature=b94a3f999cf85bcdc00d332fbd3734ba03e48382c36fa4d5af5df817395bd9ea";
$this->assertEquals($authPat, $request->request_headers['Authorization']);
}
public function testSignerV4AdditionalHeaders()
{
// case 1
$credentials = new Credentials("ak", "sk");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/1234%2B-/123/1.txt");
$request->set_method("PUT");
$bucket = "bucket";
$object = "1234+-/123/1.txt";
$request->add_header("x-oss-head1", "value");
$request->add_header("abc", "value");
$request->add_header("ZAbc", "value");
$request->add_header("XYZ", "value");
$request->add_header("content-type", "text/plain");
$request->add_header("x-oss-content-sha256", "UNSIGNED-PAYLOAD");
$request->add_header("Date", gmdate('D, d M Y H:i:s \G\M\T', 1702747512));
$signer = new SignerV4();
$query = array();
$query["param1"] = "value1";
$query["+param1"] = "value3";
$query["|param1"] = "value4";
$query["+param2"] = "";
$query["|param2"] = "";
$query["param2"] = "";
$parsed_url = parse_url($request->request_url);
$parsed_url['query'] = OssUtil::toQueryString($query);;
$request->request_url = OssUtil::unparseUrl($parsed_url);
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'region' => 'cn-hangzhou',
'product' => 'oss',
'additionalHeaders' => array("ZAbc", "abc")
);
$signer->sign($request, $credentials, $signingOpt);
$authPat = "OSS4-HMAC-SHA256 Credential=ak/20231216/cn-hangzhou/oss/aliyun_v4_request,AdditionalHeaders=abc;zabc,Signature=4a4183c187c07c8947db7620deb0a6b38d9fbdd34187b6dbaccb316fa251212f";
$this->assertEquals($authPat, $request->request_headers['Authorization']);
// case 1
$credentials = new Credentials("ak", "sk");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/1234%2B-/123/1.txt");
$request->set_method("PUT");
$bucket = "bucket";
$object = "1234+-/123/1.txt";
$request->add_header("x-oss-head1", "value");
$request->add_header("abc", "value");
$request->add_header("ZAbc", "value");
$request->add_header("XYZ", "value");
$request->add_header("content-type", "text/plain");
$request->add_header("x-oss-content-sha256", "UNSIGNED-PAYLOAD");
$request->add_header("Date", gmdate('D, d M Y H:i:s \G\M\T', 1702747512));
$signer = new SignerV4();
$query = array();
$query["param1"] = "value1";
$query["+param1"] = "value3";
$query["|param1"] = "value4";
$query["+param2"] = "";
$query["|param2"] = "";
$query["param2"] = "";
$parsed_url = parse_url($request->request_url);
$parsed_url['query'] = OssUtil::toQueryString($query);;
$request->request_url = OssUtil::unparseUrl($parsed_url);
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'region' => 'cn-hangzhou',
'product' => 'oss',
'additionalHeaders' => array("x-oss-no-exist", "ZAbc", "x-oss-head1", "abc")
);
$signer->sign($request, $credentials, $signingOpt);
$authPat = "OSS4-HMAC-SHA256 Credential=ak/20231216/cn-hangzhou/oss/aliyun_v4_request,AdditionalHeaders=abc;zabc,Signature=4a4183c187c07c8947db7620deb0a6b38d9fbdd34187b6dbaccb316fa251212f";
$this->assertEquals($authPat, $request->request_headers['Authorization']);
}
public function testSignerV4Presign()
{
// case 1
$credentials = new Credentials("ak", "sk");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/1234%2B-/123/1.txt");
$request->set_method("PUT");
$bucket = "bucket";
$object = "1234+-/123/1.txt";
$request->add_header("x-oss-head1", "value");
$request->add_header("abc", "value");
$request->add_header("ZAbc", "value");
$request->add_header("XYZ", "value");
$request->add_header("content-type", "application/octet-stream");
$request->add_header("Date", gmdate('D, d M Y H:i:s \G\M\T', 1702781677));
$signer = new SignerV4();
$query = array();
$query["param1"] = "value1";
$query["+param1"] = "value3";
$query["|param1"] = "value4";
$query["+param2"] = "";
$query["|param2"] = "";
$query["param2"] = "";
$parsed_url = parse_url($request->request_url);
$parsed_url['query'] = OssUtil::toQueryString($query);;
$request->request_url = OssUtil::unparseUrl($parsed_url);
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'region' => 'cn-hangzhou',
'product' => 'oss',
'expiration' => 1702782276,
);
$signer->presign($request, $credentials, $signingOpt);
$parsed_url = parse_url($request->request_url);
$queryString = isset($parsed_url['query']) ? $parsed_url['query'] : '';
$query = array();
parse_str($queryString, $query);
$this->assertEquals('OSS4-HMAC-SHA256', $query['x-oss-signature-version']);
$this->assertEquals('OSS4-HMAC-SHA256', $query['x-oss-signature-version']);
$this->assertEquals('599', $query['x-oss-expires']);
$this->assertEquals('ak/20231217/cn-hangzhou/oss/aliyun_v4_request', $query['x-oss-credential']);
$this->assertEquals('a39966c61718be0d5b14e668088b3fa07601033f6518ac7b523100014269c0fe', $query['x-oss-signature']);
$this->assertFalse(isset($query['x-oss-additional-headers']));
}
public function testSignerV4PresignWithToken()
{
// case 1
$credentials = new Credentials("ak", "sk", "token");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/1234%2B-/123/1.txt");
$request->set_method("PUT");
$bucket = "bucket";
$object = "1234+-/123/1.txt";
$request->add_header("x-oss-head1", "value");
$request->add_header("abc", "value");
$request->add_header("ZAbc", "value");
$request->add_header("XYZ", "value");
$request->add_header("content-type", "application/octet-stream");
$request->add_header("Date", gmdate('D, d M Y H:i:s \G\M\T', 1702785388));
$signer = new SignerV4();
$query = array();
$query["param1"] = "value1";
$query["+param1"] = "value3";
$query["|param1"] = "value4";
$query["+param2"] = "";
$query["|param2"] = "";
$query["param2"] = "";
$parsed_url = parse_url($request->request_url);
$parsed_url['query'] = OssUtil::toQueryString($query);;
$request->request_url = OssUtil::unparseUrl($parsed_url);
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'region' => 'cn-hangzhou',
'product' => 'oss',
'expiration' => 1702785987,
);
$signer->presign($request, $credentials, $signingOpt);
$parsed_url = parse_url($request->request_url);
$queryString = isset($parsed_url['query']) ? $parsed_url['query'] : '';
$query = array();
parse_str($queryString, $query);
$this->assertEquals('OSS4-HMAC-SHA256', $query['x-oss-signature-version']);
$this->assertEquals('599', $query['x-oss-expires']);
$this->assertEquals('ak/20231217/cn-hangzhou/oss/aliyun_v4_request', $query['x-oss-credential']);
$this->assertEquals('3817ac9d206cd6dfc90f1c09c00be45005602e55898f26f5ddb06d7892e1f8b5', $query['x-oss-signature']);
$this->assertFalse(isset($query['x-oss-additional-headers']));
//print($request->request_url);
}
public function testSignerV4PresignWithAdditionalHeaders()
{
// case 1
$credentials = new Credentials("ak", "sk");
$request = new RequestCore("http://bucket.oss-cn-hangzhou.aliyuncs.com/1234%2B-/123/1.txt");
$request->set_method("PUT");
$bucket = "bucket";
$object = "1234+-/123/1.txt";
$request->add_header("x-oss-head1", "value");
$request->add_header("abc", "value");
$request->add_header("ZAbc", "value");
$request->add_header("XYZ", "value");
$request->add_header("content-type", "application/octet-stream");
$request->add_header("Date", gmdate('D, d M Y H:i:s \G\M\T', 1702783809));
$signer = new SignerV4();
$query = array();
$query["param1"] = "value1";
$query["+param1"] = "value3";
$query["|param1"] = "value4";
$query["+param2"] = "";
$query["|param2"] = "";
$query["param2"] = "";
$parsed_url = parse_url($request->request_url);
$parsed_url['query'] = OssUtil::toQueryString($query);;
$request->request_url = OssUtil::unparseUrl($parsed_url);
$signingOpt = array(
'bucket' => $bucket,
'key' => $object,
'region' => 'cn-hangzhou',
'product' => 'oss',
'expiration' => 1702784408,
'additionalHeaders' => array("ZAbc", "abc")
);
$signer->presign($request, $credentials, $signingOpt);
$parsed_url = parse_url($request->request_url);
$queryString = isset($parsed_url['query']) ? $parsed_url['query'] : '';
$query = array();
parse_str($queryString, $query);
$this->assertEquals('OSS4-HMAC-SHA256', $query['x-oss-signature-version']);
$this->assertEquals('20231217T033009Z', $query['x-oss-date']);
$this->assertEquals('599', $query['x-oss-expires']);
$this->assertEquals('ak/20231217/cn-hangzhou/oss/aliyun_v4_request', $query['x-oss-credential']);
$this->assertEquals('6bd984bfe531afb6db1f7550983a741b103a8c58e5e14f83ea474c2322dfa2b7', $query['x-oss-signature']);
$this->assertEquals('abc;zabc', $query['x-oss-additional-headers']);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace OSS\Tests;
class StsBase
{
protected $SignatureVersion = "1.0";
protected $Version = "2015-04-01";
protected $Timestamp;
protected $SignatureMethod = "HMAC-SHA1";
protected $Format = "JSON";
protected $AccessKeyId;
protected $SignatureNonce;
private $Signature;
public function __set($name, $value)
{
$this->$name = $value;
}
public function __construct()
{
$this->Timestamp = gmdate('Y-m-d\TH:i:s\Z');
$this->SignatureNonce = time().rand(10000,99999);
}
}

View File

@ -0,0 +1,108 @@
<?php
namespace OSS\Tests;
use OSS\Core\OssException;
require_once __DIR__ . DIRECTORY_SEPARATOR . 'StsBase.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'AssumeRole.php';
class StsClient
{
public $AccessSecret;
public function doAction($params, $format="JSON")
{
$request_url = $this->generateSignedURL($params);
$response = $this->sendRequest($request_url, $format);
$result= $this->parseResponse($response, $format);
return $result;
}
private function sendRequest($url, $format)
{
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($curl_handle, CURLOPT_HEADER, true);
$response = curl_exec($curl_handle);
$headerSize = curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE);
$response = substr($response, $headerSize);
if (curl_getinfo($curl_handle, CURLINFO_HTTP_CODE) != '200') {
$errors = $this->parseResponse($response, $format);
throw new OssException($errors->Code);
}
curl_close($curl_handle);
return $response;
}
private function parseResponse($body, $format)
{
if ("JSON" == $format) {
$respObject = json_decode($body);
} elseif ("XML" == $format) {
$respObject = @simplexml_load_string($body);
} elseif ("RAW" == $format) {
$respObject = $body;
}
return $respObject;
}
private function generateSignedURL($arr)
{
$request_url = 'https://sts.aliyuncs.com/?';
foreach ($arr as $key=>$item) {
if (is_null($item)) unset($arr[$key]);
}
$Signature = $this->computeSignature($arr, $this->AccessSecret);
ksort($arr);
foreach ($arr as $key => $value) {
$request_url .= $key."=".urlencode($value)."&";
}
$request_url .="Signature=".urlencode($Signature);
return $request_url;
}
private function computeSignature($parameters, $accessKeySecret)
{
ksort($parameters);
$canonicalizedQueryString = '';
foreach ($parameters as $key => $value) {
$canonicalizedQueryString .= '&' . $this->percentEncode($key). '=' . $this->percentEncode($value);
}
$stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
$signature = $this->signString($stringToSign, $accessKeySecret."&");
return $signature;
}
private function signString($source, $accessSecret)
{
return base64_encode(hash_hmac('sha1', $source, $accessSecret, true));
}
private function percentEncode($str)
{
$res = urlencode($str);
$res = preg_replace('/\+/', '%20', $res);
$res = preg_replace('/\*/', '%2A', $res);
$res = preg_replace('/%7E/', '~', $res);
return $res;
}
}

119
vendor/bin/jp.php vendored Normal file
View File

@ -0,0 +1,119 @@
#!/usr/bin/env php
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../mtdowling/jmespath.php/bin/jp.php)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;
return (bool) $this->handle;
}
public function stream_read($count)
{
$data = fread($this->handle, $count);
if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}
$this->position += strlen($data);
return $data;
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
fclose($this->handle);
}
public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}
public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}
return false;
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return feof($this->handle);
}
public function stream_stat()
{
return array();
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}
return false;
}
}
}
if (
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
) {
return include("phpvfscomposer://" . __DIR__ . '/..'.'/mtdowling/jmespath.php/bin/jp.php');
}
}
return include __DIR__ . '/..'.'/mtdowling/jmespath.php/bin/jp.php';

5
vendor/bin/jp.php.bat vendored Normal file
View File

@ -0,0 +1,5 @@
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/jp.php
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
php "%BIN_TARGET%" %*

View File

@ -0,0 +1,74 @@
#!/usr/bin/env php
<?php
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require __DIR__ . '/../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../autoload.php')) {
require __DIR__ . '/../../../autoload.php';
} elseif (file_exists(__DIR__ . '/../autoload.php')) {
require __DIR__ . '/../autoload.php';
} else {
throw new RuntimeException('Unable to locate autoload.php file.');
}
use JmesPath\Env;
use JmesPath\DebugRuntime;
$description = <<<EOT
Runs a JMESPath expression on the provided input or a test case.
Provide the JSON input and expression:
echo '{}' | jp.php expression
Or provide the path to a compliance script, a suite, and test case number:
jp.php --script path_to_script --suite test_suite_number --case test_case_number [expression]
EOT;
$args = [];
$currentKey = null;
for ($i = 1, $total = count($argv); $i < $total; $i++) {
if ($i % 2) {
if (substr($argv[$i], 0, 2) == '--') {
$currentKey = str_replace('--', '', $argv[$i]);
} else {
$currentKey = trim($argv[$i]);
}
} else {
$args[$currentKey] = $argv[$i];
$currentKey = null;
}
}
$expression = $currentKey;
if (isset($args['file']) || isset($args['suite']) || isset($args['case'])) {
if (!isset($args['file']) || !isset($args['suite']) || !isset($args['case'])) {
die($description);
}
// Manually run a compliance test
$path = realpath($args['file']);
file_exists($path) or die('File not found at ' . $path);
$json = json_decode(file_get_contents($path), true);
$set = $json[$args['suite']];
$data = $set['given'];
if (!isset($expression)) {
$expression = $set['cases'][$args['case']]['expression'];
echo "Expects\n=======\n";
if (isset($set['cases'][$args['case']]['result'])) {
echo json_encode($set['cases'][$args['case']]['result'], JSON_PRETTY_PRINT) . "\n\n";
} elseif (isset($set['cases'][$args['case']]['error'])) {
echo "{$set['cases'][$argv['case']]['error']} error\n\n";
} else {
echo "NULL\n\n";
}
}
} elseif (isset($expression)) {
// Pass in an expression and STDIN as a standalone argument
$data = json_decode(stream_get_contents(STDIN), true);
} else {
die($description);
}
$runtime = new DebugRuntime(Env::createRuntime());
$runtime($expression, $data);

View File

@ -0,0 +1,68 @@
#!/usr/bin/env php
<?php
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require __DIR__ . '/../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../autoload.php')) {
require __DIR__ . '/../../../autoload.php';
} else {
throw new RuntimeException('Unable to locate autoload.php file.');
}
$xdebug = new \Composer\XdebugHandler\XdebugHandler('perf.php');
$xdebug->check();
unset($xdebug);
$dir = isset($argv[1]) ? $argv[1] : __DIR__ . '/../tests/compliance/perf';
is_dir($dir) or die('Dir not found: ' . $dir);
// Warm up the runner
\JmesPath\Env::search('foo', []);
$total = 0;
foreach (glob($dir . '/*.json') as $file) {
$total += runSuite($file);
}
echo "\nTotal time: {$total}\n";
function runSuite($file)
{
$contents = file_get_contents($file);
$json = json_decode($contents, true);
$total = 0;
foreach ($json as $suite) {
foreach ($suite['cases'] as $case) {
$total += runCase(
$suite['given'],
$case['expression'],
$case['name']
);
}
}
return $total;
}
function runCase($given, $expression, $name)
{
$best = 99999;
$runtime = \JmesPath\Env::createRuntime();
for ($i = 0; $i < 100; $i++) {
$t = microtime(true);
$runtime($expression, $given);
$tryTime = (microtime(true) - $t) * 1000;
if ($tryTime < $best) {
$best = $tryTime;
}
if (!getenv('CACHE')) {
$runtime = \JmesPath\Env::createRuntime();
// Delete compiled scripts if not caching.
if ($runtime instanceof \JmesPath\CompilerRuntime) {
array_map('unlink', glob(sys_get_temp_dir() . '/jmespath_*.php'));
}
}
}
printf("time: %07.4fms name: %s\n", $best, $name);
return $best;
}

View File

@ -0,0 +1,11 @@
<?php
if (\PHP_VERSION_ID < 80000 && !interface_exists('Stringable')) {
interface Stringable
{
/**
* @return string
*/
public function __toString();
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="true" colors="true" cacheResultFile="/tmp/.phpspreadsheet.phpunit.result.cache">
<coverage/>
<php>
<ini name="memory_limit" value="2048M"/>
</php>
<testsuite name="PhpSpreadsheet Unit Test Suite">
<directory>./tests/PhpSpreadsheetTests</directory>
</testsuite>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>

View File

@ -0,0 +1,66 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Cell;
class IgnoredErrors
{
/** @var bool */
private $numberStoredAsText = false;
/** @var bool */
private $formula = false;
/** @var bool */
private $twoDigitTextYear = false;
/** @var bool */
private $evalError = false;
public function setNumberStoredAsText(bool $value): self
{
$this->numberStoredAsText = $value;
return $this;
}
public function getNumberStoredAsText(): bool
{
return $this->numberStoredAsText;
}
public function setFormula(bool $value): self
{
$this->formula = $value;
return $this;
}
public function getFormula(): bool
{
return $this->formula;
}
public function setTwoDigitTextYear(bool $value): self
{
$this->twoDigitTextYear = $value;
return $this;
}
public function getTwoDigitTextYear(): bool
{
return $this->twoDigitTextYear;
}
public function setEvalError(bool $value): self
{
$this->evalError = $value;
return $this;
}
public function getEvalError(): bool
{
return $this->evalError;
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Style\Font;
class AxisText extends Properties
{
/** @var ?int */
private $rotation;
/** @var Font */
private $font;
public function __construct()
{
parent::__construct();
$this->font = new Font();
$this->font->setSize(null, true);
}
public function setRotation(?int $rotation): self
{
$this->rotation = $rotation;
return $this;
}
public function getRotation(): ?int
{
return $this->rotation;
}
public function getFillColorObject(): ChartColor
{
$fillColor = $this->font->getChartColor();
if ($fillColor === null) {
$fillColor = new ChartColor();
$this->font->setChartColorFromObject($fillColor);
}
return $fillColor;
}
public function getFont(): Font
{
return $this->font;
}
public function setFont(Font $font): self
{
$this->font = $font;
return $this;
}
}

View File

@ -0,0 +1,89 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Helper;
use PhpOffice\PhpSpreadsheet\Exception;
class Downloader
{
protected string $filepath;
protected string $filename;
protected string $filetype;
protected const CONTENT_TYPES = [
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xls' => 'application/vnd.ms-excel',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'csv' => 'text/csv',
'html' => 'text/html',
'pdf' => 'application/pdf',
];
public function __construct(string $folder, string $filename, ?string $filetype = null)
{
if ((is_dir($folder) === false) || (is_readable($folder) === false)) {
throw new Exception("Folder {$folder} is not accessable");
}
$filepath = "{$folder}/{$filename}";
$this->filepath = (string) realpath($filepath);
$this->filename = basename($filepath);
if ((file_exists($this->filepath) === false) || (is_readable($this->filepath) === false)) {
throw new Exception("{$this->filename} not found, or cannot be read");
}
$filetype ??= pathinfo($filename, PATHINFO_EXTENSION);
if (array_key_exists(strtolower($filetype), self::CONTENT_TYPES) === false) {
throw new Exception("Invalid filetype: {$filetype} cannot be downloaded");
}
$this->filetype = strtolower($filetype);
}
public function download(): void
{
$this->headers();
readfile($this->filepath);
}
public function headers(): void
{
ob_clean();
$this->contentType();
$this->contentDisposition();
$this->cacheHeaders();
$this->fileSize();
flush();
}
protected function contentType(): void
{
header('Content-Type: ' . self::CONTENT_TYPES[$this->filetype]);
}
protected function contentDisposition(): void
{
header('Content-Disposition: attachment;filename="' . $this->filename . '"');
}
protected function cacheHeaders(): void
{
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
}
protected function fileSize(): void
{
header('Content-Length: ' . filesize($this->filepath));
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Helper;
class Handler
{
/** @var string */
private static $invalidHex = 'Y';
// A bunch of methods to show that we continue
// to capture messages even using PhpUnit 10.
public static function suppressed(): bool
{
return @trigger_error('hello');
}
public static function deprecated(): string
{
return (string) hexdec(self::$invalidHex);
}
public static function notice(string $value): void
{
date_default_timezone_set($value);
}
public static function warning(): bool
{
return file_get_contents(__FILE__ . 'noexist') !== false;
}
public static function userDeprecated(): bool
{
return trigger_error('hello', E_USER_DEPRECATED);
}
public static function userNotice(): bool
{
return trigger_error('userNotice', E_USER_NOTICE);
}
public static function userWarning(): bool
{
return trigger_error('userWarning', E_USER_WARNING);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx;
class SharedFormula
{
private string $master;
private string $formula;
public function __construct(string $master, string $formula)
{
$this->master = $master;
$this->formula = $formula;
}
public function master(): string
{
return $this->master;
}
public function formula(): string
{
return $this->formula;
}
}

View File

@ -0,0 +1,177 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Cell\AddressHelper;
use PhpOffice\PhpSpreadsheet\Cell\AddressRange;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx\Namespaces;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use SimpleXMLElement;
class DataValidations
{
private const OPERATOR_MAPPINGS = [
'between' => DataValidation::OPERATOR_BETWEEN,
'equal' => DataValidation::OPERATOR_EQUAL,
'greater' => DataValidation::OPERATOR_GREATERTHAN,
'greaterorequal' => DataValidation::OPERATOR_GREATERTHANOREQUAL,
'less' => DataValidation::OPERATOR_LESSTHAN,
'lessorequal' => DataValidation::OPERATOR_LESSTHANOREQUAL,
'notbetween' => DataValidation::OPERATOR_NOTBETWEEN,
'notequal' => DataValidation::OPERATOR_NOTEQUAL,
];
private const TYPE_MAPPINGS = [
'textlength' => DataValidation::TYPE_TEXTLENGTH,
];
private int $thisRow = 0;
private int $thisColumn = 0;
private function replaceR1C1(array $matches): string
{
return AddressHelper::convertToA1($matches[0], $this->thisRow, $this->thisColumn, false);
}
public function loadDataValidations(SimpleXMLElement $worksheet, Spreadsheet $spreadsheet): void
{
$xmlX = $worksheet->children(Namespaces::URN_EXCEL);
$sheet = $spreadsheet->getActiveSheet();
/** @var callable */
$pregCallback = [$this, 'replaceR1C1'];
foreach ($xmlX->DataValidation as $dataValidation) {
$cells = [];
$validation = new DataValidation();
// set defaults
$validation->setShowDropDown(true);
$validation->setShowInputMessage(true);
$validation->setShowErrorMessage(true);
$validation->setShowDropDown(true);
$this->thisRow = 1;
$this->thisColumn = 1;
foreach ($dataValidation as $tagName => $tagValue) {
$tagValue = (string) $tagValue;
$tagValueLower = strtolower($tagValue);
switch ($tagName) {
case 'Range':
foreach (explode(',', $tagValue) as $range) {
$cell = '';
if (preg_match('/^R(\d+)C(\d+):R(\d+)C(\d+)$/', (string) $range, $selectionMatches) === 1) {
// range
$firstCell = Coordinate::stringFromColumnIndex((int) $selectionMatches[2])
. $selectionMatches[1];
$cell = $firstCell
. ':'
. Coordinate::stringFromColumnIndex((int) $selectionMatches[4])
. $selectionMatches[3];
$this->thisRow = (int) $selectionMatches[1];
$this->thisColumn = (int) $selectionMatches[2];
$sheet->getCell($firstCell);
} elseif (preg_match('/^R(\d+)C(\d+)$/', (string) $range, $selectionMatches) === 1) {
// cell
$cell = Coordinate::stringFromColumnIndex((int) $selectionMatches[2])
. $selectionMatches[1];
$sheet->getCell($cell);
$this->thisRow = (int) $selectionMatches[1];
$this->thisColumn = (int) $selectionMatches[2];
} elseif (preg_match('/^C(\d+)$/', (string) $range, $selectionMatches) === 1) {
// column
$firstCell = Coordinate::stringFromColumnIndex((int) $selectionMatches[1])
. '1';
$cell = $firstCell
. ':'
. Coordinate::stringFromColumnIndex((int) $selectionMatches[1])
. ((string) AddressRange::MAX_ROW);
$this->thisColumn = (int) $selectionMatches[1];
$sheet->getCell($firstCell);
} elseif (preg_match('/^R(\d+)$/', (string) $range, $selectionMatches)) {
// row
$firstCell = 'A'
. $selectionMatches[1];
$cell = $firstCell
. ':'
. AddressRange::MAX_COLUMN
. $selectionMatches[1];
$this->thisRow = (int) $selectionMatches[1];
$sheet->getCell($firstCell);
}
$validation->setSqref($cell);
$stRange = $sheet->shrinkRangeToFit($cell);
$cells = array_merge($cells, Coordinate::extractAllCellReferencesInRange($stRange));
}
break;
case 'Type':
$validation->setType(self::TYPE_MAPPINGS[$tagValueLower] ?? $tagValueLower);
break;
case 'Qualifier':
$validation->setOperator(self::OPERATOR_MAPPINGS[$tagValueLower] ?? $tagValueLower);
break;
case 'InputTitle':
$validation->setPromptTitle($tagValue);
break;
case 'InputMessage':
$validation->setPrompt($tagValue);
break;
case 'InputHide':
$validation->setShowInputMessage(false);
break;
case 'ErrorStyle':
$validation->setErrorStyle($tagValueLower);
break;
case 'ErrorTitle':
$validation->setErrorTitle($tagValue);
break;
case 'ErrorMessage':
$validation->setError($tagValue);
break;
case 'ErrorHide':
$validation->setShowErrorMessage(false);
break;
case 'ComboHide':
$validation->setShowDropDown(false);
break;
case 'UseBlank':
$validation->setAllowBlank(true);
break;
case 'CellRangeList':
// FIXME missing FIXME
break;
case 'Min':
case 'Value':
$tagValue = (string) preg_replace_callback(AddressHelper::R1C1_COORDINATE_REGEX, $pregCallback, $tagValue);
$validation->setFormula1($tagValue);
break;
case 'Max':
$tagValue = (string) preg_replace_callback(AddressHelper::R1C1_COORDINATE_REGEX, $pregCallback, $tagValue);
$validation->setFormula2($tagValue);
break;
}
}
foreach ($cells as $cell) {
$sheet->getCell($cell)->setDataValidation(clone $validation);
}
}
}
}

View File

@ -0,0 +1,125 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
class Date extends DateTimeWizard
{
/**
* Year (4 digits), e.g. 2023.
*/
public const YEAR_FULL = 'yyyy';
/**
* Year (last 2 digits), e.g. 23.
*/
public const YEAR_SHORT = 'yy';
public const MONTH_FIRST_LETTER = 'mmmmm';
/**
* Month name, long form, e.g. January.
*/
public const MONTH_NAME_FULL = 'mmmm';
/**
* Month name, short form, e.g. Jan.
*/
public const MONTH_NAME_SHORT = 'mmm';
/**
* Month number with a leading zero if required, e.g. 01.
*/
public const MONTH_NUMBER_LONG = 'mm';
/**
* Month number without a leading zero, e.g. 1.
*/
public const MONTH_NUMBER_SHORT = 'm';
/**
* Day of the week, full form, e.g. Tuesday.
*/
public const WEEKDAY_NAME_LONG = 'dddd';
/**
* Day of the week, short form, e.g. Tue.
*/
public const WEEKDAY_NAME_SHORT = 'ddd';
/**
* Day number with a leading zero, e.g. 03.
*/
public const DAY_NUMBER_LONG = 'dd';
/**
* Day number without a leading zero, e.g. 3.
*/
public const DAY_NUMBER_SHORT = 'd';
protected const DATE_BLOCKS = [
self::YEAR_FULL,
self::YEAR_SHORT,
self::MONTH_FIRST_LETTER,
self::MONTH_NAME_FULL,
self::MONTH_NAME_SHORT,
self::MONTH_NUMBER_LONG,
self::MONTH_NUMBER_SHORT,
self::WEEKDAY_NAME_LONG,
self::WEEKDAY_NAME_SHORT,
self::DAY_NUMBER_LONG,
self::DAY_NUMBER_SHORT,
];
public const SEPARATOR_DASH = '-';
public const SEPARATOR_DOT = '.';
public const SEPARATOR_SLASH = '/';
public const SEPARATOR_SPACE_NONBREAKING = "\u{a0}";
public const SEPARATOR_SPACE = ' ';
protected const DATE_DEFAULT = [
self::YEAR_FULL,
self::MONTH_NUMBER_LONG,
self::DAY_NUMBER_LONG,
];
/**
* @var string[]
*/
protected array $separators;
/**
* @var string[]
*/
protected array $formatBlocks;
/**
* @param null|string|string[] $separators
* If you want to use the same separator for all format blocks, then it can be passed as a string literal;
* if you wish to use different separators, then they should be passed as an array.
* If you want to use only a single format block, then pass a null as the separator argument
*/
public function __construct($separators = self::SEPARATOR_DASH, string ...$formatBlocks)
{
$separators ??= self::SEPARATOR_DASH;
$formatBlocks = (count($formatBlocks) === 0) ? self::DATE_DEFAULT : $formatBlocks;
$this->separators = $this->padSeparatorArray(
is_array($separators) ? $separators : [$separators],
count($formatBlocks) - 1
);
$this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
}
private function mapFormatBlocks(string $value): string
{
// Any date masking codes are returned as lower case values
if (in_array(mb_strtolower($value), self::DATE_BLOCKS, true)) {
return mb_strtolower($value);
}
// Wrap any string literals in quotes, so that they're clearly defined as string literals
return $this->wrapLiteral($value);
}
public function format(): string
{
return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
class DateTime extends DateTimeWizard
{
/**
* @var string[]
*/
protected array $separators;
/**
* @var array<DateTimeWizard|string>
*/
protected array $formatBlocks;
/**
* @param null|string|string[] $separators
* If you want to use only a single format block, then pass a null as the separator argument
* @param DateTimeWizard|string ...$formatBlocks
*/
public function __construct($separators, ...$formatBlocks)
{
$this->separators = $this->padSeparatorArray(
is_array($separators) ? $separators : [$separators],
count($formatBlocks) - 1
);
$this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
}
/**
* @param DateTimeWizard|string $value
*/
private function mapFormatBlocks($value): string
{
// Any date masking codes are returned as lower case values
if (is_object($value)) {
// We can't explicitly test for Stringable until PHP >= 8.0
return $value;
}
// Wrap any string literals in quotes, so that they're clearly defined as string literals
return $this->wrapLiteral($value);
}
public function format(): string
{
return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
abstract class DateTimeWizard implements Wizard
{
protected const NO_ESCAPING_NEEDED = "$+-/():!^&'~{}<>= ";
protected function padSeparatorArray(array $separators, int $count): array
{
$lastSeparator = array_pop($separators);
return $separators + array_fill(0, $count, $lastSeparator);
}
protected function escapeSingleCharacter(string $value): string
{
if (strpos(self::NO_ESCAPING_NEEDED, $value) !== false) {
return $value;
}
return "\\{$value}";
}
protected function wrapLiteral(string $value): string
{
if (mb_strlen($value, 'UTF-8') === 1) {
return $this->escapeSingleCharacter($value);
}
// Wrap any other string literals in quotes, so that they're clearly defined as string literals
return '"' . str_replace('"', '""', $value) . '"';
}
protected function intersperse(string $formatBlock, ?string $separator): string
{
return "{$formatBlock}{$separator}";
}
public function __toString(): string
{
return $this->format();
}
}

View File

@ -0,0 +1,153 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
class Duration extends DateTimeWizard
{
public const DAYS_DURATION = 'd';
/**
* Hours as a duration (can exceed 24), e.g. 29.
*/
public const HOURS_DURATION = '[h]';
/**
* Hours without a leading zero, e.g. 9.
*/
public const HOURS_SHORT = 'h';
/**
* Hours with a leading zero, e.g. 09.
*/
public const HOURS_LONG = 'hh';
/**
* Minutes as a duration (can exceed 60), e.g. 109.
*/
public const MINUTES_DURATION = '[m]';
/**
* Minutes without a leading zero, e.g. 5.
*/
public const MINUTES_SHORT = 'm';
/**
* Minutes with a leading zero, e.g. 05.
*/
public const MINUTES_LONG = 'mm';
/**
* Seconds as a duration (can exceed 60), e.g. 129.
*/
public const SECONDS_DURATION = '[s]';
/**
* Seconds without a leading zero, e.g. 2.
*/
public const SECONDS_SHORT = 's';
/**
* Seconds with a leading zero, e.g. 02.
*/
public const SECONDS_LONG = 'ss';
protected const DURATION_BLOCKS = [
self::DAYS_DURATION,
self::HOURS_DURATION,
self::HOURS_LONG,
self::HOURS_SHORT,
self::MINUTES_DURATION,
self::MINUTES_LONG,
self::MINUTES_SHORT,
self::SECONDS_DURATION,
self::SECONDS_LONG,
self::SECONDS_SHORT,
];
protected const DURATION_MASKS = [
self::DAYS_DURATION => self::DAYS_DURATION,
self::HOURS_DURATION => self::HOURS_SHORT,
self::MINUTES_DURATION => self::MINUTES_LONG,
self::SECONDS_DURATION => self::SECONDS_LONG,
];
protected const DURATION_DEFAULTS = [
self::HOURS_LONG => self::HOURS_DURATION,
self::HOURS_SHORT => self::HOURS_DURATION,
self::MINUTES_LONG => self::MINUTES_DURATION,
self::MINUTES_SHORT => self::MINUTES_DURATION,
self::SECONDS_LONG => self::SECONDS_DURATION,
self::SECONDS_SHORT => self::SECONDS_DURATION,
];
public const SEPARATOR_COLON = ':';
public const SEPARATOR_SPACE_NONBREAKING = "\u{a0}";
public const SEPARATOR_SPACE = ' ';
public const DURATION_DEFAULT = [
self::HOURS_DURATION,
self::MINUTES_LONG,
self::SECONDS_LONG,
];
/**
* @var string[]
*/
protected array $separators;
/**
* @var string[]
*/
protected array $formatBlocks;
protected bool $durationIsSet = false;
/**
* @param null|string|string[] $separators
* If you want to use the same separator for all format blocks, then it can be passed as a string literal;
* if you wish to use different separators, then they should be passed as an array.
* If you want to use only a single format block, then pass a null as the separator argument
*/
public function __construct($separators = self::SEPARATOR_COLON, string ...$formatBlocks)
{
$separators ??= self::SEPARATOR_COLON;
$formatBlocks = (count($formatBlocks) === 0) ? self::DURATION_DEFAULT : $formatBlocks;
$this->separators = $this->padSeparatorArray(
is_array($separators) ? $separators : [$separators],
count($formatBlocks) - 1
);
$this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
if ($this->durationIsSet === false) {
// We need at least one duration mask, so if none has been set we change the first mask element
// to a duration.
$this->formatBlocks[0] = self::DURATION_DEFAULTS[mb_strtolower($this->formatBlocks[0])];
}
}
private function mapFormatBlocks(string $value): string
{
// Any duration masking codes are returned as lower case values
if (in_array(mb_strtolower($value), self::DURATION_BLOCKS, true)) {
if (array_key_exists(mb_strtolower($value), self::DURATION_MASKS)) {
if ($this->durationIsSet) {
// We should only have a single duration mask, the first defined in the mask set,
// so convert any additional duration masks to standard time masks.
$value = self::DURATION_MASKS[mb_strtolower($value)];
}
$this->durationIsSet = true;
}
return mb_strtolower($value);
}
// Wrap any string literals in quotes, so that they're clearly defined as string literals
return $this->wrapLiteral($value);
}
public function format(): string
{
return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
class Time extends DateTimeWizard
{
/**
* Hours without a leading zero, e.g. 9.
*/
public const HOURS_SHORT = 'h';
/**
* Hours with a leading zero, e.g. 09.
*/
public const HOURS_LONG = 'hh';
/**
* Minutes without a leading zero, e.g. 5.
*/
public const MINUTES_SHORT = 'm';
/**
* Minutes with a leading zero, e.g. 05.
*/
public const MINUTES_LONG = 'mm';
/**
* Seconds without a leading zero, e.g. 2.
*/
public const SECONDS_SHORT = 's';
/**
* Seconds with a leading zero, e.g. 02.
*/
public const SECONDS_LONG = 'ss';
public const MORNING_AFTERNOON = 'AM/PM';
protected const TIME_BLOCKS = [
self::HOURS_LONG,
self::HOURS_SHORT,
self::MINUTES_LONG,
self::MINUTES_SHORT,
self::SECONDS_LONG,
self::SECONDS_SHORT,
self::MORNING_AFTERNOON,
];
public const SEPARATOR_COLON = ':';
public const SEPARATOR_SPACE_NONBREAKING = "\u{a0}";
public const SEPARATOR_SPACE = ' ';
protected const TIME_DEFAULT = [
self::HOURS_LONG,
self::MINUTES_LONG,
self::SECONDS_LONG,
];
/**
* @var string[]
*/
protected array $separators;
/**
* @var string[]
*/
protected array $formatBlocks;
/**
* @param null|string|string[] $separators
* If you want to use the same separator for all format blocks, then it can be passed as a string literal;
* if you wish to use different separators, then they should be passed as an array.
* If you want to use only a single format block, then pass a null as the separator argument
*/
public function __construct($separators = self::SEPARATOR_COLON, string ...$formatBlocks)
{
$separators ??= self::SEPARATOR_COLON;
$formatBlocks = (count($formatBlocks) === 0) ? self::TIME_DEFAULT : $formatBlocks;
$this->separators = $this->padSeparatorArray(
is_array($separators) ? $separators : [$separators],
count($formatBlocks) - 1
);
$this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
}
private function mapFormatBlocks(string $value): string
{
// Any date masking codes are returned as lower case values
// except for AM/PM, which is set to uppercase
if (in_array(mb_strtolower($value), self::TIME_BLOCKS, true)) {
return mb_strtolower($value);
} elseif (mb_strtoupper($value) === self::MORNING_AFTERNOON) {
return mb_strtoupper($value);
}
// Wrap any string literals in quotes, so that they're clearly defined as string literals
return $this->wrapLiteral($value);
}
public function format(): string
{
return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
}
}

View File

@ -0,0 +1,175 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style;
/**
* Class to handle tint applied to color.
* Code borrows heavily from some Python projects.
*
* @see https://docs.python.org/3/library/colorsys.html
* @see https://gist.github.com/Mike-Honey/b36e651e9a7f1d2e1d60ce1c63b9b633
*/
class RgbTint
{
private const ONE_THIRD = 1.0 / 3.0;
private const ONE_SIXTH = 1.0 / 6.0;
private const TWO_THIRD = 2.0 / 3.0;
private const RGBMAX = 255.0;
/**
* MS excel's tint function expects that HLS is base 240.
*
* @see https://social.msdn.microsoft.com/Forums/en-US/e9d8c136-6d62-4098-9b1b-dac786149f43/excel-color-tint-algorithm-incorrect?forum=os_binaryfile#d3c2ac95-52e0-476b-86f1-e2a697f24969
*/
private const HLSMAX = 240.0;
/**
* Convert red/green/blue to hue/luminance/saturation.
*
* @param float $red 0.0 through 1.0
* @param float $green 0.0 through 1.0
* @param float $blue 0.0 through 1.0
*
* @return float[]
*/
private static function rgbToHls(float $red, float $green, float $blue): array
{
$maxc = max($red, $green, $blue);
$minc = min($red, $green, $blue);
$luminance = ($minc + $maxc) / 2.0;
if ($minc === $maxc) {
return [0.0, $luminance, 0.0];
}
$maxMinusMin = $maxc - $minc;
if ($luminance <= 0.5) {
$s = $maxMinusMin / ($maxc + $minc);
} else {
$s = $maxMinusMin / (2.0 - $maxc - $minc);
}
$rc = ($maxc - $red) / $maxMinusMin;
$gc = ($maxc - $green) / $maxMinusMin;
$bc = ($maxc - $blue) / $maxMinusMin;
if ($red === $maxc) {
$h = $bc - $gc;
} elseif ($green === $maxc) {
$h = 2.0 + $rc - $bc;
} else {
$h = 4.0 + $gc - $rc;
}
$h = self::positiveDecimalPart($h / 6.0);
return [$h, $luminance, $s];
}
/** @var mixed */
private static $scrutinizerZeroPointZero = 0.0;
/**
* Convert hue/luminance/saturation to red/green/blue.
*
* @param float $hue 0.0 through 1.0
* @param float $luminance 0.0 through 1.0
* @param float $saturation 0.0 through 1.0
*
* @return float[]
*/
private static function hlsToRgb($hue, $luminance, $saturation): array
{
if ($saturation === self::$scrutinizerZeroPointZero) {
return [$luminance, $luminance, $luminance];
}
if ($luminance <= 0.5) {
$m2 = $luminance * (1.0 + $saturation);
} else {
$m2 = $luminance + $saturation - ($luminance * $saturation);
}
$m1 = 2.0 * $luminance - $m2;
return [
self::vFunction($m1, $m2, $hue + self::ONE_THIRD),
self::vFunction($m1, $m2, $hue),
self::vFunction($m1, $m2, $hue - self::ONE_THIRD),
];
}
private static function vFunction(float $m1, float $m2, float $hue): float
{
$hue = self::positiveDecimalPart($hue);
if ($hue < self::ONE_SIXTH) {
return $m1 + ($m2 - $m1) * $hue * 6.0;
}
if ($hue < 0.5) {
return $m2;
}
if ($hue < self::TWO_THIRD) {
return $m1 + ($m2 - $m1) * (self::TWO_THIRD - $hue) * 6.0;
}
return $m1;
}
private static function positiveDecimalPart(float $hue): float
{
$hue = fmod($hue, 1.0);
return ($hue >= 0.0) ? $hue : (1.0 + $hue);
}
/**
* Convert red/green/blue to HLSMAX-based hue/luminance/saturation.
*
* @return int[]
*/
private static function rgbToMsHls(int $red, int $green, int $blue): array
{
$red01 = $red / self::RGBMAX;
$green01 = $green / self::RGBMAX;
$blue01 = $blue / self::RGBMAX;
[$hue, $luminance, $saturation] = self::rgbToHls($red01, $green01, $blue01);
return [
(int) round($hue * self::HLSMAX),
(int) round($luminance * self::HLSMAX),
(int) round($saturation * self::HLSMAX),
];
}
/**
* Converts HLSMAX based HLS values to rgb values in the range (0,1).
*
* @return float[]
*/
private static function msHlsToRgb(int $hue, int $lightness, int $saturation): array
{
return self::hlsToRgb($hue / self::HLSMAX, $lightness / self::HLSMAX, $saturation / self::HLSMAX);
}
/**
* Tints HLSMAX based luminance.
*
* @see http://ciintelligence.blogspot.co.uk/2012/02/converting-excel-theme-color-and-tint.html
*/
private static function tintLuminance(float $tint, float $luminance): int
{
if ($tint < 0) {
return (int) round($luminance * (1.0 + $tint));
}
return (int) round($luminance * (1.0 - $tint) + (self::HLSMAX - self::HLSMAX * (1.0 - $tint)));
}
/**
* Return result of tinting supplied rgb as 6 hex digits.
*/
public static function rgbAndTintToRgb(int $red, int $green, int $blue, float $tint): string
{
[$hue, $luminance, $saturation] = self::rgbToMsHls($red, $green, $blue);
[$red, $green, $blue] = self::msHlsToRgb($hue, self::tintLuminance($tint, $luminance), $saturation);
return sprintf(
'%02X%02X%02X',
(int) round($red * self::RGBMAX),
(int) round($green * self::RGBMAX),
(int) round($blue * self::RGBMAX)
);
}
}

View File

@ -0,0 +1,269 @@
<?php
namespace PhpOffice\PhpSpreadsheet;
class Theme
{
/** @var string */
private $themeColorName = 'Office';
/** @var string */
private $themeFontName = 'Office';
public const COLOR_SCHEME_2013_PLUS_NAME = 'Office 2013+';
public const COLOR_SCHEME_2013_PLUS = [
'dk1' => '000000',
'lt1' => 'FFFFFF',
'dk2' => '44546A',
'lt2' => 'E7E6E6',
'accent1' => '4472C4',
'accent2' => 'ED7D31',
'accent3' => 'A5A5A5',
'accent4' => 'FFC000',
'accent5' => '5B9BD5',
'accent6' => '70AD47',
'hlink' => '0563C1',
'folHlink' => '954F72',
];
public const COLOR_SCHEME_2007_2010_NAME = 'Office 2007-2010';
public const COLOR_SCHEME_2007_2010 = [
'dk1' => '000000',
'lt1' => 'FFFFFF',
'dk2' => '1F497D',
'lt2' => 'EEECE1',
'accent1' => '4F81BD',
'accent2' => 'C0504D',
'accent3' => '9BBB59',
'accent4' => '8064A2',
'accent5' => '4BACC6',
'accent6' => 'F79646',
'hlink' => '0000FF',
'folHlink' => '800080',
];
/** @var string[] */
private $themeColors = self::COLOR_SCHEME_2007_2010;
/** @var string */
private $majorFontLatin = 'Cambria';
/** @var string */
private $majorFontEastAsian = '';
/** @var string */
private $majorFontComplexScript = '';
/** @var string */
private $minorFontLatin = 'Calibri';
/** @var string */
private $minorFontEastAsian = '';
/** @var string */
private $minorFontComplexScript = '';
/**
* Map of Major (header) fonts to write.
*
* @var string[]
*/
private $majorFontSubstitutions = self::FONTS_TIMES_SUBSTITUTIONS;
/**
* Map of Minor (body) fonts to write.
*
* @var string[]
*/
private $minorFontSubstitutions = self::FONTS_ARIAL_SUBSTITUTIONS;
public const FONTS_TIMES_SUBSTITUTIONS = [
'Jpan' => ' Pゴシック',
'Hang' => '맑은 고딕',
'Hans' => '宋体',
'Hant' => '新細明體',
'Arab' => 'Times New Roman',
'Hebr' => 'Times New Roman',
'Thai' => 'Tahoma',
'Ethi' => 'Nyala',
'Beng' => 'Vrinda',
'Gujr' => 'Shruti',
'Khmr' => 'MoolBoran',
'Knda' => 'Tunga',
'Guru' => 'Raavi',
'Cans' => 'Euphemia',
'Cher' => 'Plantagenet Cherokee',
'Yiii' => 'Microsoft Yi Baiti',
'Tibt' => 'Microsoft Himalaya',
'Thaa' => 'MV Boli',
'Deva' => 'Mangal',
'Telu' => 'Gautami',
'Taml' => 'Latha',
'Syrc' => 'Estrangelo Edessa',
'Orya' => 'Kalinga',
'Mlym' => 'Kartika',
'Laoo' => 'DokChampa',
'Sinh' => 'Iskoola Pota',
'Mong' => 'Mongolian Baiti',
'Viet' => 'Times New Roman',
'Uigh' => 'Microsoft Uighur',
'Geor' => 'Sylfaen',
];
public const FONTS_ARIAL_SUBSTITUTIONS = [
'Jpan' => ' Pゴシック',
'Hang' => '맑은 고딕',
'Hans' => '宋体',
'Hant' => '新細明體',
'Arab' => 'Arial',
'Hebr' => 'Arial',
'Thai' => 'Tahoma',
'Ethi' => 'Nyala',
'Beng' => 'Vrinda',
'Gujr' => 'Shruti',
'Khmr' => 'DaunPenh',
'Knda' => 'Tunga',
'Guru' => 'Raavi',
'Cans' => 'Euphemia',
'Cher' => 'Plantagenet Cherokee',
'Yiii' => 'Microsoft Yi Baiti',
'Tibt' => 'Microsoft Himalaya',
'Thaa' => 'MV Boli',
'Deva' => 'Mangal',
'Telu' => 'Gautami',
'Taml' => 'Latha',
'Syrc' => 'Estrangelo Edessa',
'Orya' => 'Kalinga',
'Mlym' => 'Kartika',
'Laoo' => 'DokChampa',
'Sinh' => 'Iskoola Pota',
'Mong' => 'Mongolian Baiti',
'Viet' => 'Arial',
'Uigh' => 'Microsoft Uighur',
'Geor' => 'Sylfaen',
];
public function getThemeColors(): array
{
return $this->themeColors;
}
public function setThemeColor(string $key, string $value): self
{
$this->themeColors[$key] = $value;
return $this;
}
public function getThemeColorName(): string
{
return $this->themeColorName;
}
public function setThemeColorName(string $name, ?array $themeColors = null): self
{
$this->themeColorName = $name;
if ($name === self::COLOR_SCHEME_2007_2010_NAME) {
$themeColors = $themeColors ?? self::COLOR_SCHEME_2007_2010;
} elseif ($name === self::COLOR_SCHEME_2013_PLUS_NAME) {
$themeColors = $themeColors ?? self::COLOR_SCHEME_2013_PLUS;
}
if ($themeColors !== null) {
$this->themeColors = $themeColors;
}
return $this;
}
public function getMajorFontLatin(): string
{
return $this->majorFontLatin;
}
public function getMajorFontEastAsian(): string
{
return $this->majorFontEastAsian;
}
public function getMajorFontComplexScript(): string
{
return $this->majorFontComplexScript;
}
public function getMajorFontSubstitutions(): array
{
return $this->majorFontSubstitutions;
}
/** @param null|array $substitutions */
public function setMajorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, $substitutions): self
{
if (!empty($latin)) {
$this->majorFontLatin = $latin;
}
if ($eastAsian !== null) {
$this->majorFontEastAsian = $eastAsian;
}
if ($complexScript !== null) {
$this->majorFontComplexScript = $complexScript;
}
if ($substitutions !== null) {
$this->majorFontSubstitutions = $substitutions;
}
return $this;
}
public function getMinorFontLatin(): string
{
return $this->minorFontLatin;
}
public function getMinorFontEastAsian(): string
{
return $this->minorFontEastAsian;
}
public function getMinorFontComplexScript(): string
{
return $this->minorFontComplexScript;
}
public function getMinorFontSubstitutions(): array
{
return $this->minorFontSubstitutions;
}
/** @param null|array $substitutions */
public function setMinorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, $substitutions): self
{
if (!empty($latin)) {
$this->minorFontLatin = $latin;
}
if ($eastAsian !== null) {
$this->minorFontEastAsian = $eastAsian;
}
if ($complexScript !== null) {
$this->minorFontComplexScript = $complexScript;
}
if ($substitutions !== null) {
$this->minorFontSubstitutions = $substitutions;
}
return $this;
}
public function getThemeFontName(): string
{
return $this->themeFontName;
}
public function setThemeFontName(?string $name): self
{
if (!empty($name)) {
$this->themeFontName = $name;
}
return $this;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Writer;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;
class ZipStream0
{
/**
* @param resource $fileHandle
*/
public static function newZipStream($fileHandle): ZipStream
{
return class_exists(Archive::class) ? ZipStream2::newZipStream($fileHandle) : ZipStream3::newZipStream($fileHandle);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Writer;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;
class ZipStream2
{
/**
* @param resource $fileHandle
*/
public static function newZipStream($fileHandle): ZipStream
{
$options = new Archive();
$options->setEnableZip64(false);
$options->setOutputStream($fileHandle);
return new ZipStream(null, $options);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Writer;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;
class ZipStream3
{
/**
* @param resource $fileHandle
*/
public static function newZipStream($fileHandle): ZipStream
{
return new ZipStream(
enableZip64: false,
outputStream: $fileHandle,
sendHttpHeaders: false,
defaultEnableZeroHeader: false,
);
}
}

View File

@ -0,0 +1,38 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
$local_path = "/data/exampleobject";
try {
// -------------------- 1. 人体识别 原图存储在COS -------------------- //
$result = $cosClient->aIBodyRecognitionProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
));
// 请求成功
print_r($result);
// -------------------- 1. 人体识别 原图存储在COS -------------------- //
// -------------------- 2. 人体识别 原图来自其他链接 -------------------- //
$result = $cosClient->aIBodyRecognitionProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // 该值为空即可
'DetectUrl' => 'https://www.xxx.com/xxx.jpg',
));
// 请求成功
print_r($result);
// -------------------- 2. 人体识别 原图来自其他链接 -------------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,38 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
$local_path = "/data/exampleobject";
try {
// -------------------- 1. 游戏场景识别 原图存储在COS -------------------- //
$result = $cosClient->aIGameRecProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
));
// 请求成功
print_r($result);
// -------------------- 1. 游戏场景识别 原图存储在COS -------------------- //
// -------------------- 2. 游戏场景识别 原图来自其他链接 -------------------- //
$result = $cosClient->aIGameRecProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // 该值为空即可
'DetectUrl' => 'https://www.xxx.com/xxx.jpg',
));
// 请求成功
print_r($result);
// -------------------- 2. 游戏场景识别 原图来自其他链接 -------------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,65 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
$object = 'xxx.jpg';
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageColoring');
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', $object); // 获取下载链接
echo "{$downloadUrl}&{$query}"; // 携带签名的图片地址以“&”连接
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageColoring');
$ciProcessParams->addParam('detect-url', 'https://xxx.com/xxx.jpg');
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', ''); // 获取下载链接
echo "{$downloadUrl}&{$query}";
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
// ---------------------------- 3. 上传时处理 ---------------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageColoring');
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, "output.png"); // rules
$result = $cosClient->putObject(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'object.jpg',
'Body' => fopen('/tmp/local.jpg', 'rb'), // 本地文件
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// ---------------------------- 3. 上传时处理 ---------------------------- //
// --------------------- 4. 云上数据处理 ------------------------------ //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageColoring');
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, 'output.jpg'); // rules
$result = $cosClient->ImageProcess(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// --------------------- 4. 云上数据处理 ------------------------------ //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,83 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
$object = 'xxx.jpg';
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageCrop');
$ciProcessParams->addParam('width', 100); // 需要裁剪区域的宽度与height共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片宽度的像素值
$ciProcessParams->addParam('height', 100); // 需要裁剪区域的高度与width共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片高度的像素值width : height建议取值在[1, 2.5]之间,超过这个范围可能会影响效果
$ciProcessParams->addParam('fixed', 0); // 是否严格按照 width 和 height 的值进行输出。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', $object); // 获取下载链接
echo "{$downloadUrl}&{$query}"; // 携带签名的图片地址以“&”连接
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageCrop');
$ciProcessParams->addParam('detect-url', 'https://xxx.com/xxx.jpg');
$ciProcessParams->addParam('width', 100); // 需要裁剪区域的宽度与height共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片宽度的像素值
$ciProcessParams->addParam('height', 100); // 需要裁剪区域的高度与width共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片高度的像素值width : height建议取值在[1, 2.5]之间,超过这个范围可能会影响效果
$ciProcessParams->addParam('fixed', 0); // 是否严格按照 width 和 height 的值进行输出。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', ''); // 获取下载链接
echo "{$downloadUrl}&{$query}";
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
// ---------------------------- 3. 上传时处理 ---------------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageCrop');
$ciProcessParams->addParam('width', 100); // 需要裁剪区域的宽度与height共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片宽度的像素值
$ciProcessParams->addParam('height', 100); // 需要裁剪区域的高度与width共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片高度的像素值width : height建议取值在[1, 2.5]之间,超过这个范围可能会影响效果
$ciProcessParams->addParam('fixed', 0); // 是否严格按照 width 和 height 的值进行输出。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, "output.png"); // rules
$result = $cosClient->putObject(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'object.jpg',
'Body' => fopen('/tmp/local.jpg', 'rb'), // 本地文件
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// ---------------------------- 3. 上传时处理 ---------------------------- //
// --------------------- 4. 云上数据处理 ------------------------------ //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIImageCrop');
$ciProcessParams->addParam('width', 100); // 需要裁剪区域的宽度与height共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片宽度的像素值
$ciProcessParams->addParam('height', 100); // 需要裁剪区域的高度与width共同组成所需裁剪的图片宽高比例输入数字请大于0、小于图片高度的像素值width : height建议取值在[1, 2.5]之间,超过这个范围可能会影响效果
$ciProcessParams->addParam('fixed', 0); // 是否严格按照 width 和 height 的值进行输出。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, 'output.jpg'); // rules
$result = $cosClient->ImageProcess(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// --------------------- 4. 云上数据处理 ------------------------------ //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,79 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
$object = 'xxx.jpg';
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIEnhanceImage');
$ciProcessParams->addParam('denoise', 3); // 去噪强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行去噪操作默认值为3。
$ciProcessParams->addParam('sharpen', 3); // 锐化强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行锐化操作默认值为3。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', $object); // 获取下载链接
echo "{$downloadUrl}&{$query}"; // 携带签名的图片地址以“&”连接
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIEnhanceImage');
$ciProcessParams->addParam('detect-url', 'https://xxx.com/xxx.jpg');
$ciProcessParams->addParam('denoise', 3); // 去噪强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行去噪操作默认值为3。
$ciProcessParams->addParam('sharpen', 3); // 锐化强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行锐化操作默认值为3。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', ''); // 获取下载链接
echo "{$downloadUrl}&{$query}";
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
// ---------------------------- 3. 上传时处理 ---------------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIEnhanceImage');
$ciProcessParams->addParam('denoise', 3); // 去噪强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行去噪操作默认值为3。
$ciProcessParams->addParam('sharpen', 3); // 锐化强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行锐化操作默认值为3。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, "output.png"); // rules
$result = $cosClient->putObject(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'object.jpg',
'Body' => fopen('/tmp/local.jpg', 'rb'), // 本地文件
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// ---------------------------- 3. 上传时处理 ---------------------------- //
// --------------------- 4. 云上数据处理 ------------------------------ //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AIEnhanceImage');
$ciProcessParams->addParam('denoise', 3); // 去噪强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行去噪操作默认值为3。
$ciProcessParams->addParam('sharpen', 3); // 锐化强度值,取值范围为 0 - 5 之间的整数,值为 0 时不进行锐化操作默认值为3。
$ciProcessParams->addParam('ignore-error', 1); // 当此参数为1时针对文件过大等导致处理失败的场景会直接返回原图而不报错。
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, 'output.jpg'); // rules
$result = $cosClient->ImageProcess(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// --------------------- 4. 云上数据处理 ------------------------------ //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,65 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
$object = 'xxx.jpg';
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AISuperResolution');
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', $object); // 获取下载链接
echo "{$downloadUrl}&{$query}"; // 携带签名的图片地址以“&”连接
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AISuperResolution');
$ciProcessParams->addParam('detect-url', 'https://xxx.com/xxx.jpg');
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', ''); // 获取下载链接
echo "{$downloadUrl}&{$query}";
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
// ---------------------------- 3. 上传时处理 ---------------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AISuperResolution');
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, "output.png"); // rules
$result = $cosClient->putObject(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'object.jpg',
'Body' => fopen('/tmp/local.jpg', 'rb'), // 本地文件
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// ---------------------------- 3. 上传时处理 ---------------------------- //
// --------------------- 4. 云上数据处理 ------------------------------ //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('AISuperResolution');
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, 'output.jpg'); // rules
$result = $cosClient->ImageProcess(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// --------------------- 4. 云上数据处理 ------------------------------ //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,40 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
$local_path = "/data/exampleobject";
try {
// -------------------- 1. 卡证识别 原图存储在COS -------------------- //
$result = $cosClient->aILicenseRecProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
'CardType' => 'IDCard', // 卡证识别类型有效值为IDCardDriverLicense。<br>IDCard表示身份证DriverLicense表示驾驶证默认DriverLicense
));
// 请求成功
print_r($result);
// -------------------- 1. 卡证识别 原图存储在COS -------------------- //
// -------------------- 2. 卡证识别 原图来自其他链接 暂不支持 -------------------- //
$result = $cosClient->aILicenseRecProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // 该值为空即可
'DetectUrl' => 'https://www.xxx.com/xxx.jpg',
'CardType' => 'IDCard', // 卡证识别类型有效值为IDCardDriverLicense。<br>IDCard表示身份证DriverLicense表示驾驶证默认DriverLicense
));
// 请求成功
print_r($result);
// -------------------- 2. 卡证识别 原图来自其他链接 暂不支持 -------------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,29 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 实时文字翻译
$result = $cosClient->autoTranslationBlockProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'InputText' => '', // 待翻译的文本
'SourceLang' => '', // 输入语言,如 "zh"
'TargetLang' => '', // 输出语言,如 "en"
// 'TextDomain' => '', // 文本所属业务领域,如: "ecommerce", //缺省值为 general
// 'TextStyle' => '', // 文本类型,如: "title", //缺省值为 sentence
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,24 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须用https
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 关闭AI内容识别服务
$result = $cosClient->closeAiService(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,24 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须用https
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 关闭智能语音服务 https://cloud.tencent.com/document/product/460/95755
$result = $cosClient->closeAsrService(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,23 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
$result = $cosClient->closeImageSlim(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,54 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交一个翻译任务 https://cloud.tencent.com/document/product/460/84799
$result = $cosClient->createAiTranslationJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'Translation',
'Input' => array(
'Object' => 'test.docx',
'Lang' => 'zh',
'Type' => 'docx',
// 'BasicType' => '',
),
'Operation' => array(
// 'UserData' => 'xxx',
// 'JobLevel' => '',
// 'NoNeedOutput' => 'true',
'Translation' => array(
'Lang' => 'en',
'Type' => 'docx',
),
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'xxx.txt',
),
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,45 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交一个分词任务 https://cloud.tencent.com/document/product/460/84800
$result = $cosClient->createAiWordsGeneralizeJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'WordsGeneralize',
'Input' => array(
'Object' => 'test.txt',
),
'Operation' => array(
// 'UserData' => '',
// 'JobLevel' => '',
'WordsGeneralize' => array(
'NerMethod' => 'DL',
'SegMethod' => 'MIX',
),
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,45 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
$result = $cosClient->createM3U8PlayListJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'StartTime' => 1679386006,
'EndTime' => 1679386006,
'Operation' => array(
'M3U8List' => array(
array(
'BucketId' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Index' => '0',
'ObjectPath' => 'test1.m3u8',
),
array(
'BucketId' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Index' => '0',
'ObjectPath' => 'test2.m3u8',
),
),
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Object' => 'xxx.m3u8',
),
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,31 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 创建音频降噪模板 https://cloud.tencent.com/document/product/460/94315
$result = $cosClient->createMediaNoiseReductionTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'NoiseReduction',
'Name' => 'NoiseReduction-Template',
'NoiseReduction' => array(
'Format' => 'wav',
'Samplerate' => '16000',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,90 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交视频人像抠图任务
// start --------------- 使用模版 暂不支持模版ID ----------------- //
$result = $cosClient->createMediaSegmentVideoBodyJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'SegmentVideoBody',
'Input' => array(
'Object' => 'input/test.mp4',
),
'Operation' => array(
'TemplateId' => '',
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'output/out.mp4',
),
// 'UserData' => '',
// 'JobLevel' => '',
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// end --------------- 使用模版 ----------------- //
// start --------------- 自定义参数 ----------------- //
$result = $cosClient->createMediaSegmentVideoBodyJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'SegmentVideoBody',
'Input' => array(
'Object' => 'input/test.mp4',
),
'Operation' => array(
'SegmentVideoBody' => array(
'Mode' => 'Mask',
'SegmentType' => '',
'BackgroundGreen' => '',
'BackgroundBlue' => '',
'BackgroundLogoUrl' => '',
'BinaryThreshold' => '',
'RemoveRed' => '',
'RemoveGreen' => '',
'RemoveBlue' => '',
),
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'output/out.mp4',
),
// 'UserData' => '',
// 'JobLevel' => '',
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// end --------------- 自定义参数 ----------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,34 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 创建智能封面模板 https://cloud.tencent.com/document/product/460/84734
$result = $cosClient->createMediaSmartCoverTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'SmartCover',
'Name' => 'media-smartcover-name',
'SmartCover' => array(
'Format' => 'jpg',
'Width' => '1280',
'Height' => '960',
'Count' => '3',
'DeleteDuplicates' => 'true',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,74 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交视频目标检测任务
// start --------------- 使用模版 ----------------- //
$result = $cosClient->createMediaTargetRecJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'VideoTargetRec',
'Input' => array(
'Object' => 'test.mp4',
),
'Operation' => array(
'TemplateId' => '',
// 'UserData' => 'xxx',
// 'JobLevel' => '0',
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// end --------------- 使用模版 ----------------- //
// start --------------- 自定义参数 ----------------- //
$result = $cosClient->createMediaTargetRecJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'VideoTargetRec',
'Input' => array(
'Object' => 'test.mp4',
),
'Operation' => array(
// 'UserData' => 'xxx',
// 'JobLevel' => '0',
'VideoTargetRec' => array(
'Body' => 'true',
'Pet' => 'true',
'Car' => 'false',
),
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// end --------------- 自定义参数 ----------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,32 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 创建视频目标检测模板
$result = $cosClient->createMediaTargetRecTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'VideoTargetRec',
'Name' => 'template-name',
'VideoTargetRec' => array(
'Body' => 'true',
'Pet' => 'true',
'Car' => 'false',
), // Body、Pet、Car 不能同时为 false
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,61 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 创建音视频转码 pro 模板 https://cloud.tencent.com/document/product/460/84732
$result = $cosClient->createMediaTranscodeProTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'TranscodePro',
'Name' => 'media-transcode-pro-name',
'Container' => array(
'Format' => 'mxf',
),
'Video' => array(
'Codec' => 'xavc',
'Profile' => 'XAVC-HD_intra_420_10bit_class50',
'Width' => '1440',
'Height' => '1080',
'Interlaced' => 'true',
'Fps' => '30000/1001',
'Bitrate' => '',
'Rotate' => '',
),
'TimeInterval' => array(
'Start' => '',
'Duration' => '',
),
'Audio' => array(
'Codec' => '',
'Remove' => '',
),
'TransConfig' => array(
'AdjDarMethod' => '',
'IsCheckReso' => '',
'ResoAdjMethod' => '',
'IsCheckVideoBitrate' => '',
'VideoBitrateAdjMethod' => '',
'IsCheckAudioBitrate' => '',
'AudioBitrateAdjMethod' => '',
'IsCheckVideoFps' => '',
'VideoFpsAdjMethod' => '',
'DeleteMetadata' => '',
'IsHdr2Sdr' => '',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,201 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交画质增强任务 https://cloud.tencent.com/document/product/460/84775
// start --------------- 使用模版 ----------------- //
$result = $cosClient->createMediaVideoEnhanceJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'VideoEnhance',
'Input' => array(
'Object' => 'test.mp4',
),
'Operation' => array(
'TemplateId' => '', // 画质增强模板 ID
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'tmp/output.mp4',
),
// 'UserData' => 'xxx',
// 'JobLevel' => '0',
// 'WatermarkTemplateId' => array(
// 'WatermarkTemplateId-1',
// 'WatermarkTemplateId-2',
// ),
// 'Watermark' => array(
// array(
// 'Type' => '',
// 'Pos' => '',
// 'LocMode' => '',
// 'Dx' => '',
// 'Dy' => '',
// 'StartTime' => '',
// 'EndTime' => '',
// 'Image' => array(
// 'Url' => '',
// 'Mode' => '',
// 'Width' => '',
// 'Height' => '',
// 'Transparency' => '',
// 'Background' => '',
// ),
// 'Text' => array(
// 'FontSize' => '',
// 'FontType' => '',
// 'FontColor' => '',
// 'Transparency' => '',
// 'Text' => '',
// ),
// 'SlideConfig' => array(
// 'SlideMode' => '',
// 'XSlideSpeed' => '',
// 'YSlideSpeed' => '',
// ),
// ),
// ),
// 'DigitalWatermark' => array(
// 'Message' => '',
// 'Type' => '',
// 'Version' => '',
// 'IgnoreError' => '',
// 'State' => '',
// ),
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// end --------------- 使用模版 ----------------- //
// start --------------- 自定义参数 ----------------- //
$result = $cosClient->createMediaVideoEnhanceJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'VideoEnhance',
'Input' => array(
'Object' => 'test.mp4',
),
'Operation' => array(
// 画质增强参数
'VideoEnhance' => array(
'Transcode' => array(
'Container' => array(
'Format' => 'mp4',
),
'Video' => array(
'Codec' => 'H.264',
'Width' => '1280',
'Height' => '920',
'Fps' => '30',
),
'Audio' => array(
'Codec' => 'aac',
'Samplerate' => '44100',
'Bitrate' => '128',
'Channels' => '4',
),
),
'SuperResolution' => array(
'Resolution' => 'sdtohd',
'EnableScaleUp' => 'true',
'Version' => 'Enhance',
),
'SDRtoHDR' => array(
'HdrMode' => 'HDR10',
),
'ColorEnhance' => array(
'Contrast' => '50',
'Correction' => '100',
'Saturation' => '100',
),
'MsSharpen' => array(
'SharpenLevel' => '5',
),
'FrameEnhance' => array(
'FrameDoubling' => 'true',
),
),
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'tmp/output.mp4',
),
// 'UserData' => 'xxx',
// 'JobLevel' => '0',
// 'WatermarkTemplateId' => array(
// 'WatermarkTemplateId-1',
// 'WatermarkTemplateId-2',
// ),
// 'Watermark' => array(
// array(
// 'Type' => '',
// 'Pos' => '',
// 'LocMode' => '',
// 'Dx' => '',
// 'Dy' => '',
// 'StartTime' => '',
// 'EndTime' => '',
// 'Image' => array(
// 'Url' => '',
// 'Mode' => '',
// 'Width' => '',
// 'Height' => '',
// 'Transparency' => '',
// 'Background' => '',
// ),
// 'Text' => array(
// 'FontSize' => '',
// 'FontType' => '',
// 'FontColor' => '',
// 'Transparency' => '',
// 'Text' => '',
// ),
// 'SlideConfig' => array(
// 'SlideMode' => '',
// 'XSlideSpeed' => '',
// 'YSlideSpeed' => '',
// ),
// ),
// ),
// 'DigitalWatermark' => array(
// 'Message' => '',
// 'Type' => '',
// 'Version' => '',
// 'IgnoreError' => '',
// 'State' => '',
// ),
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// end --------------- 自定义参数 ----------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,65 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// https://cloud.tencent.com/document/product/460/84722 创建画质增强模板
$result = $cosClient->createMediaVideoEnhanceTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'VideoEnhance',
'Name' => 'TemplateName',
'VideoEnhance' => array(
'Transcode' => array(
'Container' => array(
'Format' => 'mp4',
),
'Video' => array(
'Codec' => 'H.264',
'Width' => '1280',
'Height' => '920',
'Fps' => '30',
),
'Audio' => array(
'Codec' => 'aac',
'Samplerate' => '44100',
'Bitrate' => '128',
'Channels' => '4',
),
),
'SuperResolution' => array(
'Resolution' => 'sdtohd',
'EnableScaleUp' => 'true',
'Version' => 'Enhance',
),
'SDRtoHDR' => array(
'HdrMode' => 'HDR10',
),
'ColorEnhance' => array(
'Contrast' => '50',
'Correction' => '100',
'Saturation' => '100',
),
'MsSharpen' => array(
'SharpenLevel' => '5',
),
'FrameEnhance' => array(
'FrameDoubling' => 'true',
),
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,41 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交听歌识曲任务 https://cloud.tencent.com/document/product/460/84795
$result = $cosClient->createVoiceSoundHoundJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'SoundHound',
'Input' => array(
'Object' => 'test.mp3',
),
'Operation' => array(
'UserData' => 'xxx', // 透传用户信息
'JobLevel' => '0', // 任务优先级级别限制0 、1 、2。级别越大任务优先级越高默认为0
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,95 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交一个语音识别任务 https://cloud.tencent.com/document/product/460/84798
// 1. 使用模版
$result = $cosClient->createVoiceSpeechRecognitionJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'SpeechRecognition',
'Input' => array(
'Object' => 'test.mp3',
// 'Url' => '',
),
'Operation' => array(
'TemplateId' => '',
// 'UserData' => '',
// 'JobLevel' => '',
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'xxx.txt',
),
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// 2. 自定义参数
$result = $cosClient->createVoiceSpeechRecognitionJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'SpeechRecognition',
'Input' => array(
'Object' => 'test.mp3',
// 'Url' => '',
),
'Operation' => array(
// 'UserData' => '',
// 'JobLevel' => '',
'SpeechRecognition' => array(
'EngineModelType' => '16k_zh',
'ChannelNum' => 1,
'ResTextFormat' => 1,
'FilterDirty' => 0,
'FilterModal' => 1,
'ConvertNumMode' => 0,
'SpeakerDiarization' => 1,
'SpeakerNumber' => 0,
'FilterPunc' => 0,
// 'OutputFileType' => 'txt',
// 'FlashAsr' => 'true',
// 'Format' => 'mp3',
// 'FirstChannelOnly' => 1,
// 'WordInfo' => 1,
// 'SentenceMaxLength' => 6,
),
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'xxx.txt',
),
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,44 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 创建语音识别模板 https://cloud.tencent.com/document/product/460/84498
$result = $cosClient->createVoiceSpeechRecognitionTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'SpeechRecognition',
'Name' => 'voice-speechrecognition-name',
'SpeechRecognition' => array(
'EngineModelType' => '16k_zh',
'ChannelNum' => 1,
'ResTextFormat' => 1,
'FilterDirty' => 0,
'FilterModal' => 1,
'ConvertNumMode' => 0,
'SpeakerDiarization' => 1,
'SpeakerNumber' => 0,
'FilterPunc' => 0,
'OutputFileType' => 'txt',
// 'FlashAsr' => 'true',
// 'Format' => 'mp3',
// 'FirstChannelOnly' => 1,
// 'WordInfo' => 1,
// 'SentenceMaxLength' => 6,
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,86 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交一个语音合成任务 https://cloud.tencent.com/document/product/460/84797
// 1. 使用模版
$result = $cosClient->createVoiceTtsJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'Tts', // 固定为 Tts
'Operation' => array(
'TemplateId' => 't1460606b9752148c4ab182f55163ba7cd',
'TtsConfig' => array(
'InputType' => 'Text',
'Input' => '床前明月光,疑是地上霜',
),
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'demo.mp3',
),
// 'UserData' => 'xxx',
// 'JobLevel' => '0',
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
// 2. 自定义参数
$result = $cosClient->createVoiceTtsJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'Tts', // 固定为 Tts
'Operation' => array(
'TtsConfig' => array(
'InputType' => 'Text',
'Input' => '床前明月光,疑是地上霜',
),
'TtsTpl' => array(
'Mode' => 'Sync',
'Codec' => 'pcm',
'VoiceType' => 'aixiaoxing',
'Volume' => '2',
'Speed' => '200',
'Emotion' => 'arousal',
),
'Output' => array(
'Region' => $region,
'Bucket' => 'examplebucket-125000000',
'Object' => 'demo.mp3',
),
// 'UserData' => 'xxx',
// 'JobLevel' => '0',
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,33 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 创建语音合成模板 https://cloud.tencent.com/document/product/460/84499
$result = $cosClient->createVoiceTtsTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'Tts',
'Name' => 'TemplateName',
'Mode' => 'Sync',
'Codec' => 'pcm',
'VoiceType' => 'aixiaoxing',
'Volume' => '2',
'Speed' => '200',
'Emotion' => 'arousal',
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,44 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 提交音乐评分任务 https://cloud.tencent.com/document/product/460/96095
$result = $cosClient->createVoiceVocalScoreJobs(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Tag' => 'VocalScore',
'Input' => array(
'Object' => 'test.mp3',
),
'Operation' => array(
"VocalScore" => array(
'StandardObject' => 'test.mp3',
),
// 'UserData' => 'xxx', // 透传用户信息
// 'JobLevel' => '0', // 任务优先级级别限制0 、1 、2。级别越大任务优先级越高默认为0
),
// 'CallBack' => '',
// 'CallBackFormat' => '',
// 'CallBackType' => '',
// 'CallBackMqConfig' => array(
// 'MqRegion' => '',
// 'MqMode' => '',
// 'MqName' => '',
// ),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,40 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
$local_path = "/data/exampleobject";
try {
// -------------------- 1. 图片标签 原图存储在COS -------------------- //
$result = $cosClient->detectLabelProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
'Scenes' => '',
));
// 请求成功
print_r($result);
// -------------------- 1. 图片标签 原图存储在COS -------------------- //
// -------------------- 2. 图片标签 原图来自其他链接 -------------------- //
$result = $cosClient->detectLabelProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // 该值为空即可
'DetectUrl' => 'https://www.xxx.com/xxx.jpg',
'Scenes' => '',
));
// 请求成功
print_r($result);
// -------------------- 2. 图片标签 原图来自其他链接 -------------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,38 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
$local_path = "/data/exampleobject";
try {
// -------------------- 1. 宠物识别 原图存储在COS -------------------- //
$result = $cosClient->detectPetProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
));
// 请求成功
print_r($result);
// -------------------- 1. 宠物识别 原图存储在COS -------------------- //
// -------------------- 2. 宠物识别 原图来自其他链接 暂不支持 -------------------- //
// $result = $cosClient->detectPetProcess(array(
// 'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
// 'Key' => '', // 该值为空即可
// 'DetectUrl' => 'https://www.xxx.com/xxx.jpg',
// ));
// // 请求成功
// print_r($result);
// -------------------- 2. 宠物识别 原图来自其他链接 暂不支持 -------------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,30 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 查询 AI 内容识别服务状态 https://cloud.tencent.com/document/product/460/79594
$result = $cosClient->getAiBucketList(array(
// 'Regions' => '', // 可选 地域信息,例如 ap-shanghai、ap-beijing若查询多个地域以“,”分隔字符串
// 'BucketNames' => '', // 可选 存储桶名称,以“,”分隔,支持多个存储桶,精确搜索
// 'BucketName' => '', // 可选 存储桶名称前缀,前缀搜索
// 'PageNumber' => 1, // 可选 第几页
// 'PageSize' => 20, // 可选 每页个数
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,28 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须为https
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 搜索 AI 内容识别队列 https://cloud.tencent.com/document/product/460/79394
$result = $cosClient->getAiQueueList(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
// 'QueueIds' => 'xxx', // 队列 ID以“,”符号分割字符串
// 'State' => 'Active', // Active 表示队列内的作业会被媒体处理服务调度执行, Paused 表示队列暂停,作业不再会被媒体处理调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响
// 'PageNumber' => '1', // 第几页
// 'PageSize' => '10', // 每页个数
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,30 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 查询智能语音服务 https://cloud.tencent.com/document/product/460/46232
$result = $cosClient->getAsrBucketList(array(
// 'Regions' => '', // 可选 地域信息,例如 ap-shanghai、ap-beijing若查询多个地域以“,”分隔字符串
// 'BucketNames' => '', // 可选 存储桶名称,以“,”分隔,支持多个存储桶,精确搜索
// 'BucketName' => '', // 可选 存储桶名称前缀,前缀搜索
// 'PageNumber' => 1, // 可选 第几页
// 'PageSize' => 20, // 可选 每页个数
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,28 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须为https
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 查询智能语音队列 https://cloud.tencent.com/document/product/460/46234
$result = $cosClient->getAsrQueueList(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
// 'QueueIds' => 'xxx', // 队列 ID以“,”符号分割字符串
// 'State' => 'Active', // Active 表示队列内的作业会被媒体处理服务调度执行, Paused 表示队列暂停,作业不再会被媒体处理调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响
// 'PageNumber' => '1', // 第几页
// 'PageSize' => '10', // 每页个数
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,23 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
$result = $cosClient->getImageSlim(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,30 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 查询图片处理服务状态
$result = $cosClient->getPicBucketList(array(
// 'Regions' => '', // 可选 地域信息,例如 ap-shanghai、ap-beijing若查询多个地域以“,”分隔字符串
// 'BucketNames' => '', // 可选 存储桶名称,以“,”分隔,支持多个存储桶,精确搜索
// 'BucketName' => '', // 可选 存储桶名称前缀,前缀搜索
// 'PageNumber' => 1, // 可选 第几页
// 'PageSize' => 20, // 可选 每页个数
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,28 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须为https
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 搜索图片处理队列 https://cloud.tencent.com/document/product/460/79395
$result = $cosClient->getPicQueueList(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
// 'QueueIds' => 'xxx', // 队列 ID以“,”符号分割字符串
// 'State' => 'Active', // Active 表示队列内的作业会被媒体处理服务调度执行, Paused 表示队列暂停,作业不再会被媒体处理调度执行,队列内的所有作业状态维持在暂停状态,已经执行中的任务不受影响
// 'PageNumber' => '1', // 第几页
// 'PageSize' => '10', // 每页个数
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,67 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
$object = 'xxx.jpg';
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('GoodsMatting');
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', $object); // 获取下载链接
echo "{$downloadUrl}&{$query}"; // 携带签名的图片地址以“&”连接
// -------------------- 1. 下载时处理-原图存储在COS -------------------- //
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('GoodsMatting');
$ciProcessParams->addParam('detect-url', 'https://xxx.com/xxx.jpg');
$query = $ciProcessParams->queryString();
$downloadUrl = $cosClient->getObjectUrl('examplebucket-1250000000', ''); // 获取下载链接
echo "{$downloadUrl}&{$query}";
// -------------------- 2. 下载时处理-原图来自其他链接 -------------------- //
// ---------------------------- 3. 上传时处理 ---------------------------- //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('GoodsMatting');
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, "output.png"); // rules
$result = $cosClient->putObject(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'object.jpg',
'Body' => fopen('/tmp/local.jpg', 'rb'), // 本地文件
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// ---------------------------- 3. 上传时处理 ---------------------------- //
// --------------------- 4. 云上数据处理 ------------------------------ //
$ciProcessParams = new Qcloud\Cos\ImageParamTemplate\CIProcessTransformation('GoodsMatting');
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
$picOperations->setIsPicInfo(1); // is_pic_info
$picOperations->addRule($ciProcessParams, 'output.jpg'); // rules
$result = $cosClient->ImageProcess(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
'PicOperations' => $picOperations->queryString(),
));
// 请求成功
print_r($result);
// --------------------- 4. 云上数据处理 ------------------------------ //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,20 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 活体人脸核身 待补充
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,24 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须用https
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 开通 AI 内容识别 https://cloud.tencent.com/document/product/460/79593
$result = $cosClient->openAiService(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,24 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须用https
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 开通智能语音服务 https://cloud.tencent.com/document/product/460/95754
$result = $cosClient->openAsrService(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,30 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials' => array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
$result = $cosClient->openImageSlim(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'SlimMode' => 'API',
'Suffixs' => array(
'Suffix' => array(
'jpg',
'png',
),
),
));
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,38 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
$local_path = "/data/exampleobject";
try {
// -------------------- 1. Logo 识别 原图存储在COS -------------------- //
$result = $cosClient->recognizeLogoProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'test.jpg',
));
// 请求成功
print_r($result);
// -------------------- 1. Logo 识别 原图存储在COS -------------------- //
// -------------------- 2. Logo 识别 原图来自其他链接 -------------------- //
$result = $cosClient->recognizeLogoProcess(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // 该值为空即可
'DetectUrl' => 'https://www.xxx.com/xxx.jpg',
));
// 请求成功
print_r($result);
// -------------------- 2. Logo 识别 原图来自其他链接 -------------------- //
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,102 @@
<?php
/**
* 第一步:获取临时密钥
* 该demo为临时密钥获取sdk的使用示例具体情参考sdk git地址 https://github.com/tencentyun/qcloud-cos-sts-sdk
* 参考文档 https://cloud.tencent.com/document/product/436/14048
* $config 配置中的 allowCiSource 字段为万象资源配置为true时授予万象资源权限
* 拿到临时密钥后可以在cos php sdk中使用 https://github.com/tencentyun/cos-php-sdk-v5
* Array
* (
* [expiredTime] => 1700828878
* [expiration] => 2023-11-24T12:27:58Z
* [credentials] => Array
* (
* [sessionToken] => token
* [tmpSecretId] => secretId
* [tmpSecretKey] => secretKey
* )
*
* [requestId] => 2a521211-b212-xxxx-xxxx-c9976a3966bd
* [startTime] => 1700810878
* )
*/
require_once __DIR__ . '/vendor/autoload.php';
$bucket = 'examplebucket-1250000000';
$secretKey = 'SECRETKEY';
$secretId = 'SECRETID';
$region = "ap-beijing";
$sts = new QCloud\COSSTS\Sts();
$config = array(
'url' => 'https://sts.tencentcloudapi.com/', // url和domain保持一致
'domain' => 'sts.tencentcloudapi.com', // 域名,非必须,默认为 sts.tencentcloudapi.com
'proxy' => '',
'secretId' => $secretId, // 固定密钥,若为明文密钥,请直接以'xxx'形式填入不要填写到getenv()函数中
'secretKey' => $secretKey, // 固定密钥,若为明文密钥,请直接以'xxx'形式填入不要填写到getenv()函数中
'bucket' => $bucket, // 换成你的 bucket
'region' => $region, // 换成 bucket 所在园区
'durationSeconds' => 1800*10, // 密钥有效期
'allowPrefix' => array('/*'), // 这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的具体路径,例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用)
'allowCiSource' => false, // 万象资源配置
'allowActions' => array (
'name/cos:*',
'name/ci:*',
// 具体action按需设置
),
// // 临时密钥生效条件关于condition的详细设置规则和COS支持的condition类型可以参考 https://cloud.tencent.com/document/product/436/71306
// "condition" => array(
// "ip_equal" => array(
// "qcs:ip" => array(
// "10.217.182.3/24",
// "111.21.33.72/24",
// )
// )
// )
);
try {
// 获取临时密钥,计算签名
$tempKeys = $sts->getTempKeys($config);
print_r($tempKeys);
} catch (Exception $e) {
echo $e;
}
/**
* 第二步在cos php sdk中使用临时密钥
* 创建临时密钥生成的Client以文本同步审核为例
*/
// 临时密钥
$tmpSecretId = 'secretId'; // 第一步获取到的 $tempKeys['credentials']['tmpSecretId']
$tmpSecretKey = 'secretKey'; // 第一步获取到的 $tempKeys['credentials']['tmpSecretKey']
$token = 'token'; // 第一步获取到的 $tempKeys['credentials']['sessionToken']
$tokenClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $tmpSecretId ,
'secretKey' => $tmpSecretKey,
'token' => $token,
)
)
);
try {
$content = '敏感词';
$result = $tokenClient->detectText(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Input' => array(
'Content' => base64_encode($content), // 文本需base64_encode
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,38 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须为https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新 AI 内容识别队列 https://cloud.tencent.com/document/product/460/79397
$result = $cosClient->updateAiQueue(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // queueId
'Name' => 'queue-ai-process',
'State' => 'Active',
'NotifyConfig' => array(
'State' => 'Off',
// 'Event' => '',
// 'ResultFormat' => '',
// 'Type' => '',
// 'Url' => '',
// 'MqMode' => '',
// 'MqRegion' => '',
// 'MqName' => '',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,38 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须为https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新智能语音队列 https://cloud.tencent.com/document/product/460/46235
$result = $cosClient->updateAsrQueue(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // queueId
'Name' => 'queue-smart-audio',
'State' => 'Active',
'NotifyConfig' => array(
'State' => 'Off',
// 'Event' => '',
// 'ResultFormat' => '',
// 'Type' => '',
// 'Url' => '',
// 'MqMode' => '',
// 'MqRegion' => '',
// 'MqName' => '',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,32 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新音频降噪模板 https://cloud.tencent.com/document/product/460/94394
$result = $cosClient->updateMediaNoiseReductionTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // TemplateId
'Tag' => 'NoiseReduction',
'Name' => 'NoiseReduction-Template',
'NoiseReduction' => array(
'Format' => 'wav',
'Samplerate' => '16000',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,35 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新智能封面模板 https://cloud.tencent.com/document/product/460/84755
$result = $cosClient->updateMediaSmartCoverTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // TemplateId
'Tag' => 'SmartCover',
'Name' => 'media-smartcover-name',
'SmartCover' => array(
'Format' => 'jpg',
'Width' => '1280',
'Height' => '960',
'Count' => '3',
'DeleteDuplicates' => 'true',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,33 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新视频目标检测模板
$result = $cosClient->updateMediaTargetRecTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // TemplateId
'Tag' => 'VideoTargetRec',
'Name' => 'template-name',
'VideoTargetRec' => array(
'Body' => 'true',
'Pet' => 'true',
'Car' => 'false',
), // Body、Pet、Car 不能同时为 false
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,62 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新音视频转码 pro 模板 https://cloud.tencent.com/document/product/460/84753
$result = $cosClient->updateMediaTranscodeProTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // TemplateId
'Tag' => 'TranscodePro',
'Name' => 'media-transcode-pro-name',
'Container' => array(
'Format' => 'mxf',
),
'Video' => array(
'Codec' => 'xavc',
'Profile' => 'XAVC-HD_intra_420_10bit_class50',
'Width' => '1440',
'Height' => '1080',
'Interlaced' => 'true',
'Fps' => '30000/1001',
'Bitrate' => '',
'Rotate' => '',
),
'TimeInterval' => array(
'Start' => '',
'Duration' => '',
),
'Audio' => array(
'Codec' => '',
'Remove' => '',
),
'TransConfig' => array(
'AdjDarMethod' => '',
'IsCheckReso' => '',
'ResoAdjMethod' => '',
'IsCheckVideoBitrate' => '',
'VideoBitrateAdjMethod' => '',
'IsCheckAudioBitrate' => '',
'AudioBitrateAdjMethod' => '',
'IsCheckVideoFps' => '',
'VideoFpsAdjMethod' => '',
'DeleteMetadata' => '',
'IsHdr2Sdr' => '',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,66 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部默认为http
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// https://cloud.tencent.com/document/product/460/84745 更新画质增强模板
$result = $cosClient->updateMediaVideoEnhanceTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // TemplateId
'Tag' => 'VideoEnhance',
'Name' => 'TemplateName',
'VideoEnhance' => array(
'Transcode' => array(
'Container' => array(
'Format' => 'mp4',
),
'Video' => array(
'Codec' => 'H.264',
'Width' => '1280',
'Height' => '920',
'Fps' => '30',
),
'Audio' => array(
'Codec' => 'aac',
'Samplerate' => '44100',
'Bitrate' => '128',
'Channels' => '4',
),
),
'SuperResolution' => array(
'Resolution' => 'sdtohd',
'EnableScaleUp' => 'true',
'Version' => 'Enhance',
),
'SDRtoHDR' => array(
'HdrMode' => 'HDR10',
),
'ColorEnhance' => array(
'Contrast' => '50',
'Correction' => '100',
'Saturation' => '100',
),
'MsSharpen' => array(
'SharpenLevel' => '5',
),
'FrameEnhance' => array(
'FrameDoubling' => 'true',
),
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,38 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须为https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新图片处理队列 https://cloud.tencent.com/document/product/460/79396
$result = $cosClient->updatePicQueue(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // queueId
'Name' => 'queue-pic-process',
'State' => 'Active',
'NotifyConfig' => array(
'State' => 'Off',
// 'Event' => '',
// 'ResultFormat' => '',
// 'Type' => '',
// 'Url' => '',
// 'MqMode' => '',
// 'MqRegion' => '',
// 'MqName' => '',
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,45 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新语音识别模板 https://cloud.tencent.com/document/product/460/84759
$result = $cosClient->updateVoiceSpeechRecognitionTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // TemplateId
'Tag' => 'SpeechRecognition',
'Name' => 'voice-speechrecognition-name',
'SpeechRecognition' => array(
'EngineModelType' => '16k_zh',
'ChannelNum' => 1,
'ResTextFormat' => 1,
'FilterDirty' => 0,
'FilterModal' => 1,
'ConvertNumMode' => 0,
'SpeakerDiarization' => 1,
'SpeakerNumber' => 0,
'FilterPunc' => 0,
'OutputFileType' => 'txt',
// 'FlashAsr' => 'true',
// 'Format' => 'mp3',
// 'FirstChannelOnly' => 1,
// 'WordInfo' => 1,
// 'SentenceMaxLength' => 6,
),
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,34 @@
<?php
require dirname(__FILE__, 2) . '/vendor/autoload.php';
$secretId = "SECRETID"; //替换为用户的 secretId请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey请登录访问管理控制台进行查看和管理https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region已创建桶归属的region可以在控制台查看https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'scheme' => 'https', // 万象接口必须使用https
'credentials'=> array(
'secretId' => $secretId,
'secretKey' => $secretKey)));
try {
// 更新语音合成模板 https://cloud.tencent.com/document/product/460/84758
$result = $cosClient->updateVoiceTtsTemplate(array(
'Bucket' => 'examplebucket-125000000', //存储桶名称由BucketName-Appid 组成可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => '', // TemplateId
'Tag' => 'Tts',
'Name' => 'TemplateName',
'Mode' => 'Sync',
'Codec' => 'pcm',
'VoiceType' => 'aixiaoxing',
'Volume' => '2',
'Speed' => '200',
'Emotion' => 'arousal',
));
// 请求成功
print_r($result);
} catch (\Exception $e) {
// 请求失败
echo($e);
}

View File

@ -0,0 +1,119 @@
<?php
return [
'İ' => 'i̇',
'µ' => 'μ',
'ſ' => 's',
'ͅ' => 'ι',
'ς' => 'σ',
'ϐ' => 'β',
'ϑ' => 'θ',
'ϕ' => 'φ',
'ϖ' => 'π',
'ϰ' => 'κ',
'ϱ' => 'ρ',
'ϵ' => 'ε',
'ẛ' => 'ṡ',
'' => 'ι',
'ß' => 'ss',
'ʼn' => 'ʼn',
'ǰ' => 'ǰ',
'ΐ' => 'ΐ',
'ΰ' => 'ΰ',
'և' => 'եւ',
'ẖ' => 'ẖ',
'ẗ' => 'ẗ',
'ẘ' => 'ẘ',
'ẙ' => 'ẙ',
'ẚ' => 'aʾ',
'ẞ' => 'ss',
'ὐ' => 'ὐ',
'ὒ' => 'ὒ',
'ὔ' => 'ὔ',
'ὖ' => 'ὖ',
'ᾀ' => 'ἀι',
'ᾁ' => 'ἁι',
'ᾂ' => 'ἂι',
'ᾃ' => 'ἃι',
'ᾄ' => 'ἄι',
'ᾅ' => 'ἅι',
'ᾆ' => 'ἆι',
'ᾇ' => 'ἇι',
'ᾈ' => 'ἀι',
'ᾉ' => 'ἁι',
'ᾊ' => 'ἂι',
'ᾋ' => 'ἃι',
'ᾌ' => 'ἄι',
'ᾍ' => 'ἅι',
'ᾎ' => 'ἆι',
'ᾏ' => 'ἇι',
'ᾐ' => 'ἠι',
'ᾑ' => 'ἡι',
'ᾒ' => 'ἢι',
'ᾓ' => 'ἣι',
'ᾔ' => 'ἤι',
'ᾕ' => 'ἥι',
'ᾖ' => 'ἦι',
'ᾗ' => 'ἧι',
'ᾘ' => 'ἠι',
'ᾙ' => 'ἡι',
'ᾚ' => 'ἢι',
'ᾛ' => 'ἣι',
'ᾜ' => 'ἤι',
'ᾝ' => 'ἥι',
'ᾞ' => 'ἦι',
'ᾟ' => 'ἧι',
'ᾠ' => 'ὠι',
'ᾡ' => 'ὡι',
'ᾢ' => 'ὢι',
'ᾣ' => 'ὣι',
'ᾤ' => 'ὤι',
'ᾥ' => 'ὥι',
'ᾦ' => 'ὦι',
'ᾧ' => 'ὧι',
'ᾨ' => 'ὠι',
'ᾩ' => 'ὡι',
'ᾪ' => 'ὢι',
'ᾫ' => 'ὣι',
'ᾬ' => 'ὤι',
'ᾭ' => 'ὥι',
'ᾮ' => 'ὦι',
'ᾯ' => 'ὧι',
'ᾲ' => 'ὰι',
'ᾳ' => 'αι',
'ᾴ' => 'άι',
'ᾶ' => 'ᾶ',
'ᾷ' => 'ᾶι',
'ᾼ' => 'αι',
'ῂ' => 'ὴι',
'ῃ' => 'ηι',
'ῄ' => 'ήι',
'ῆ' => 'ῆ',
'ῇ' => 'ῆι',
'ῌ' => 'ηι',
'ῒ' => 'ῒ',
'ῖ' => 'ῖ',
'ῗ' => 'ῗ',
'ῢ' => 'ῢ',
'ῤ' => 'ῤ',
'ῦ' => 'ῦ',
'ῧ' => 'ῧ',
'ῲ' => 'ὼι',
'ῳ' => 'ωι',
'ῴ' => 'ώι',
'ῶ' => 'ῶ',
'ῷ' => 'ῶι',
'ῼ' => 'ωι',
'ff' => 'ff',
'fi' => 'fi',
'fl' => 'fl',
'ffi' => 'ffi',
'ffl' => 'ffl',
'ſt' => 'st',
'st' => 'st',
'ﬓ' => 'մն',
'ﬔ' => 'մե',
'ﬕ' => 'մի',
'ﬖ' => 'վն',
'ﬗ' => 'մխ',
];

View File

@ -0,0 +1,51 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (\PHP_VERSION_ID >= 70400 && extension_loaded('curl')) {
/**
* @property string $data
*/
class CURLStringFile extends CURLFile
{
private $data;
public function __construct(string $data, string $postname, string $mime = 'application/octet-stream')
{
$this->data = $data;
parent::__construct('data://application/octet-stream;base64,'.base64_encode($data), $mime, $postname);
}
public function __set(string $name, $value): void
{
if ('data' !== $name) {
$this->$name = $value;
return;
}
if (is_object($value) ? !method_exists($value, '__toString') : !is_scalar($value)) {
throw new \TypeError('Cannot assign '.gettype($value).' to property CURLStringFile::$data of type string');
}
$this->name = 'data://application/octet-stream;base64,'.base64_encode($value);
}
public function __isset(string $name): bool
{
return isset($this->$name);
}
public function &__get(string $name)
{
return $this->$name;
}
}
}

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface as BaseValueResolverInterface;
if (interface_exists(BaseValueResolverInterface::class)) {
/** @internal */
interface ValueResolverInterface extends BaseValueResolverInterface
{
}
} else {
/** @internal */
interface ValueResolverInterface
{
}
}

View File

@ -0,0 +1 @@
console 工具使用 hiddeninput.exe 在 windows 上隐藏密码输入,该二进制文件由第三方提供,相关源码和其他细节可以在 [Hidden Input](https://github.com/Seldaek/hidden-input) 找到。

Binary file not shown.

View File

@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think\route;
/**
* 资源路由注册类
*/
class ResourceRegister
{
/**
* 资源路由
* @var Resource
*/
protected $resource;
/**
* 是否注册过
* @var bool
*/
protected $registered = false;
/**
* 架构函数
* @access public
* @param Resource $resource 资源路由
*/
public function __construct(Resource $resource)
{
$this->resource = $resource;
}
/**
* 注册资源路由
* @access protected
* @return void
*/
protected function register()
{
$this->registered = true;
$this->resource->parseGroupRule($this->resource->getRule());
}
/**
* 动态方法
* @access public
* @param string $method 方法名
* @param array $args 调用参数
* @return mixed
*/
public function __call($method, $args)
{
return call_user_func_array([$this->resource, $method], $args);
}
public function __destruct()
{
if (!$this->registered) {
$this->register();
}
}
}

1
vendor/w7corp/easywechat/docs/.npmrc vendored Normal file
View File

@ -0,0 +1 @@
auto-install-peers=true

View File

@ -0,0 +1,44 @@
# API 调用
该方法将 API 交由开发者自行调用微信有部分新的接口4.x并未全部兼容支持,可以使用该方案去自行封装接口:
例如URL Link接口
```php
$response = $app->httpPostJson('wxa/generate_urllink',[
'path' => 'pages/index/index',
'is_expire' => true,
'expire_type' => 1,
'expire_interval' => 1
]);
```
## 语法说明
```php
httpGet(string $uri, array $query = [])
httpPostJson(string $uri, array $data = [], array $query = [])
```
### GET
```php
$response = $app->httpGet('/cgi-bin/user/list', [
'next_openid' => 'OPENID1',
]);
```
### POST
```php
$response = $app->httpPostJson('/cgi-bin/user/info/updateremark', [
"openid" => "oDF3iY9ffA-hqb2vVvbr7qxf6A0Q",
"remark" => "pangzi"
]);
```

View File

@ -0,0 +1,117 @@
# 小程序发货信息管理
> 微信文档 https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order-shipping/order-shipping.html
## 发货信息录入接口
```php
$data = [
'order_key' => [
'order_number_type' => 1,
'mchid' => '',
'out_trade_no' => ''
],
'logistics_type' => 4,
'delivery_mode' => 1,
'shipping_list' => [
'tracking_no' => '323244567777',
'express_company' => 'DHL',
'item_desc' => '微信红包抱枕*1个',
'contact' => [
'consignor_contact' => '189****1234',
'receiver_contact' => '189****1234'
],
],
'upload_time' => '2022-12-15T13:29:35.120+08:00',
'payer' => [
'openid' => 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o'
]
];
$app->shipping->uploadShippingInfo($data);
```
## 发货信息合单录入接口
```php
$data = [
'order_key' => [
'order_number_type' => 1,
'mchid' => '',
'out_trade_no' => ''
],
'sub_orders' => [
'order_key' => [
'order_number_type' => 1,
'transaction_id' => '',
'mchid' => '',
'out_trade_no' => ''
],
'logistics_type' => 4,
'delivery_mode' => 1,
'shipping_list' => [
'tracking_no' => '323244567777',
'express_company' => 'DHL',
'item_desc' => '微信红包抱枕*1个',
'contact' => [
'consignor_contact' => '189****1234',
'receiver_contact' => '189****1234'
],
],
],
'upload_time' => '2022-12-15T13:29:35.120+08:00',
'payer' => [
'openid' => 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o'
]
];
$app->shipping->uploadCombineShippingInfo($data);
```
## 查询订单发货状态
```php
$data = $app->shipping->getOrder([
'transaction_id' => 'xxx'
]);
```
## 查询订单列表
```php
$data = $app->shipping->getOrderList();
```
## 确认收货提醒接口
```php
$data = [
'transaction_id' => '42000020212023112332159214xx',
'received_time' => ''
];
$app->shipping->notifyConfirmReceive($data);
```
## 消息跳转路径设置接口
```php
$data = [
'path' => 'pages/goods/order_detail?id=xxxx',
];
$app->shipping->setMsgJumpPath($data);
```
## 查询小程序是否已开通发货信息管理服务
```php
$app->shipping->isTradeManaged();
```
## 查询小程序是否已完成交易结算管理确认
```php
$app->shipping->isTradeCompleted();
```

View File

@ -0,0 +1,32 @@
## 文件上传 <version-tag>6.10.0+</version-tag>
由于微信 v3 对文件类上传使用特殊的签名机制,参见:[微信支付 - 图片上传API](https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter2_1_1.shtml)。
因此,我们提供了一个媒体上传方法,方便开发者使用。
```php
$path = '/path/to/your/files/demo.jpg';
$api->uploadMedia('/v3/marketing/favor/media/image-upload', $path);
```
## 自定义 meta 信息
部分接口使用的签名 meta 不一致,所以可以自行传入:
```php
$url = '/v3/...';
$path = '/path/to/your/files/demo.jpg';
$meta = [
'bank_type' => 'CFT',
'filename' => 'demo.jpg',
'sha256' => 'xxxxxxxxxxx',
];
$api->uploadMedia($url, $path, $meta);
```
## 关于 sha256
- 文件,用 `hash_file('sha256', $path)` 计算
- 字符串,用 `hash('sha256', $string)` 计算

Some files were not shown because too many files have changed in this diff Show More