init commit
This commit is contained in:
15
addons/wdsxh/library/alibabacloud/openapi-core/.gitignore
vendored
Normal file
15
addons/wdsxh/library/alibabacloud/openapi-core/.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
composer.phar
|
||||
/vendor/
|
||||
|
||||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
|
||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||
composer.lock
|
||||
|
||||
.vscode/
|
||||
.idea
|
||||
.DS_Store
|
||||
|
||||
cache/
|
||||
*.cache
|
||||
runtime/
|
||||
.php_cs.cache
|
||||
65
addons/wdsxh/library/alibabacloud/openapi-core/.php_cs.dist
Normal file
65
addons/wdsxh/library/alibabacloud/openapi-core/.php_cs.dist
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* This document has been generated with
|
||||
* https://mlocati.github.io/php-cs-fixer-configurator/#version:2.15|configurator
|
||||
* you can change this configuration by importing this file.
|
||||
*/
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRiskyAllowed(true)
|
||||
->setIndent(' ')
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'@PhpCsFixer' => true,
|
||||
'@Symfony:risky' => true,
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'array_indentation' => true,
|
||||
'combine_consecutive_unsets' => true,
|
||||
'method_separation' => true,
|
||||
'single_quote' => true,
|
||||
'declare_equal_normalize' => true,
|
||||
'function_typehint_space' => true,
|
||||
'hash_to_slash_comment' => true,
|
||||
'include' => true,
|
||||
'lowercase_cast' => true,
|
||||
'no_multiline_whitespace_before_semicolons' => true,
|
||||
'no_leading_import_slash' => true,
|
||||
'no_multiline_whitespace_around_double_arrow' => true,
|
||||
'no_spaces_around_offset' => true,
|
||||
'no_unneeded_control_parentheses' => true,
|
||||
'no_unused_imports' => true,
|
||||
'no_whitespace_before_comma_in_array' => true,
|
||||
'no_whitespace_in_blank_line' => true,
|
||||
'object_operator_without_whitespace' => true,
|
||||
'single_blank_line_before_namespace' => true,
|
||||
'single_class_element_per_statement' => true,
|
||||
'space_after_semicolon' => true,
|
||||
'standardize_not_equals' => true,
|
||||
'ternary_operator_spaces' => true,
|
||||
'trailing_comma_in_multiline_array' => true,
|
||||
'trim_array_spaces' => true,
|
||||
'unary_operator_spaces' => true,
|
||||
'whitespace_after_comma_in_array' => true,
|
||||
'no_extra_consecutive_blank_lines' => [
|
||||
'curly_brace_block',
|
||||
'extra',
|
||||
'parenthesis_brace_block',
|
||||
'square_brace_block',
|
||||
'throw',
|
||||
'use',
|
||||
],
|
||||
'binary_operator_spaces' => [
|
||||
'align_double_arrow' => true,
|
||||
'align_equals' => true,
|
||||
],
|
||||
'braces' => [
|
||||
'allow_single_line_closure' => true,
|
||||
],
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->exclude('vendor')
|
||||
->exclude('tests')
|
||||
->in(__DIR__)
|
||||
);
|
||||
31
addons/wdsxh/library/alibabacloud/openapi-core/README-CN.md
Normal file
31
addons/wdsxh/library/alibabacloud/openapi-core/README-CN.md
Normal file
@@ -0,0 +1,31 @@
|
||||
[English](README.md) | 简体中文
|
||||
|
||||

|
||||
|
||||
## Alibaba Cloud OpenApi Client
|
||||
|
||||
## 安装
|
||||
|
||||
### Composer
|
||||
|
||||
```bash
|
||||
composer require alibabacloud/openapi-core
|
||||
```
|
||||
|
||||
## 问题
|
||||
|
||||
[提交 Issue](https://github.com/aliyun/darabonba-openapi/issues/new),不符合指南的问题可能会立即关闭。
|
||||
|
||||
## 发行说明
|
||||
|
||||
每个版本的详细更改记录在[发行说明](./ChangeLog.txt)中。
|
||||
|
||||
## 相关
|
||||
|
||||
* [最新源码](https://github.com/aliyun/darabonba-openapi)
|
||||
|
||||
## 许可证
|
||||
|
||||
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
|
||||
31
addons/wdsxh/library/alibabacloud/openapi-core/README.md
Normal file
31
addons/wdsxh/library/alibabacloud/openapi-core/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
English | [简体中文](README-CN.md)
|
||||
|
||||

|
||||
|
||||
## Alibaba Cloud OpenApi Client
|
||||
|
||||
## Installation
|
||||
|
||||
### Composer
|
||||
|
||||
```bash
|
||||
composer require alibabacloud/openapi-core
|
||||
```
|
||||
|
||||
## Issues
|
||||
|
||||
[Opening an Issue](https://github.com/aliyun/darabonba-openapi/issues/new), Issues not conforming to the guidelines may be closed immediately.
|
||||
|
||||
## Changelog
|
||||
|
||||
Detailed changes for each release are documented in the [release notes](./ChangeLog.txt).
|
||||
|
||||
## References
|
||||
|
||||
* [Latest Release](https://github.com/aliyun/darabonba-openapi)
|
||||
|
||||
## License
|
||||
|
||||
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
|
||||
15
addons/wdsxh/library/alibabacloud/openapi-core/autoload.php
Normal file
15
addons/wdsxh/library/alibabacloud/openapi-core/autoload.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
if (file_exists(__DIR__ . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php')) {
|
||||
require_once __DIR__ . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
}
|
||||
|
||||
spl_autoload_register(function ($class) {
|
||||
$name = str_replace('Darabonba\\OpenApi\\', '', $class);
|
||||
$file = __DIR__ . \DIRECTORY_SEPARATOR . 'src' . \DIRECTORY_SEPARATOR . str_replace('\\', \DIRECTORY_SEPARATOR, $name) . '.php';
|
||||
if (file_exists($file)) {
|
||||
require_once $file;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
39
addons/wdsxh/library/alibabacloud/openapi-core/composer.json
Normal file
39
addons/wdsxh/library/alibabacloud/openapi-core/composer.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "alibabacloud/openapi-core",
|
||||
"description": "Alibaba Cloud OpenApi Client Core",
|
||||
"type": "library",
|
||||
"license": "Apache-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alibaba Cloud SDK",
|
||||
"email": "sdk-team@alibabacloud.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">5.5",
|
||||
"alibabacloud/credentials": "^1.2.2",
|
||||
"alibabacloud/darabonba": "^1",
|
||||
"alibabacloud/gateway-spi": "^1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/dotenv": "^3.4",
|
||||
"phpunit/phpunit": "^4.8.35|^5.4.3|^9.3",
|
||||
"symfony/var-dumper": "^3.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Darabonba\\OpenApi\\": "src"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"fixer": "php-cs-fixer fix ./"
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true,
|
||||
"preferred-install": "dist",
|
||||
"optimize-autoloader": true
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"github": "https://github.com/aliyun/darabonba-openapi",
|
||||
"main": "src/OpenApiClient.php"
|
||||
}
|
||||
31
addons/wdsxh/library/alibabacloud/openapi-core/phpunit.xml
Normal file
31
addons/wdsxh/library/alibabacloud/openapi-core/phpunit.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="./tests/bootstrap.php" colors="true" processIsolation="false" stopOnFailure="false"
|
||||
convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true"
|
||||
testSuiteLoaderFile="phpunit/src/Runner/StandardTestSuiteLoader.php">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="All">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>integration</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-html" target="cache/coverage" lowUpperBound="35" highLowerBound="70"/>
|
||||
<log type="coverage-clover" target="cache/coverage.clover"/>
|
||||
</logging>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class AlibabaCloudException extends DaraException {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $statusCode;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $code;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $message;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $requestId;
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
$this->statusCode = $map['statusCode'];
|
||||
$this->code = $map['code'];
|
||||
$this->message = $map['message'];
|
||||
$this->description = $map['description'];
|
||||
$this->requestId = $map['requestId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class ClientException extends DaraException {
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
public $accessDeniedDetail;
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
$this->accessDeniedDetail = $map['accessDeniedDetail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getAccessDeniedDetail()
|
||||
{
|
||||
return $this->accessDeniedDetail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class ServerException extends DaraException {
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Exceptions;
|
||||
use AlibabaCloud\Dara\Exception\DaraException;
|
||||
class ThrottlingException extends DaraException {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $retryAfter;
|
||||
|
||||
public function __construct($map)
|
||||
{
|
||||
parent::__construct($map);
|
||||
$this->retryAfter = $map['retryAfter'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRetryAfter()
|
||||
{
|
||||
return $this->retryAfter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,464 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use AlibabaCloud\Credentials\Credential;
|
||||
use Darabonba\OpenApi\Models\GlobalParameters;
|
||||
use AlibabaCloud\Dara\RetryPolicy\RetryOptions;
|
||||
/**
|
||||
* @remarks
|
||||
* Model for initing client
|
||||
*/
|
||||
class Config extends Model {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeyId;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeySecret;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $securityToken;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $bearerToken;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $protocol;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $method;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $regionId;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $readTimeout;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $connectTimeout;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $httpProxy;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $httpsProxy;
|
||||
/**
|
||||
* @var Credential
|
||||
*/
|
||||
public $credential;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpoint;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $noProxy;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $maxIdleConns;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $network;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $userAgent;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $suffix;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $socks5Proxy;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $socks5NetWork;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpointType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $openPlatformEndpoint;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $signatureVersion;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $signatureAlgorithm;
|
||||
/**
|
||||
* @var GlobalParameters
|
||||
*/
|
||||
public $globalParameters;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $key;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $cert;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ca;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
public $disableHttp2;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $tlsMinVersion;
|
||||
/**
|
||||
* @var RetryOptions
|
||||
*/
|
||||
public $retryOptions;
|
||||
protected $_name = [
|
||||
'accessKeyId' => 'accessKeyId',
|
||||
'accessKeySecret' => 'accessKeySecret',
|
||||
'securityToken' => 'securityToken',
|
||||
'bearerToken' => 'bearerToken',
|
||||
'protocol' => 'protocol',
|
||||
'method' => 'method',
|
||||
'regionId' => 'regionId',
|
||||
'readTimeout' => 'readTimeout',
|
||||
'connectTimeout' => 'connectTimeout',
|
||||
'httpProxy' => 'httpProxy',
|
||||
'httpsProxy' => 'httpsProxy',
|
||||
'credential' => 'credential',
|
||||
'endpoint' => 'endpoint',
|
||||
'noProxy' => 'noProxy',
|
||||
'maxIdleConns' => 'maxIdleConns',
|
||||
'network' => 'network',
|
||||
'userAgent' => 'userAgent',
|
||||
'suffix' => 'suffix',
|
||||
'socks5Proxy' => 'socks5Proxy',
|
||||
'socks5NetWork' => 'socks5NetWork',
|
||||
'endpointType' => 'endpointType',
|
||||
'openPlatformEndpoint' => 'openPlatformEndpoint',
|
||||
'type' => 'type',
|
||||
'signatureVersion' => 'signatureVersion',
|
||||
'signatureAlgorithm' => 'signatureAlgorithm',
|
||||
'globalParameters' => 'globalParameters',
|
||||
'key' => 'key',
|
||||
'cert' => 'cert',
|
||||
'ca' => 'ca',
|
||||
'disableHttp2' => 'disableHttp2',
|
||||
'tlsMinVersion' => 'tlsMinVersion',
|
||||
'retryOptions' => 'retryOptions',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(null !== $this->credential) {
|
||||
$this->credential->validate();
|
||||
}
|
||||
if(null !== $this->globalParameters) {
|
||||
$this->globalParameters->validate();
|
||||
}
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->accessKeyId) {
|
||||
$res['accessKeyId'] = $this->accessKeyId;
|
||||
}
|
||||
|
||||
if (null !== $this->accessKeySecret) {
|
||||
$res['accessKeySecret'] = $this->accessKeySecret;
|
||||
}
|
||||
|
||||
if (null !== $this->securityToken) {
|
||||
$res['securityToken'] = $this->securityToken;
|
||||
}
|
||||
|
||||
if (null !== $this->bearerToken) {
|
||||
$res['bearerToken'] = $this->bearerToken;
|
||||
}
|
||||
|
||||
if (null !== $this->protocol) {
|
||||
$res['protocol'] = $this->protocol;
|
||||
}
|
||||
|
||||
if (null !== $this->method) {
|
||||
$res['method'] = $this->method;
|
||||
}
|
||||
|
||||
if (null !== $this->regionId) {
|
||||
$res['regionId'] = $this->regionId;
|
||||
}
|
||||
|
||||
if (null !== $this->readTimeout) {
|
||||
$res['readTimeout'] = $this->readTimeout;
|
||||
}
|
||||
|
||||
if (null !== $this->connectTimeout) {
|
||||
$res['connectTimeout'] = $this->connectTimeout;
|
||||
}
|
||||
|
||||
if (null !== $this->httpProxy) {
|
||||
$res['httpProxy'] = $this->httpProxy;
|
||||
}
|
||||
|
||||
if (null !== $this->httpsProxy) {
|
||||
$res['httpsProxy'] = $this->httpsProxy;
|
||||
}
|
||||
|
||||
if (null !== $this->credential) {
|
||||
$res['credential'] = $this->credential;
|
||||
}
|
||||
|
||||
if (null !== $this->endpoint) {
|
||||
$res['endpoint'] = $this->endpoint;
|
||||
}
|
||||
|
||||
if (null !== $this->noProxy) {
|
||||
$res['noProxy'] = $this->noProxy;
|
||||
}
|
||||
|
||||
if (null !== $this->maxIdleConns) {
|
||||
$res['maxIdleConns'] = $this->maxIdleConns;
|
||||
}
|
||||
|
||||
if (null !== $this->network) {
|
||||
$res['network'] = $this->network;
|
||||
}
|
||||
|
||||
if (null !== $this->userAgent) {
|
||||
$res['userAgent'] = $this->userAgent;
|
||||
}
|
||||
|
||||
if (null !== $this->suffix) {
|
||||
$res['suffix'] = $this->suffix;
|
||||
}
|
||||
|
||||
if (null !== $this->socks5Proxy) {
|
||||
$res['socks5Proxy'] = $this->socks5Proxy;
|
||||
}
|
||||
|
||||
if (null !== $this->socks5NetWork) {
|
||||
$res['socks5NetWork'] = $this->socks5NetWork;
|
||||
}
|
||||
|
||||
if (null !== $this->endpointType) {
|
||||
$res['endpointType'] = $this->endpointType;
|
||||
}
|
||||
|
||||
if (null !== $this->openPlatformEndpoint) {
|
||||
$res['openPlatformEndpoint'] = $this->openPlatformEndpoint;
|
||||
}
|
||||
|
||||
if (null !== $this->type) {
|
||||
$res['type'] = $this->type;
|
||||
}
|
||||
|
||||
if (null !== $this->signatureVersion) {
|
||||
$res['signatureVersion'] = $this->signatureVersion;
|
||||
}
|
||||
|
||||
if (null !== $this->signatureAlgorithm) {
|
||||
$res['signatureAlgorithm'] = $this->signatureAlgorithm;
|
||||
}
|
||||
|
||||
if (null !== $this->globalParameters) {
|
||||
$res['globalParameters'] = null !== $this->globalParameters ? $this->globalParameters->toArray($noStream) : $this->globalParameters;
|
||||
}
|
||||
|
||||
if (null !== $this->key) {
|
||||
$res['key'] = $this->key;
|
||||
}
|
||||
|
||||
if (null !== $this->cert) {
|
||||
$res['cert'] = $this->cert;
|
||||
}
|
||||
|
||||
if (null !== $this->ca) {
|
||||
$res['ca'] = $this->ca;
|
||||
}
|
||||
|
||||
if (null !== $this->disableHttp2) {
|
||||
$res['disableHttp2'] = $this->disableHttp2;
|
||||
}
|
||||
|
||||
if (null !== $this->tlsMinVersion) {
|
||||
$res['tlsMinVersion'] = $this->tlsMinVersion;
|
||||
}
|
||||
|
||||
if (null !== $this->retryOptions) {
|
||||
$res['retryOptions'] = null !== $this->retryOptions ? $this->retryOptions->toArray($noStream) : $this->retryOptions;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['accessKeyId'])) {
|
||||
$model->accessKeyId = $map['accessKeyId'];
|
||||
}
|
||||
|
||||
if (isset($map['accessKeySecret'])) {
|
||||
$model->accessKeySecret = $map['accessKeySecret'];
|
||||
}
|
||||
|
||||
if (isset($map['securityToken'])) {
|
||||
$model->securityToken = $map['securityToken'];
|
||||
}
|
||||
|
||||
if (isset($map['bearerToken'])) {
|
||||
$model->bearerToken = $map['bearerToken'];
|
||||
}
|
||||
|
||||
if (isset($map['protocol'])) {
|
||||
$model->protocol = $map['protocol'];
|
||||
}
|
||||
|
||||
if (isset($map['method'])) {
|
||||
$model->method = $map['method'];
|
||||
}
|
||||
|
||||
if (isset($map['regionId'])) {
|
||||
$model->regionId = $map['regionId'];
|
||||
}
|
||||
|
||||
if (isset($map['readTimeout'])) {
|
||||
$model->readTimeout = $map['readTimeout'];
|
||||
}
|
||||
|
||||
if (isset($map['connectTimeout'])) {
|
||||
$model->connectTimeout = $map['connectTimeout'];
|
||||
}
|
||||
|
||||
if (isset($map['httpProxy'])) {
|
||||
$model->httpProxy = $map['httpProxy'];
|
||||
}
|
||||
|
||||
if (isset($map['httpsProxy'])) {
|
||||
$model->httpsProxy = $map['httpsProxy'];
|
||||
}
|
||||
|
||||
if (isset($map['credential'])) {
|
||||
$model->credential = $map['credential'];
|
||||
}
|
||||
|
||||
if (isset($map['endpoint'])) {
|
||||
$model->endpoint = $map['endpoint'];
|
||||
}
|
||||
|
||||
if (isset($map['noProxy'])) {
|
||||
$model->noProxy = $map['noProxy'];
|
||||
}
|
||||
|
||||
if (isset($map['maxIdleConns'])) {
|
||||
$model->maxIdleConns = $map['maxIdleConns'];
|
||||
}
|
||||
|
||||
if (isset($map['network'])) {
|
||||
$model->network = $map['network'];
|
||||
}
|
||||
|
||||
if (isset($map['userAgent'])) {
|
||||
$model->userAgent = $map['userAgent'];
|
||||
}
|
||||
|
||||
if (isset($map['suffix'])) {
|
||||
$model->suffix = $map['suffix'];
|
||||
}
|
||||
|
||||
if (isset($map['socks5Proxy'])) {
|
||||
$model->socks5Proxy = $map['socks5Proxy'];
|
||||
}
|
||||
|
||||
if (isset($map['socks5NetWork'])) {
|
||||
$model->socks5NetWork = $map['socks5NetWork'];
|
||||
}
|
||||
|
||||
if (isset($map['endpointType'])) {
|
||||
$model->endpointType = $map['endpointType'];
|
||||
}
|
||||
|
||||
if (isset($map['openPlatformEndpoint'])) {
|
||||
$model->openPlatformEndpoint = $map['openPlatformEndpoint'];
|
||||
}
|
||||
|
||||
if (isset($map['type'])) {
|
||||
$model->type = $map['type'];
|
||||
}
|
||||
|
||||
if (isset($map['signatureVersion'])) {
|
||||
$model->signatureVersion = $map['signatureVersion'];
|
||||
}
|
||||
|
||||
if (isset($map['signatureAlgorithm'])) {
|
||||
$model->signatureAlgorithm = $map['signatureAlgorithm'];
|
||||
}
|
||||
|
||||
if (isset($map['globalParameters'])) {
|
||||
$model->globalParameters = GlobalParameters::fromMap($map['globalParameters']);
|
||||
}
|
||||
|
||||
if (isset($map['key'])) {
|
||||
$model->key = $map['key'];
|
||||
}
|
||||
|
||||
if (isset($map['cert'])) {
|
||||
$model->cert = $map['cert'];
|
||||
}
|
||||
|
||||
if (isset($map['ca'])) {
|
||||
$model->ca = $map['ca'];
|
||||
}
|
||||
|
||||
if (isset($map['disableHttp2'])) {
|
||||
$model->disableHttp2 = $map['disableHttp2'];
|
||||
}
|
||||
|
||||
if (isset($map['tlsMinVersion'])) {
|
||||
$model->tlsMinVersion = $map['tlsMinVersion'];
|
||||
}
|
||||
|
||||
if (isset($map['retryOptions'])) {
|
||||
$model->retryOptions = RetryOptions::fromMap($map['retryOptions']);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
class GlobalParameters extends Model {
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $headers;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $queries;
|
||||
protected $_name = [
|
||||
'headers' => 'headers',
|
||||
'queries' => 'queries',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(is_array($this->headers)) {
|
||||
Model::validateArray($this->headers);
|
||||
}
|
||||
if(is_array($this->queries)) {
|
||||
Model::validateArray($this->queries);
|
||||
}
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->headers) {
|
||||
if(is_array($this->headers)) {
|
||||
$res['headers'] = [];
|
||||
foreach($this->headers as $key1 => $value1) {
|
||||
$res['headers'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->queries) {
|
||||
if(is_array($this->queries)) {
|
||||
$res['queries'] = [];
|
||||
foreach($this->queries as $key1 => $value1) {
|
||||
$res['queries'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['headers'])) {
|
||||
if(!empty($map['headers'])) {
|
||||
$model->headers = [];
|
||||
foreach($map['headers'] as $key1 => $value1) {
|
||||
$model->headers[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['queries'])) {
|
||||
if(!empty($map['queries'])) {
|
||||
$model->queries = [];
|
||||
foreach($map['queries'] as $key1 => $value1) {
|
||||
$model->queries[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use GuzzleHttp\Psr7\Stream;
|
||||
class OpenApiRequest extends Model {
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $headers;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $query;
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $body;
|
||||
/**
|
||||
* @var Stream
|
||||
*/
|
||||
public $stream;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $hostMap;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpointOverride;
|
||||
protected $_name = [
|
||||
'headers' => 'headers',
|
||||
'query' => 'query',
|
||||
'body' => 'body',
|
||||
'stream' => 'stream',
|
||||
'hostMap' => 'hostMap',
|
||||
'endpointOverride' => 'endpointOverride',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(is_array($this->headers)) {
|
||||
Model::validateArray($this->headers);
|
||||
}
|
||||
if(is_array($this->query)) {
|
||||
Model::validateArray($this->query);
|
||||
}
|
||||
if(is_array($this->hostMap)) {
|
||||
Model::validateArray($this->hostMap);
|
||||
}
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->headers) {
|
||||
if(is_array($this->headers)) {
|
||||
$res['headers'] = [];
|
||||
foreach($this->headers as $key1 => $value1) {
|
||||
$res['headers'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->query) {
|
||||
if(is_array($this->query)) {
|
||||
$res['query'] = [];
|
||||
foreach($this->query as $key1 => $value1) {
|
||||
$res['query'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->body) {
|
||||
$res['body'] = $this->body;
|
||||
}
|
||||
|
||||
if (null !== $this->stream) {
|
||||
$res['stream'] = $this->stream;
|
||||
}
|
||||
|
||||
if (null !== $this->hostMap) {
|
||||
if(is_array($this->hostMap)) {
|
||||
$res['hostMap'] = [];
|
||||
foreach($this->hostMap as $key1 => $value1) {
|
||||
$res['hostMap'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->endpointOverride) {
|
||||
$res['endpointOverride'] = $this->endpointOverride;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['headers'])) {
|
||||
if(!empty($map['headers'])) {
|
||||
$model->headers = [];
|
||||
foreach($map['headers'] as $key1 => $value1) {
|
||||
$model->headers[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['query'])) {
|
||||
if(!empty($map['query'])) {
|
||||
$model->query = [];
|
||||
foreach($map['query'] as $key1 => $value1) {
|
||||
$model->query[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['body'])) {
|
||||
$model->body = $map['body'];
|
||||
}
|
||||
|
||||
if (isset($map['stream'])) {
|
||||
$model->stream = $map['stream'];
|
||||
}
|
||||
|
||||
if (isset($map['hostMap'])) {
|
||||
if(!empty($map['hostMap'])) {
|
||||
$model->hostMap = [];
|
||||
foreach($map['hostMap'] as $key1 => $value1) {
|
||||
$model->hostMap[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['endpointOverride'])) {
|
||||
$model->endpointOverride = $map['endpointOverride'];
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
class Params extends Model {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $action;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $version;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $protocol;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $pathname;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $method;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $authType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $bodyType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $reqBodyType;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $style;
|
||||
protected $_name = [
|
||||
'action' => 'action',
|
||||
'version' => 'version',
|
||||
'protocol' => 'protocol',
|
||||
'pathname' => 'pathname',
|
||||
'method' => 'method',
|
||||
'authType' => 'authType',
|
||||
'bodyType' => 'bodyType',
|
||||
'reqBodyType' => 'reqBodyType',
|
||||
'style' => 'style',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
Model::validateRequired('action', $this->action, true);
|
||||
Model::validateRequired('version', $this->version, true);
|
||||
Model::validateRequired('protocol', $this->protocol, true);
|
||||
Model::validateRequired('pathname', $this->pathname, true);
|
||||
Model::validateRequired('method', $this->method, true);
|
||||
Model::validateRequired('authType', $this->authType, true);
|
||||
Model::validateRequired('bodyType', $this->bodyType, true);
|
||||
Model::validateRequired('reqBodyType', $this->reqBodyType, true);
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->action) {
|
||||
$res['action'] = $this->action;
|
||||
}
|
||||
|
||||
if (null !== $this->version) {
|
||||
$res['version'] = $this->version;
|
||||
}
|
||||
|
||||
if (null !== $this->protocol) {
|
||||
$res['protocol'] = $this->protocol;
|
||||
}
|
||||
|
||||
if (null !== $this->pathname) {
|
||||
$res['pathname'] = $this->pathname;
|
||||
}
|
||||
|
||||
if (null !== $this->method) {
|
||||
$res['method'] = $this->method;
|
||||
}
|
||||
|
||||
if (null !== $this->authType) {
|
||||
$res['authType'] = $this->authType;
|
||||
}
|
||||
|
||||
if (null !== $this->bodyType) {
|
||||
$res['bodyType'] = $this->bodyType;
|
||||
}
|
||||
|
||||
if (null !== $this->reqBodyType) {
|
||||
$res['reqBodyType'] = $this->reqBodyType;
|
||||
}
|
||||
|
||||
if (null !== $this->style) {
|
||||
$res['style'] = $this->style;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['action'])) {
|
||||
$model->action = $map['action'];
|
||||
}
|
||||
|
||||
if (isset($map['version'])) {
|
||||
$model->version = $map['version'];
|
||||
}
|
||||
|
||||
if (isset($map['protocol'])) {
|
||||
$model->protocol = $map['protocol'];
|
||||
}
|
||||
|
||||
if (isset($map['pathname'])) {
|
||||
$model->pathname = $map['pathname'];
|
||||
}
|
||||
|
||||
if (isset($map['method'])) {
|
||||
$model->method = $map['method'];
|
||||
}
|
||||
|
||||
if (isset($map['authType'])) {
|
||||
$model->authType = $map['authType'];
|
||||
}
|
||||
|
||||
if (isset($map['bodyType'])) {
|
||||
$model->bodyType = $map['bodyType'];
|
||||
}
|
||||
|
||||
if (isset($map['reqBodyType'])) {
|
||||
$model->reqBodyType = $map['reqBodyType'];
|
||||
}
|
||||
|
||||
if (isset($map['style'])) {
|
||||
$model->style = $map['style'];
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi\Models;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use AlibabaCloud\Dara\SSE\Event;
|
||||
class SSEResponse extends Model {
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $headers;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $statusCode;
|
||||
/**
|
||||
* @var Event
|
||||
*/
|
||||
public $event;
|
||||
protected $_name = [
|
||||
'headers' => 'headers',
|
||||
'statusCode' => 'statusCode',
|
||||
'event' => 'event',
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if(is_array($this->headers)) {
|
||||
Model::validateArray($this->headers);
|
||||
}
|
||||
Model::validateRequired('headers', $this->headers, true);
|
||||
Model::validateRequired('statusCode', $this->statusCode, true);
|
||||
Model::validateRequired('event', $this->event, true);
|
||||
parent::validate();
|
||||
}
|
||||
|
||||
public function toArray($noStream = false)
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->headers) {
|
||||
if(is_array($this->headers)) {
|
||||
$res['headers'] = [];
|
||||
foreach($this->headers as $key1 => $value1) {
|
||||
$res['headers'][$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->statusCode) {
|
||||
$res['statusCode'] = $this->statusCode;
|
||||
}
|
||||
|
||||
if (null !== $this->event) {
|
||||
$res['event'] = null !== $this->event ? $this->event->toArray($noStream) : $this->event;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function toMap($noStream = false)
|
||||
{
|
||||
return $this->toArray($noStream);
|
||||
}
|
||||
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['headers'])) {
|
||||
if(!empty($map['headers'])) {
|
||||
$model->headers = [];
|
||||
foreach($map['headers'] as $key1 => $value1) {
|
||||
$model->headers[$key1] = $value1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($map['statusCode'])) {
|
||||
$model->statusCode = $map['statusCode'];
|
||||
}
|
||||
|
||||
if (isset($map['event'])) {
|
||||
$model->event = Event::fromMap($map['event']);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
1867
addons/wdsxh/library/alibabacloud/openapi-core/src/OpenApiClient.php
Normal file
1867
addons/wdsxh/library/alibabacloud/openapi-core/src/OpenApiClient.php
Normal file
File diff suppressed because it is too large
Load Diff
684
addons/wdsxh/library/alibabacloud/openapi-core/src/Utils.php
Normal file
684
addons/wdsxh/library/alibabacloud/openapi-core/src/Utils.php
Normal file
@@ -0,0 +1,684 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
|
||||
namespace Darabonba\OpenApi;
|
||||
use AlibabaCloud\Dara\Model;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Dara\Request;
|
||||
use AlibabaCloud\Dara\Util\BytesUtil;
|
||||
/**
|
||||
* @remarks
|
||||
* This is for OpenApi Util
|
||||
*/
|
||||
class Utils {
|
||||
|
||||
private static $defaultUserAgent = '';
|
||||
/**
|
||||
* @remarks
|
||||
* Convert all params of body other than type of readable into content
|
||||
*
|
||||
* @param body - source Model
|
||||
* @param content - target Model
|
||||
* @returns void
|
||||
* @param Model $body
|
||||
* @param Model $content
|
||||
* @return void
|
||||
*/
|
||||
static public function convert($body, $content)
|
||||
{
|
||||
$map = $body->toMap();
|
||||
$map = self::exceptStream($map);
|
||||
$newContent = $content::fromMap($map);
|
||||
$class = new \ReflectionClass($newContent);
|
||||
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$name = $property->getName();
|
||||
if (!$property->isStatic()) {
|
||||
$content->{$name} = $property->getValue($newContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function exceptStream($map)
|
||||
{
|
||||
if ($map instanceof StreamInterface) {
|
||||
return null;
|
||||
} elseif (\is_array($map)) {
|
||||
$data = [];
|
||||
foreach ($map as $k => $v) {
|
||||
if (null !== $v) {
|
||||
$item = self::exceptStream($v);
|
||||
if (null !== $item) {
|
||||
$data[$k] = $item;
|
||||
}
|
||||
} else {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* If endpointType is internal, use internal endpoint
|
||||
* If serverUse is true and endpointType is accelerate, use accelerate endpoint
|
||||
* Default return endpoint
|
||||
*
|
||||
* @param serverUse - whether use accelerate endpoint
|
||||
* @param endpointType - value must be internal or accelerate
|
||||
* @returns the final endpoint
|
||||
* @param string $endpoint
|
||||
* @param boolean $useAccelerate
|
||||
* @param string $endpointType
|
||||
* @return string
|
||||
*/
|
||||
static public function getEndpoint($endpoint, $useAccelerate, $endpointType)
|
||||
{
|
||||
if ('internal' == $endpointType) {
|
||||
$tmp = explode('.', $endpoint);
|
||||
$tmp[0] .= '-internal';
|
||||
$endpoint = implode('.', $tmp);
|
||||
}
|
||||
if ($useAccelerate && 'accelerate' == $endpointType) {
|
||||
return 'oss-accelerate.aliyuncs.com';
|
||||
}
|
||||
|
||||
return $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get throttling param
|
||||
*
|
||||
* @param the - response headers
|
||||
* @returns time left
|
||||
* @param string[] $headers
|
||||
* @return int
|
||||
*/
|
||||
public static function getThrottlingTimeLeft(array $headers): int {
|
||||
$rateLimitForUserApi = $headers["x-ratelimit-user-api"] ?? null;
|
||||
$rateLimitForUser = $headers["x-ratelimit-user"] ?? null;
|
||||
|
||||
$timeLeftForUserApi = self::getTimeLeft($rateLimitForUserApi);
|
||||
$timeLeftForUser = self::getTimeLeft($rateLimitForUser);
|
||||
|
||||
return max($timeLeftForUserApi, $timeLeftForUser);
|
||||
}
|
||||
|
||||
|
||||
private static function getTimeLeft($rateLimit) {
|
||||
if ($rateLimit) {
|
||||
$pairs = explode(',', $rateLimit);
|
||||
foreach ($pairs as $pair) {
|
||||
$kv = explode(':', $pair);
|
||||
if (count($kv) === 2) {
|
||||
$key = trim($kv[0]);
|
||||
$value = trim($kv[1]);
|
||||
if ($key === 'TimeLeft') {
|
||||
$timeLeftValue = intval($value);
|
||||
if ($timeLeftValue === 0 && $value !== "0") { // 确认不是 "0"
|
||||
return null;
|
||||
}
|
||||
return $timeLeftValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Hash the raw data with signatureAlgorithm
|
||||
*
|
||||
* @param raw - hashing data
|
||||
* @param signatureAlgorithm - the autograph method
|
||||
* @returns hashed bytes
|
||||
* @param int[] $raw
|
||||
* @param string $signatureAlgorithm
|
||||
* @return int[]
|
||||
*/
|
||||
static public function hash($raw, $signatureAlgorithm)
|
||||
{
|
||||
$str = BytesUtil::toString($raw);
|
||||
|
||||
switch ($signatureAlgorithm) {
|
||||
case 'ACS3-HMAC-SHA256':
|
||||
case 'ACS3-RSA-SHA256':
|
||||
$res = hash('sha256', $str, true);
|
||||
return $res;
|
||||
case 'ACS3-HMAC-SM3':
|
||||
$res = self::sm3($str);
|
||||
return hex2bin($res);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Generate a nonce string
|
||||
* @returns the nonce string
|
||||
* @return string
|
||||
*/
|
||||
static public function getNonce()
|
||||
{
|
||||
return md5(uniqid() . uniqid(md5(microtime(true)), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get the string to be signed according to request
|
||||
*
|
||||
* @param request - which contains signed messages
|
||||
* @returns the signed string
|
||||
* @param Request $request
|
||||
* @return string
|
||||
*/
|
||||
static public function getStringToSign($request)
|
||||
{
|
||||
$pathname = $request->pathname ?: '';
|
||||
$query = $request->query ?: [];
|
||||
|
||||
$accept = isset($request->headers['accept']) ? $request->headers['accept'] : '';
|
||||
$contentMD5 = isset($request->headers['content-md5']) ? $request->headers['content-md5'] : '';
|
||||
$contentType = isset($request->headers['content-type']) ? $request->headers['content-type'] : '';
|
||||
$date = isset($request->headers['date']) ? $request->headers['date'] : '';
|
||||
|
||||
$result = $request->method . "\n" .
|
||||
$accept . "\n" .
|
||||
$contentMD5 . "\n" .
|
||||
$contentType . "\n" .
|
||||
$date . "\n";
|
||||
|
||||
$canonicalizedHeaders = self::getCanonicalizedHeaders($request->headers);
|
||||
$canonicalizedResource = self::getCanonicalizedResource($pathname, $query);
|
||||
|
||||
return $result . $canonicalizedHeaders . $canonicalizedResource;
|
||||
}
|
||||
|
||||
private static function getCanonicalizedHeaders($headers, $prefix = 'x-acs-')
|
||||
{
|
||||
ksort($headers);
|
||||
$str = '';
|
||||
foreach ($headers as $k => $v) {
|
||||
if (0 === strpos(strtolower($k), $prefix)) {
|
||||
$str .= $k . ':' . trim(self::filter($v)) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
private static function getCanonicalizedResource($pathname, $query)
|
||||
{
|
||||
if (0 === \count($query)) {
|
||||
return $pathname;
|
||||
}
|
||||
ksort($query);
|
||||
$tmp = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (!empty($v)) {
|
||||
$tmp[] = $k . '=' . $v;
|
||||
} else {
|
||||
$tmp[] = $k;
|
||||
}
|
||||
}
|
||||
|
||||
return $pathname . '?' . implode('&', $tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get signature according to stringToSign, secret
|
||||
*
|
||||
* @param stringToSign - the signed string
|
||||
* @param secret - accesskey secret
|
||||
* @returns the signature
|
||||
* @param string $stringToSign
|
||||
* @param string $secret
|
||||
* @return string
|
||||
*/
|
||||
static public function getROASignature($stringToSign, $secret)
|
||||
{
|
||||
return base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Parse filter into a form string
|
||||
*
|
||||
* @param filter - object
|
||||
* @returns the string
|
||||
* @param mixed[] $filter
|
||||
* @return string
|
||||
*/
|
||||
static public function toForm($filter)
|
||||
{
|
||||
$query = $filter;
|
||||
if (null === $query) {
|
||||
return '';
|
||||
}
|
||||
if ($query instanceof Model) {
|
||||
$query = $query->toMap();
|
||||
}
|
||||
$tmp = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (0 !== strpos($k, '_')) {
|
||||
$tmp[$k] = $v;
|
||||
}
|
||||
}
|
||||
$res = self::flatten($tmp);
|
||||
ksort($res);
|
||||
|
||||
return http_build_query($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get timestamp
|
||||
* @returns the timestamp string
|
||||
* @return string
|
||||
*/
|
||||
static public function getTimestamp()
|
||||
{
|
||||
return gmdate('Y-m-d\\TH:i:s\\Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get UTC string
|
||||
* @returns the UTC string
|
||||
* @return string
|
||||
*/
|
||||
static public function getDateUTCString()
|
||||
{
|
||||
return gmdate('D, d M Y H:i:s T');
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Parse filter into a object which's type is map[string]string
|
||||
*
|
||||
* @param filter - query param
|
||||
* @returns the object
|
||||
* @param mixed[] $filter
|
||||
* @return string[]
|
||||
*/
|
||||
static public function query($filter)
|
||||
{
|
||||
if (null === $filter) {
|
||||
return [];
|
||||
}
|
||||
$dict = $filter;
|
||||
if ($dict instanceof Model) {
|
||||
$dict = $dict->toMap();
|
||||
}
|
||||
$tmp = [];
|
||||
foreach ($dict as $k => $v) {
|
||||
if (0 !== strpos($k, '_')) {
|
||||
$tmp[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return self::flatten($tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get signature according to signedParams, method and secret
|
||||
*
|
||||
* @param signedParams - params which need to be signed
|
||||
* @param method - http method e.g. GET
|
||||
* @param secret - AccessKeySecret
|
||||
* @returns the signature
|
||||
* @param string[] $signedParams
|
||||
* @param string $method
|
||||
* @param string $secret
|
||||
* @return string
|
||||
*/
|
||||
static public function getRPCSignature($signedParams, $method, $secret)
|
||||
{
|
||||
$secret .= '&';
|
||||
$strToSign = self::getRpcStrToSign($method, $signedParams);
|
||||
|
||||
$signMethod = 'HMAC-SHA1';
|
||||
|
||||
return self::encode($signMethod, $strToSign, $secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Parse array into a string with specified style
|
||||
*
|
||||
* @param array - the array
|
||||
* @param prefix - the prefix string
|
||||
* @returns the string
|
||||
* @param mixed $array_
|
||||
* @param string $prefix
|
||||
* @param string $style
|
||||
* @return string
|
||||
*/
|
||||
static public function arrayToStringWithSpecifiedStyle($object, $prefix, $style)
|
||||
{
|
||||
if (null === $object) {
|
||||
return '';
|
||||
}
|
||||
if ('repeatList' === $style) {
|
||||
return self::toForm([$prefix => $object]);
|
||||
}
|
||||
if ('simple' == $style || 'spaceDelimited' == $style || 'pipeDelimited' == $style) {
|
||||
$strs = self::flatten($object);
|
||||
|
||||
switch ($style) {
|
||||
case 'spaceDelimited':
|
||||
return implode(' ', $strs);
|
||||
|
||||
case 'pipeDelimited':
|
||||
return implode('|', $strs);
|
||||
|
||||
default:
|
||||
return implode(',', $strs);
|
||||
}
|
||||
} elseif ('json' === $style) {
|
||||
self::parse($object, $parsed);
|
||||
return json_encode($parsed);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Transform input as map.
|
||||
* @param mixed $input
|
||||
* @return mixed[]
|
||||
*/
|
||||
static public function parseToMap($input)
|
||||
{
|
||||
self::parse($input, $result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Get the authorization
|
||||
*
|
||||
* @param request - request params
|
||||
* @param signatureAlgorithm - the autograph method
|
||||
* @param payload - the hashed request
|
||||
* @param acesskey - the acesskey string
|
||||
* @param accessKeySecret - the accessKeySecret string
|
||||
* @returns authorization string
|
||||
* @param Request $request
|
||||
* @param string $signatureAlgorithm
|
||||
* @param string $payload
|
||||
* @param string $acesskey
|
||||
* @param string $accessKeySecret
|
||||
* @return string
|
||||
*/
|
||||
static public function getAuthorization($request, $signatureAlgorithm, $payload, $accesskey, $accessKeySecret)
|
||||
{
|
||||
$canonicalURI = $request->pathname ? $request->pathname : '/';
|
||||
$query = $request->query ?: [];
|
||||
$method = strtoupper($request->method);
|
||||
$canonicalQueryString = self::getCanonicalQueryString($query);
|
||||
$signHeaders = [];
|
||||
foreach ($request->headers as $k => $v) {
|
||||
$k = strtolower($k);
|
||||
if (0 === strpos($k, 'x-acs-') || 'host' === $k || 'content-type' === $k) {
|
||||
$signHeaders[$k] = $v;
|
||||
}
|
||||
}
|
||||
ksort($signHeaders);
|
||||
$headers = [];
|
||||
foreach ($request->headers as $k => $v) {
|
||||
$k = strtolower($k);
|
||||
if (0 === strpos($k, 'x-acs-') || 'host' === $k || 'content-type' === $k) {
|
||||
$headers[$k] = trim($v);
|
||||
}
|
||||
}
|
||||
$canonicalHeaderString = '';
|
||||
ksort($headers);
|
||||
foreach ($headers as $k => $v) {
|
||||
$canonicalHeaderString .= $k . ':' . trim(self::filter($v)) . "\n";
|
||||
}
|
||||
if (empty($canonicalHeaderString)) {
|
||||
$canonicalHeaderString = "\n";
|
||||
}
|
||||
|
||||
$canonicalRequest = $method . "\n" . $canonicalURI . "\n" . $canonicalQueryString . "\n" .
|
||||
$canonicalHeaderString . "\n" . implode(';', array_keys($signHeaders)) . "\n" . $payload;
|
||||
$strtosign = $signatureAlgorithm . "\n" . bin2hex(self::hash(BytesUtil::from($canonicalRequest), $signatureAlgorithm));
|
||||
|
||||
$signature = self::sign($accessKeySecret, $strtosign, $signatureAlgorithm);
|
||||
$signature = bin2hex($signature);
|
||||
|
||||
return $signatureAlgorithm .
|
||||
' Credential=' . $accesskey .
|
||||
',SignedHeaders=' . implode(';', array_keys($signHeaders)) .
|
||||
',Signature=' . $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userAgent
|
||||
* @return string
|
||||
*/
|
||||
static public function getUserAgent($userAgent)
|
||||
{
|
||||
if (empty(self::$defaultUserAgent)) {
|
||||
self::$defaultUserAgent = sprintf('AlibabaCloud (%s; %s) PHP/%s Core/1.0 TeaDSL/2', PHP_OS, \PHP_SAPI, PHP_VERSION);
|
||||
}
|
||||
if (!empty($userAgent)) {
|
||||
return self::$defaultUserAgent . ' ' . $userAgent;
|
||||
}
|
||||
|
||||
return self::$defaultUserAgent;
|
||||
}
|
||||
|
||||
private static function filter($str)
|
||||
{
|
||||
return str_replace(["\t", "\n", "\r", "\f"], '', $str);
|
||||
}
|
||||
|
||||
public static function sign($secret, $str, $algorithm)
|
||||
{
|
||||
$result = '';
|
||||
switch ($algorithm) {
|
||||
case 'ACS3-HMAC-SHA256':
|
||||
$result = hash_hmac('sha256', $str, $secret, true);
|
||||
break;
|
||||
case 'ACS3-HMAC-SM3':
|
||||
$result = self::hmac_sm3($str, $secret, true);
|
||||
break;
|
||||
case 'ACS3-RSA-SHA256':
|
||||
$privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" . $secret . "\n-----END RSA PRIVATE KEY-----";
|
||||
@openssl_sign($str, $result, $privateKey, OPENSSL_ALGO_SHA256);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function hmac_sm3($data, $key, $raw_output = false)
|
||||
{
|
||||
$pack = 'H' . \strlen(self::sm3('test'));
|
||||
$blocksize = 64;
|
||||
if (\strlen($key) > $blocksize) {
|
||||
$key = pack($pack, self::sm3($key));
|
||||
}
|
||||
$key = str_pad($key, $blocksize, \chr(0x00));
|
||||
$ipad = $key ^ str_repeat(\chr(0x36), $blocksize);
|
||||
$opad = $key ^ str_repeat(\chr(0x5C), $blocksize);
|
||||
$hmac = self::sm3($opad . pack($pack, self::sm3($ipad . $data)));
|
||||
|
||||
return $raw_output ? pack($pack, $hmac) : $hmac;
|
||||
}
|
||||
|
||||
private static function sm3($message)
|
||||
{
|
||||
return (new Sm3())->sign($message);
|
||||
}
|
||||
|
||||
private static function encode($signMethod, $strToSign, $secret)
|
||||
{
|
||||
switch ($signMethod) {
|
||||
case 'HMAC-SHA256':
|
||||
return base64_encode(hash_hmac('sha256', $strToSign, $secret, true));
|
||||
default:
|
||||
return base64_encode(hash_hmac('sha1', $strToSign, $secret, true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $items
|
||||
* @param string $delimiter
|
||||
* @param string $prepend
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function flatten($items = [], $delimiter = '.', $prepend = '')
|
||||
{
|
||||
$flatten = [];
|
||||
|
||||
foreach ($items as $key => $value) {
|
||||
$pos = \is_int($key) ? $key + 1 : $key;
|
||||
|
||||
if ($value instanceof Model) {
|
||||
$value = $value->toMap();
|
||||
} elseif (\is_object($value)) {
|
||||
$value = get_object_vars($value);
|
||||
}
|
||||
|
||||
if (\is_array($value) && !empty($value)) {
|
||||
$flatten = array_merge(
|
||||
$flatten,
|
||||
self::flatten($value, $delimiter, $prepend . $pos . $delimiter)
|
||||
);
|
||||
} else {
|
||||
if (\is_bool($value)) {
|
||||
$value = true === $value ? 'true' : 'false';
|
||||
}
|
||||
$flatten[$prepend . $pos] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $flatten;
|
||||
}
|
||||
|
||||
private static function parse($input, &$output)
|
||||
{
|
||||
if (null === $input || '' === $input) {
|
||||
$output = [];
|
||||
}
|
||||
$recursive = function ($input) use (&$recursive) {
|
||||
if ($input instanceof Model) {
|
||||
$input = $input->toMap();
|
||||
} elseif (\is_object($input)) {
|
||||
$input = get_object_vars($input);
|
||||
}
|
||||
if (!\is_array($input)) {
|
||||
return $input;
|
||||
}
|
||||
$data = [];
|
||||
foreach ($input as $k => $v) {
|
||||
$data[$k] = $recursive($v);
|
||||
}
|
||||
|
||||
return $data;
|
||||
};
|
||||
$output = $recursive($input);
|
||||
if (!\is_array($output)) {
|
||||
$output = [$output];
|
||||
}
|
||||
}
|
||||
|
||||
private static function getRpcStrToSign($method, $query)
|
||||
{
|
||||
ksort($query);
|
||||
|
||||
$params = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (null !== $v) {
|
||||
$k = rawurlencode($k);
|
||||
$v = rawurlencode($v);
|
||||
$params[] = $k . '=' . (string)$v;
|
||||
}
|
||||
}
|
||||
$str = implode('&', $params);
|
||||
|
||||
return $method . '&' . rawurlencode('/') . '&' . rawurlencode($str);
|
||||
}
|
||||
|
||||
private static function getCanonicalQueryString($query)
|
||||
{
|
||||
ksort($query);
|
||||
|
||||
$params = [];
|
||||
foreach ($query as $k => $v) {
|
||||
if (null === $v) {
|
||||
continue;
|
||||
}
|
||||
$str = rawurlencode($k);
|
||||
if ('' !== $v && null !== $v) {
|
||||
$str .= '=' . rawurlencode($v);
|
||||
} else {
|
||||
$str .= '=';
|
||||
}
|
||||
$params[] = $str;
|
||||
}
|
||||
|
||||
return implode('&', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform input as array.
|
||||
*
|
||||
* @param mixed $input
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function toArray($input)
|
||||
{
|
||||
if (\is_array($input)) {
|
||||
foreach ($input as $k => &$v) {
|
||||
$v = self::toArray($v);
|
||||
}
|
||||
} elseif ($input instanceof Model) {
|
||||
$input = $input->toMap();
|
||||
foreach ($input as $k => &$v) {
|
||||
$v = self::toArray($v);
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify the value of map.
|
||||
*
|
||||
* @param array $map
|
||||
*
|
||||
* @return array the new stringified map
|
||||
*/
|
||||
public static function stringifyMapValue($map)
|
||||
{
|
||||
if (null === $map) {
|
||||
return [];
|
||||
}
|
||||
foreach ($map as &$node) {
|
||||
if (is_numeric($node)) {
|
||||
$node = (string) $node;
|
||||
} elseif (null === $node) {
|
||||
$node = '';
|
||||
} elseif (\is_bool($node)) {
|
||||
$node = true === $node ? 'true' : 'false';
|
||||
} elseif (\is_object($node)) {
|
||||
$node = json_decode(json_encode($node), true);
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
$server = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);
|
||||
|
||||
if (!$server) {
|
||||
die("Error: $errstr ($errno)");
|
||||
}
|
||||
|
||||
function send_sse($client, $id, $event, $data, $retry = 3000) {
|
||||
$sseData = "id: $id\n";
|
||||
$sseData .= "event: $event\n";
|
||||
$sseData .= "data: " . json_encode($data) . "\n";
|
||||
$sseData .= "retry: $retry\n\n"; // The retry comment is optional and should follow client's needs
|
||||
|
||||
fwrite($client, $sseData);
|
||||
fflush($client);
|
||||
}
|
||||
|
||||
while ($client = @stream_socket_accept($server)) {
|
||||
// 读取请求
|
||||
$request = fread($client, 1024);
|
||||
list($headers, $body) = explode("\r\n\r\n", $request, 2);
|
||||
// 简单解析请求头
|
||||
$headerLines = explode("\r\n", $headers);
|
||||
$requestLine = array_shift($headerLines);
|
||||
preg_match('/\btimeout:\s*true\b/i', $headers, $timeoutMatch);
|
||||
preg_match('/\b(bodytype):[ ]*([\w\d]+)\b/i', $headers, $bodyTypeMatch);
|
||||
$bodyType = $bodyTypeMatch[2] ?? null;
|
||||
preg_match('/^(GET|POST|PUT|DELETE)\s(\/\S*)\sHTTP\/1.1/', $requestLine, $matches);
|
||||
$method = $matches[1];
|
||||
$path = $matches[2];
|
||||
|
||||
|
||||
$headerAssoc = [];
|
||||
|
||||
foreach ($headerLines as $header) {
|
||||
list($name, $value) = explode(": ", $header, 2);
|
||||
$headerAssoc[strtolower($name)] = $value;
|
||||
}
|
||||
if (substr($path, 0, 4) === '/sse') {
|
||||
$responseHeaders = "HTTP/1.1 200 OK\r\n" .
|
||||
"Content-Type: text/event-stream;charset=UTF-8\r\n" .
|
||||
"Cache-Control: no-cache\r\n" .
|
||||
"Connection: keep-alive\r\n";
|
||||
foreach ($headerAssoc as $name => $value) {
|
||||
$responseHeaders .= $name . ": " . $value . "\r\n";
|
||||
}
|
||||
$responseHeaders .= "\r\n";
|
||||
fwrite($client, $responseHeaders);
|
||||
// 刷新缓冲区,确保头部被立刻发送
|
||||
flush();
|
||||
|
||||
// 模拟发送事件流
|
||||
$count = 0;
|
||||
while ($count < 5) {
|
||||
$data = [
|
||||
"count" => $count
|
||||
];
|
||||
$sseData = "id: sse-test\n";
|
||||
$sseData .= "event: flow\n";
|
||||
$sseData .= "data: " . json_encode($data) . "\n";
|
||||
$sseData .= "retry: 3000\n\n"; // 重试时间可选
|
||||
fwrite($client, $sseData);
|
||||
|
||||
// 再次刷新缓冲区,以确保数据被发送
|
||||
flush();
|
||||
|
||||
// 等待100毫秒
|
||||
usleep(100000);
|
||||
$count++;
|
||||
}
|
||||
fclose($client);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($timeoutMatch) {
|
||||
// 模拟超时
|
||||
sleep(5);
|
||||
$responseHeaders = "HTTP/1.1 500 Internal Server Error\r\n" .
|
||||
"Content-Type: text/plain\r\n" .
|
||||
"Connection: close\r\n\r\n";
|
||||
fwrite($client, $responseHeaders . "Server Timeout");
|
||||
} else {
|
||||
$headerAssoc = [];
|
||||
foreach ($headerLines as $headerLine) {
|
||||
list($key, $value) = explode(': ', $headerLine, 2);
|
||||
$headerAssoc[strtolower($key)] = trim($value);
|
||||
}
|
||||
|
||||
// 获取路径和请求方法
|
||||
preg_match('/^(GET|POST|PUT|DELETE)\s(\/\S*)\sHTTP\/1.1/', $requestLine, $matches);
|
||||
$method = $matches[1];
|
||||
$path = $matches[2];
|
||||
|
||||
// 构建响应头
|
||||
$responseHeaders = "HTTP/1.1 200 OK\r\n" .
|
||||
"Connection: close\r\n" .
|
||||
"Content-Type: application/json\r\n" .
|
||||
"x-acs-request-id: A45EE076-334D-5012-9746-A8F828D20FD4\r\n" .
|
||||
"http-method: $method\r\n" .
|
||||
"pathname: $path\r\n" .
|
||||
"raw-body: $body\r\n";
|
||||
|
||||
// 构建响应体
|
||||
$responseBody = "";
|
||||
|
||||
echo $bodyType."\n";
|
||||
|
||||
switch ($bodyType) {
|
||||
case 'array':
|
||||
$responseBody = json_encode(["AppId", "ClassId", "UserId"]);
|
||||
break;
|
||||
case 'error':
|
||||
$responseHeaders = "HTTP/1.1 400 Bad Request\r\n" .
|
||||
"Connection: close\r\n" .
|
||||
"Content-Type: application/json\r\n" .
|
||||
"x-acs-request-id: A45EE076-334D-5012-9746-A8F828D20FD4\r\n" .
|
||||
"http-method: $method\r\n" .
|
||||
"pathname: $path\r\n";
|
||||
$responseBody = json_encode([
|
||||
"Code" => "error code",
|
||||
"Message" => "error message",
|
||||
"RequestId" => "A45EE076-334D-5012-9746-A8F828D20FD4",
|
||||
"Description" => "error description",
|
||||
"AccessDeniedDetail" => new stdClass()
|
||||
]);
|
||||
break;
|
||||
case 'error1':
|
||||
$responseHeaders = "HTTP/1.1 400 Bad Request\r\n" .
|
||||
"Connection: close\r\n" .
|
||||
"Content-Type: application/json\r\n" .
|
||||
"x-acs-request-id: A45EE076-334D-5012-9746-A8F828D20FD4\r\n" .
|
||||
"http-method: $method\r\n" .
|
||||
"pathname: $path\r\n";
|
||||
$responseBody = json_encode([
|
||||
"Code" => "error code",
|
||||
"Message" => "error message",
|
||||
"RequestId" => "A45EE076-334D-5012-9746-A8F828D20FD4",
|
||||
"Description" => "error description",
|
||||
"AccessDeniedDetail" => new stdClass(),
|
||||
"accessDeniedDetail" => ["test" => 0]
|
||||
]);
|
||||
break;
|
||||
case 'error2':
|
||||
$responseHeaders = "HTTP/1.1 400 Bad Request\r\n" .
|
||||
"Connection: close\r\n" .
|
||||
"Content-Type: application/json\r\n" .
|
||||
"x-acs-request-id: A45EE076-334D-5012-9746-A8F828D20FD4\r\n" .
|
||||
"http-method: $method\r\n" .
|
||||
"pathname: $path\r\n";
|
||||
$responseBody = json_encode([
|
||||
"Code" => "error code",
|
||||
"Message" => "error message",
|
||||
"RequestId" => "A45EE076-334D-5012-9746-A8F828D20FD4",
|
||||
"Description" => "error description",
|
||||
"accessDeniedDetail" => ["test" => 0]
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
$responseBody = json_encode([
|
||||
"AppId" => "test",
|
||||
"ClassId" => "test",
|
||||
"UserId" => 123
|
||||
]);
|
||||
}
|
||||
|
||||
fwrite($client, $responseHeaders . "\r\n" . $responseBody);
|
||||
}
|
||||
fclose($client);
|
||||
continue;
|
||||
}
|
||||
|
||||
fclose($server);
|
||||
@@ -0,0 +1,419 @@
|
||||
<?php
|
||||
|
||||
namespace Darabonba\OpenApi\Tests;
|
||||
|
||||
use Darabonba\OpenApi\OpenApiClient;
|
||||
use Darabonba\OpenApi\Utils;
|
||||
|
||||
use Darabonba\OpenApi\Models\Config;
|
||||
use Darabonba\OpenApi\Models\Params;
|
||||
use Darabonba\OpenApi\Models\GlobalParameters;
|
||||
use AlibabaCloud\Dara\Models\RuntimeOptions;
|
||||
use AlibabaCloud\Dara\Models\ExtendsParameters;
|
||||
use Darabonba\OpenApi\Models\OpenApiRequest;
|
||||
use AlibabaCloud\Credentials\Credential;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class OpenApiClientTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $pid = 0;
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
// $server = dirname(__DIR__). \DIRECTORY_SEPARATOR . 'tests' . \DIRECTORY_SEPARATOR . 'Mock' . \DIRECTORY_SEPARATOR . 'MockServer.php';
|
||||
// $command = "php $server > /dev/null 2>&1 & echo $!";
|
||||
// // $command = "php -S localhost:8000 $server";
|
||||
// $output = shell_exec($command);
|
||||
// $this->pid = (int)trim($output);
|
||||
// sleep(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @after
|
||||
*/
|
||||
protected function cleanup()
|
||||
{
|
||||
// shell_exec('kill '.$this->pid);
|
||||
}
|
||||
|
||||
public function testConfig(){
|
||||
$globalParameters = new GlobalParameters([
|
||||
"headers" => [
|
||||
"global-key" => "global-value"
|
||||
],
|
||||
"queries" => [
|
||||
"global-query" => "global-value"
|
||||
]
|
||||
]);
|
||||
$config = new Config([
|
||||
"endpoint" => "config.endpoint",
|
||||
"endpointType" => "regional",
|
||||
"network" => "config.network",
|
||||
"suffix" => "config.suffix",
|
||||
"protocol" => "config.protocol",
|
||||
"method" => "config.method",
|
||||
"regionId" => "config.regionId",
|
||||
"userAgent" => "config.userAgent",
|
||||
"readTimeout" => 3000,
|
||||
"connectTimeout" => 3000,
|
||||
"httpProxy" => "config.httpProxy",
|
||||
"httpsProxy" => "config.httpsProxy",
|
||||
"noProxy" => "config.noProxy",
|
||||
"socks5Proxy" => "config.socks5Proxy",
|
||||
"socks5NetWork" => "config.socks5NetWork",
|
||||
"maxIdleConns" => 128,
|
||||
"signatureVersion" => "config.signatureVersion",
|
||||
"signatureAlgorithm" => "config.signatureAlgorithm",
|
||||
"globalParameters" => $globalParameters
|
||||
]);
|
||||
$creConfig = new \AlibabaCloud\Credentials\Credential\Config([
|
||||
"accessKeyId" => "accessKeyId",
|
||||
"accessKeySecret" => "accessKeySecret",
|
||||
"securityToken" => "securityToken",
|
||||
"type" => "sts"
|
||||
]);
|
||||
$credential = new Credential($creConfig);
|
||||
$config->credential = $credential;
|
||||
$client = new OpenApiClient($config);
|
||||
$config->accessKeyId = "ak";
|
||||
$config->accessKeySecret = "secret";
|
||||
$config->securityToken = "token";
|
||||
$config->type = "sts";
|
||||
$client = new OpenApiClient($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public static function createConfig(){
|
||||
$globalParameters = new GlobalParameters([
|
||||
"headers" => [
|
||||
"global-key" => "global-value"
|
||||
],
|
||||
"queries" => [
|
||||
"global-query" => "global-value"
|
||||
]
|
||||
]);
|
||||
$config = new Config([
|
||||
"accessKeyId" => "ak",
|
||||
"accessKeySecret" => "secret",
|
||||
"securityToken" => "token",
|
||||
"type" => "sts",
|
||||
"userAgent" => "config.userAgent",
|
||||
"readTimeout" => 3000,
|
||||
"connectTimeout" => 3000,
|
||||
"maxIdleConns" => 128,
|
||||
"signatureVersion" => "config.signatureVersion",
|
||||
"signatureAlgorithm" => "ACS3-HMAC-SHA256",
|
||||
"globalParameters" => $globalParameters
|
||||
]);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RuntimeOptions
|
||||
*/
|
||||
public static function createRuntimeOptions(){
|
||||
$runtime = new RuntimeOptions([
|
||||
"readTimeout" => 4000,
|
||||
"connectTimeout" => 4000,
|
||||
"maxIdleConns" => 100,
|
||||
"autoretry" => true,
|
||||
"maxAttempts" => 1,
|
||||
"backoffPolicy" => "no",
|
||||
"backoffPeriod" => 1,
|
||||
"ignoreSSL" => true,
|
||||
"extendsParameters" => new ExtendsParameters([
|
||||
"headers" => [
|
||||
"extends-key" => "extends-value"
|
||||
],
|
||||
])
|
||||
]);
|
||||
return $runtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OpenApiRequest
|
||||
*/
|
||||
public static function createOpenApiRequest(){
|
||||
$query = [];
|
||||
$query["key1"] = "value";
|
||||
$query["key2"] = 1;
|
||||
$query["key3"] = true;
|
||||
$body = [];
|
||||
$body["key1"] = "value";
|
||||
$body["key2"] = 1;
|
||||
$body["key3"] = true;
|
||||
$headers = [
|
||||
"for-test" => "sdk"
|
||||
];
|
||||
$req = new OpenApiRequest([
|
||||
"headers" => $headers,
|
||||
"query" => Utils::query($query),
|
||||
"body" => Utils::parseToMap($body)
|
||||
]);
|
||||
return $req;
|
||||
}
|
||||
|
||||
public function testCallApiForRPCWithV2Sign_AK_Form(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->signatureAlgorithm = "v2";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/",
|
||||
"method" => "POST",
|
||||
"authType" => "AK",
|
||||
"style" => "RPC",
|
||||
"reqBodyType" => "formData",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallApiForRPCWithV2Sign_Anonymous_JSON(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->signatureAlgorithm = "v2";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/",
|
||||
"method" => "POST",
|
||||
"authType" => "Anonymous",
|
||||
"style" => "RPC",
|
||||
"reqBodyType" => "json",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallApiForROAWithV2Sign_HTTPS_AK_Form(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->signatureAlgorithm = "v2";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/test",
|
||||
"method" => "POST",
|
||||
"authType" => "AK",
|
||||
"style" => "ROA",
|
||||
"reqBodyType" => "formData",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallApiForROAWithV2Sign_Anonymous_JSON(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->signatureAlgorithm = "v2";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/test",
|
||||
"method" => "POST",
|
||||
"authType" => "Anonymous",
|
||||
"style" => "ROA",
|
||||
"reqBodyType" => "json",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallApiForRPCWithV3Sign_AK_Form(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/",
|
||||
"method" => "POST",
|
||||
"authType" => "AK",
|
||||
"style" => "RPC",
|
||||
"reqBodyType" => "formData",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallApiForRPCWithV3Sign_Anonymous_JSON(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/",
|
||||
"method" => "POST",
|
||||
"authType" => "Anonymous",
|
||||
"style" => "RPC",
|
||||
"reqBodyType" => "json",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallApiForROAWithV3Sign_AK_Form(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/test",
|
||||
"method" => "POST",
|
||||
"authType" => "AK",
|
||||
"style" => "ROA",
|
||||
"reqBodyType" => "formData",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallApiForROAWithV3Sign_Anonymous_JSON(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/test",
|
||||
"method" => "POST",
|
||||
"authType" => "Anonymous",
|
||||
"style" => "ROA",
|
||||
"reqBodyType" => "json",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testResponseBodyType(){
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->endpoint = "test.aliyuncs.com";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/test",
|
||||
"method" => "POST",
|
||||
"authType" => "AK",
|
||||
"style" => "ROA",
|
||||
"reqBodyType" => "formData",
|
||||
"bodyType" => "json"
|
||||
]);
|
||||
$client->callApi($params, $request, $runtime);
|
||||
$params->bodyType = "array";
|
||||
$client->callApi($params, $request, $runtime);
|
||||
$params->bodyType = "string";
|
||||
$client->callApi($params, $request, $runtime);
|
||||
$params->bodyType = "byte";
|
||||
$client->callApi($params, $request, $runtime);
|
||||
}
|
||||
|
||||
public function testCallSSEApiWithSignV3()
|
||||
{
|
||||
$config = self::createConfig();
|
||||
$runtime = self::createRuntimeOptions();
|
||||
$config->protocol = "HTTP";
|
||||
$config->endpoint = "127.0.0.1:8000";
|
||||
$client = new OpenApiClient($config);
|
||||
$request = self::createOpenApiRequest();
|
||||
$params = new Params([
|
||||
"action" => "TestAPI",
|
||||
"version" => "2022-06-01",
|
||||
"protocol" => "HTTPS",
|
||||
"pathname" => "/sse",
|
||||
"method" => "POST",
|
||||
"authType" => "AK",
|
||||
"style" => "ROA",
|
||||
"reqBodyType" => "json",
|
||||
"bodyType" => "sse"
|
||||
]);
|
||||
$response = $client->callSSEApi($params, $request, $runtime);
|
||||
|
||||
|
||||
// Add more assertions as needed
|
||||
$events = [];
|
||||
|
||||
// SSE events are typically separated by double newline
|
||||
foreach ($response as $event) {
|
||||
$this->assertEquals(200, $event->statusCode);
|
||||
$headers = $event->headers;
|
||||
$this->assertEquals('text/event-stream;charset=UTF-8', $headers['Content-Type'][0]);
|
||||
$this->assertEquals('sdk', $headers['for-test'][0]);
|
||||
$userAgentArray = explode(' ', $headers['user-agent'][0]);
|
||||
$this->assertEquals('config.userAgent', end($userAgentArray));
|
||||
$this->assertEquals('global-value', $headers['global-key'][0]);
|
||||
$this->assertEquals('extends-value', $headers['extends-key'][0]);
|
||||
$this->assertNotEmpty($headers['x-acs-signature-nonce'][0]);
|
||||
$this->assertNotEmpty($headers['x-acs-date'][0]);
|
||||
$this->assertEquals('application/json', $headers['accept'][0]);
|
||||
$event = $event->event->toArray();
|
||||
// var_dump($event);
|
||||
$events[] = json_decode($event['data'], true);
|
||||
}
|
||||
$expectedEvents = [
|
||||
['count' => 0],
|
||||
['count' => 1],
|
||||
['count' => 2],
|
||||
['count' => 3],
|
||||
['count' => 4],
|
||||
];
|
||||
$this->assertCount(5, $events);
|
||||
$this->assertEquals($expectedEvents, $events);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
Reference in New Issue
Block a user