代码同步

This commit is contained in:
Ghost
2025-03-24 14:59:19 +08:00
parent f0fa19f89f
commit bd2e1e5386
716 changed files with 90318 additions and 26155 deletions

View File

@@ -11,9 +11,9 @@
],
"require": {
"php": ">5.5",
"alibabacloud/tea-utils": "^0.2.0",
"alibabacloud/tea-utils": "^0.2.21",
"alibabacloud/credentials": "^1.1",
"alibabacloud/openapi-util": "^0.1.10",
"alibabacloud/openapi-util": "^0.1.10|^0.2.1",
"alibabacloud/gateway-spi": "^1",
"alibabacloud/tea-xml": "^0.2"
},

View 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>

View File

@@ -1,14 +1,15 @@
<?php
// This file is auto-generated, don't edit it. Thanks.
namespace Darabonba\OpenApi\Models;
use AlibabaCloud\Credentials\Credential;
use AlibabaCloud\Tea\Model;
use AlibabaCloud\Credentials\Credential;
use Darabonba\OpenApi\Models\GlobalParameters;
/**
* Model for initing client.
* Model for initing client
*/
class Config extends Model
{
@@ -16,6 +17,7 @@ class Config extends Model
'accessKeyId' => '',
'accessKeySecret' => '',
'securityToken' => '',
'bearerToken' => '',
'protocol' => 'http',
'method' => '',
'regionId' => '',
@@ -37,12 +39,13 @@ class Config extends Model
'type' => '',
'signatureVersion' => '',
'signatureAlgorithm' => '',
'key' => '',
'cert' => '',
'ca' => '',
];
public function validate()
{
}
public function toMap()
{
$res = [];
@@ -55,6 +58,9 @@ class Config extends Model
if (null !== $this->securityToken) {
$res['securityToken'] = $this->securityToken;
}
if (null !== $this->bearerToken) {
$res['bearerToken'] = $this->bearerToken;
}
if (null !== $this->protocol) {
$res['protocol'] = $this->protocol;
}
@@ -121,13 +127,22 @@ class Config extends Model
if (null !== $this->globalParameters) {
$res['globalParameters'] = null !== $this->globalParameters ? $this->globalParameters->toMap() : null;
}
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;
}
return $res;
}
/**
* @param array $map
*
* @return Config
*/
public static function fromMap($map = [])
@@ -142,6 +157,9 @@ class Config extends Model
if (isset($map['securityToken'])) {
$model->securityToken = $map['securityToken'];
}
if (isset($map['bearerToken'])) {
$model->bearerToken = $map['bearerToken'];
}
if (isset($map['protocol'])) {
$model->protocol = $map['protocol'];
}
@@ -208,226 +226,225 @@ class Config extends Model
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'];
}
return $model;
}
/**
* @description accesskey id
*
* @var string
*/
public $accessKeyId;
/**
* @description accesskey secret
*
* @var string
*/
public $accessKeySecret;
/**
* @description security token
*
* @example a.txt
*
* @var string
*/
public $securityToken;
/**
* @description bearer token
* @example the-bearer-token
* @var string
*/
public $bearerToken;
/**
* @description http protocol
*
* @example http
*
* @var string
*/
public $protocol;
/**
* @description http method
*
* @example GET
*
* @var string
*/
public $method;
/**
* @description region id
*
* @example cn-hangzhou
*
* @var string
*/
public $regionId;
/**
* @description read timeout
*
* @example 10
*
* @var int
*/
public $readTimeout;
/**
* @description connect timeout
*
* @example 10
*
* @var int
*/
public $connectTimeout;
/**
* @description http proxy
*
* @example http://localhost
*
* @var string
*/
public $httpProxy;
/**
* @description https proxy
*
* @example https://localhost
*
* @var string
*/
public $httpsProxy;
/**
* @description credential
*
* @example
*
* @example
* @var Credential
*/
public $credential;
/**
* @description endpoint
*
* @example cs.aliyuncs.com
*
* @var string
*/
public $endpoint;
/**
* @description proxy white list
*
* @example http://localhost
*
* @var string
*/
public $noProxy;
/**
* @description max idle conns
*
* @example 3
*
* @var int
*/
public $maxIdleConns;
/**
* @description network for endpoint
*
* @example public
*
* @var string
*/
public $network;
/**
* @description user agent
*
* @example Alibabacloud/1
*
* @var string
*/
public $userAgent;
/**
* @description suffix for endpoint
*
* @example aliyun
*
* @var string
*/
public $suffix;
/**
* @description socks5 proxy
*
* @var string
*/
public $socks5Proxy;
/**
* @description socks5 network
*
* @example TCP
*
* @var string
*/
public $socks5NetWork;
/**
* @description endpoint type
*
* @example internal
*
* @var string
*/
public $endpointType;
/**
* @description OpenPlatform endpoint
*
* @example openplatform.aliyuncs.com
*
* @var string
*/
public $openPlatformEndpoint;
/**
* @description credential type
*
* @example access_key
*
* @deprecated
*
* @var string
*/
public $type;
/**
* @description Signature Version
*
* @example v1
*
* @var string
*/
public $signatureVersion;
/**
* @description Signature Algorithm
*
* @example ACS3-HMAC-SHA256
*
* @var string
*/
public $signatureAlgorithm;
/**
* @description Global Parameters
*
* @var GlobalParameters
*/
public $globalParameters;
/**
* @description privite key for client certificate
* @example MIIEvQ
* @var string
*/
public $key;
/**
* @description client certificate
* @example -----BEGIN CERTIFICATE-----xxx-----END CERTIFICATE-----
* @var string
*/
public $cert;
/**
* @description server certificate
* @example -----BEGIN CERTIFICATE-----xxx-----END CERTIFICATE-----
* @var string
*/
public $ca;
/**
* @description disable HTTP/2
* @example false
* @var bool
*/
public $disableHttp2;
}

View File

@@ -1,7 +1,6 @@
<?php
// This file is auto-generated, don't edit it. Thanks.
namespace Darabonba\OpenApi\Models;
use AlibabaCloud\Tea\Model;
@@ -11,7 +10,6 @@ class GlobalParameters extends Model
public function validate()
{
}
public function toMap()
{
$res = [];
@@ -21,13 +19,10 @@ class GlobalParameters extends Model
if (null !== $this->queries) {
$res['queries'] = $this->queries;
}
return $res;
}
/**
* @param array $map
*
* @return GlobalParameters
*/
public static function fromMap($map = [])
@@ -39,11 +34,10 @@ class GlobalParameters extends Model
if (isset($map['queries'])) {
$model->queries = $map['queries'];
}
return $model;
}
public $headers;
public $queries;
}

View File

@@ -1,7 +1,6 @@
<?php
// This file is auto-generated, don't edit it. Thanks.
namespace Darabonba\OpenApi\Models;
use AlibabaCloud\Tea\Model;
@@ -11,7 +10,6 @@ class OpenApiRequest extends Model
public function validate()
{
}
public function toMap()
{
$res = [];
@@ -33,13 +31,10 @@ class OpenApiRequest extends Model
if (null !== $this->endpointOverride) {
$res['endpointOverride'] = $this->endpointOverride;
}
return $res;
}
/**
* @param array $map
*
* @return OpenApiRequest
*/
public static function fromMap($map = [])
@@ -63,10 +58,8 @@ class OpenApiRequest extends Model
if (isset($map['endpointOverride'])) {
$model->endpointOverride = $map['endpointOverride'];
}
return $model;
}
public $headers;
public $query;
@@ -78,4 +71,5 @@ class OpenApiRequest extends Model
public $hostMap;
public $endpointOverride;
}

View File

@@ -1,7 +1,6 @@
<?php
// This file is auto-generated, don't edit it. Thanks.
namespace Darabonba\OpenApi\Models;
use AlibabaCloud\Tea\Model;
@@ -19,7 +18,6 @@ class Params extends Model
Model::validateRequired('bodyType', $this->bodyType, true);
Model::validateRequired('reqBodyType', $this->reqBodyType, true);
}
public function toMap()
{
$res = [];
@@ -50,13 +48,10 @@ class Params extends Model
if (null !== $this->style) {
$res['style'] = $this->style;
}
return $res;
}
/**
* @param array $map
*
* @return Params
*/
public static function fromMap($map = [])
@@ -89,10 +84,8 @@ class Params extends Model
if (isset($map['style'])) {
$model->style = $map['style'];
}
return $model;
}
/**
* @var string
*/
@@ -134,4 +127,5 @@ class Params extends Model
public $reqBodyType;
public $style;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,328 @@
<?php
namespace Darabonba\OpenApi\Tests;
use Darabonba\OpenApi\OpenApiClient;
use AlibabaCloud\Tea\Model;
use AlibabaCloud\Tea\Request;
use AlibabaCloud\Tea\Utils\Utils;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class OpenApiClientTest extends TestCase
{
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
]);
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" => OpenApiUtilClient::query($query),
"body" => OpenApiUtilClient::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);
}
}

View File

@@ -0,0 +1,3 @@
<?php
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';