初始化项目:添加后端代码、ThinkPHP框架、前端资源

This commit is contained in:
amb
2026-09-03 12:42:39 +08:00
commit 482bece22e
3726 changed files with 416708 additions and 0 deletions
@@ -0,0 +1,36 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class CredentialTest extends PHPUnit_Framework_TestCase
{
public function testCredential()
{
$credential = new Credential("accessKeyId", "accessSecret");
$this->assertEquals("accessKeyId", $credential->getAccessKeyId());
$this->assertEquals("accessSecret", $credential->getAccessSecret());
$this->assertNotNull($credential->getRefreshDate());
$dateNow = date("Y-m-d\TH:i:s\Z");
$credential->setExpiredDate(1);
$this->assertNotNull($credential->getExpiredDate());
$this->assertTrue($credential->getExpiredDate() > $dateNow);
}
}
@@ -0,0 +1,30 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class ShaHmac1SignerTest extends PHPUnit_Framework_TestCase
{
public function testShaHmac1Signer()
{
$signer = new ShaHmac1Signer();
$this->assertEquals("33nmIV5/p6kG/64eLXNljJ5vw84=",
$signer->signString("this is a ShaHmac1 test.", "accessSecret"));
}
}
@@ -0,0 +1,30 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class ShaHmac256SignerTest extends PHPUnit_Framework_TestCase
{
public function testShaHmac256Signer()
{
$signer = new ShaHmac256Signer();
$this->assertEquals("TpF1lE/avV9EHGWGg9Vo/QTd2bLRwFCk9jjo56uRbCo=",
$signer->signString("this is a ShaHmac256 test.", "accessSecret"));
}
}
@@ -0,0 +1,49 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class BaseTest extends PHPUnit_Framework_TestCase
{
/**
* @var null
*/
public $client = null;
public function setUp()
{
$path = substr(__DIR__, 0, strripos(__DIR__, DIRECTORY_SEPARATOR)) . DIRECTORY_SEPARATOR;
include_once $path . 'Config.php';
include_once 'Ecs/Rquest/DescribeRegionsRequest.php';
include_once 'BatchCompute/ListImagesRequest.php';
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "AccessKey", "AccessSecret");
$this->client = new DefaultAcsClient($iClientProfile);
}
/**
* @param $propertyKey
*/
public function getProperty($propertyKey)
{
$accessKey = "";
$accessSecret = "";
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "AccessKey", "AccessSecret");
}
}
@@ -0,0 +1,31 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace UnitTest\BatchCompute\Request;
class ListImagesRequest extends \RoaAcsRequest
{
public function __construct()
{
parent::__construct("BatchCompute", "2013-01-11", "ListImages");
$this->setUriPattern("/images");
$this->setMethod("GET");
}
}
@@ -0,0 +1,43 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once 'BaseTest.php';
use UnitTest\BatchCompute\Request as BC;
use UnitTest\Ecs\Request as Ecs;
class DefaultAcsClientTest extends BaseTest
{
public function testDoActionRPC()
{
$request = new Ecs\DescribeRegionsRequest();
$response = $this->client->doAction($request);
$this->assertNotNull($response->RequestId);
$this->assertNotNull($response->Regions->Region[0]->LocalName);
$this->assertNotNull($response->Regions->Region[0]->RegionId);
}
public function testDoActionROA()
{
$request = new BC\ListImagesRequest();
$response = $this->client->doAction($request);
$this->assertNotNull($response);
}
}
@@ -0,0 +1,117 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace UnitTest\Ecs\Request;
class DescribeRegionsRequest extends \RpcAcsRequest
{
public function __construct()
{
parent::__construct("Ecs", "2014-05-26", "DescribeRegions");
}
/**
* @var
*/
private $ownerId;
/**
* @var
*/
private $resourceOwnerAccount;
/**
* @var
*/
private $resourceOwnerId;
/**
* @var
*/
private $ownerAccount;
/**
* @return mixed
*/
public function getOwnerId()
{
return $this->ownerId;
}
/**
* @param $ownerId
*/
public function setOwnerId($ownerId)
{
$this->ownerId = $ownerId;
$this->queryParameters["OwnerId"] = $ownerId;
}
/**
* @return mixed
*/
public function getResourceOwnerAccount()
{
return $this->resourceOwnerAccount;
}
/**
* @param $resourceOwnerAccount
*/
public function setResourceOwnerAccount($resourceOwnerAccount)
{
$this->resourceOwnerAccount = $resourceOwnerAccount;
$this->queryParameters["ResourceOwnerAccount"] = $resourceOwnerAccount;
}
/**
* @return mixed
*/
public function getResourceOwnerId()
{
return $this->resourceOwnerId;
}
/**
* @param $resourceOwnerId
*/
public function setResourceOwnerId($resourceOwnerId)
{
$this->resourceOwnerId = $resourceOwnerId;
$this->queryParameters["ResourceOwnerId"] = $resourceOwnerId;
}
/**
* @return mixed
*/
public function getOwnerAccount()
{
return $this->ownerAccount;
}
/**
* @param $ownerAccount
*/
public function setOwnerAccount($ownerAccount)
{
$this->ownerAccount = $ownerAccount;
$this->queryParameters["OwnerAccount"] = $ownerAccount;
}
}
@@ -0,0 +1,107 @@
<?php
require_once '../../Config.php';
use UnitTest\Ft\TestRoaApiRequest;
use UnitTest\Ft\TestRpcApiRequest;
$clientProfile = DefaultProfile::getProfile(
"cn-hangzhou",
"<your Ak>",
"<your Secret>",
"<your StsToken>"
);
DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", "Ft", "ft.aliyuncs.com");
print_r("1.开始测试普通AK访问: ");
echo "\n";
$client = new DefaultAcsClient($clientProfile);
# 创建 API 请求并设置参数
$request = new TestRpcApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $client->getAcsResponse($request);
print_r($response);
# 创建 API 请求并设置参数
$request = new TestRoaApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $client->getAcsResponse($request);
print_r($response);
//RoleArn
echo "\n";
print_r("2.开始测试RoleArn: ");
echo "\n";
$ramRoleArnProfile = DefaultProfile::getRamRoleArnProfile(
"cn-hangzhou",
"<your Ak>",
"<your Secret>",
"<your RoleArn>",
"<your RoleSessionName>"
);
$roleArnClient = new DefaultAcsClient($ramRoleArnProfile);
# 创建 API 请求并设置参数
$request = new TestRpcApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $roleArnClient->getAcsResponse($request);
print_r($response);
# 创建 API 请求并设置参数
$request = new TestRoaApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $roleArnClient->getAcsResponse($request);
print_r($response);
echo "\n";
print_r("3.开始测试EcsArn: ");
echo "\n";
$ecsRamRoleProfile = DefaultProfile::getEcsRamRoleProfile(
"cn-hangzhou",
"<your EcsRoleName>"
);
$ecsRamRoleClient = new DefaultAcsClient($ecsRamRoleProfile);
# 创建 API 请求并设置参数
$request = new TestRpcApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $ecsRamRoleClient->getAcsResponse($request);
print_r($response);
# 创建 API 请求并设置参数
$request = new TestRoaApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $ecsRamRoleClient->getAcsResponse($request);
print_r($response);
echo "\n";
print_r("4.开始测试BearerToken: ");
echo "\n";
$bearerTokenProfile = DefaultProfile::getBearerTokenProfile(
"cn-hangzhou",
"<Your Bearer Token>"
);
$bearerTokenClient = new DefaultAcsClient($bearerTokenProfile);
# 创建 API 请求并设置参数
$request = new TestRpcApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $bearerTokenClient->getAcsResponse($request);
print_r($response);
# 创建 API 请求并设置参数
$request = new TestRoaApiRequest();
$request->setQueryParam("test");
# 发起请求并处理返回
$response = $bearerTokenClient->getAcsResponse($request);
print_r($response);
@@ -0,0 +1,85 @@
<?php
/**
* Created by PhpStorm.
* User: zhangw
* Date: 2017/12/19
* Time: 下午6:39
*/
namespace UnitTest\Ft;
class TestRoaApiRequest extends \RoaAcsRequest
{
public function __construct()
{
parent::__construct("Ft", "2016-01-02", "TestRoaApi");
$this->setUriPattern("/web/cloudapi");
$this->setMethod("GET");
}
/**
* @var
*/
private $queryParam;
/**
* @var
*/
private $bodyParam;
/**
* @var
*/
private $headerParam;
/**
* @return mixed
*/
public function getQueryParam()
{
return $this->queryParam;
}
/**
* @param $queryParam
*/
public function setQueryParam($queryParam)
{
$this->queryParam = $queryParam;
$this->queryParameters["QueryParam"] = $queryParam;
}
/**
* @return mixed
*/
public function getBodyParam()
{
return $this->bodyParam;
}
/**
* @param $bodyParam
*/
public function setBodyParam($bodyParam)
{
$this->bodyParam = $bodyParam;
$this->queryParameters["BodyParam"] = $bodyParam;
}
/**
* @return mixed
*/
public function getHeaderParam()
{
return $this->headerParam;
}
/**
* @param $headerParam
*/
public function setHeaderParam($headerParam)
{
$this->headerParam = $headerParam;
$this->headerParam["HeaderParam"] = $headerParam;
}
}
@@ -0,0 +1,61 @@
<?php
/**
* Created by PhpStorm.
* User: zhangw
* Date: 2017/12/19
* Time: 下午6:39
*/
namespace UnitTest\Ft;
class TestRpcApiRequest extends \RpcAcsRequest
{
public function __construct()
{
parent::__construct("Ft", "2016-01-01", "TestRpcApi");
}
/**
* @var
*/
private $queryParam;
/**
* @var
*/
private $bodyParam;
/**
* @return mixed
*/
public function getQueryParam()
{
return $this->queryParam;
}
/**
* @param $queryParam
*/
public function setQueryParam($queryParam)
{
$this->queryParam = $queryParam;
$this->queryParameters["QueryParam"] = $queryParam;
}
/**
* @return mixed
*/
public function getBodyParam()
{
return $this->bodyParam;
}
/**
* @param $bodyParam
*/
public function setBodyParam($bodyParam)
{
$this->bodyParam = $bodyParam;
$this->queryParameters["BodyParam"] = $bodyParam;
}
}
@@ -0,0 +1,30 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../BaseTest.php';
class HttpHelperTest extends BaseTest
{
public function testCurl()
{
$httpResponse = HttpHelper::curl("ecs.aliyuncs.com");
$this->assertEquals(400, $httpResponse->getStatus());
$this->assertNotNull($httpResponse->getBody());
}
}
@@ -0,0 +1,66 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class DefaultProfileTest extends PHPUnit_Framework_TestCase
{
public function testGetProfile()
{
$profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
$this->assertEquals("cn-hangzhou", $profile->getRegionId());
$this->assertEquals("accessId", $profile->getCredential()->getAccessKeyId());
$this->assertEquals("accessSecret", $profile->getCredential()->getAccessSecret());
}
public function testAddEndpoint()
{
$profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
$profile::addEndpoint("cn-hangzhou", "cn-hangzhou", "TestProduct", "testproduct.aliyuncs.com");
$endpoints = $profile::getEndpoints();
foreach ($endpoints as $key => $endpoint) {
if ("cn-hangzhou" == $endpoint->getName()) {
$regionIds = $endpoint->getRegionIds();
$this->assertContains("cn-hangzhou", $regionIds);
$productDomains = $endpoint->getProductDomains();
$this->assertNotNull($productDomains);
$productDomain = $this->getProductDomain($productDomains);
$this->assertNotNull($productDomain);
$this->assertEquals("TestProduct", $productDomain->getProductName());
$this->assertEquals("testproduct.aliyuncs.com", $productDomain->getDomainName());
}
}
}
/**
* @param $productDomains
*
* @return ProductDomain|null
*/
private function getProductDomain($productDomains)
{
foreach ($productDomains as $productDomain) {
if ($productDomain->getProductName() === 'TestProduct') {
return $productDomain;
}
}
return null;
}
}
@@ -0,0 +1,52 @@
<?php
/**
* Created by PhpStorm.
* User: zhangw
* Date: 2017/7/17
* Time: 下午4:57
*/
include_once '../../Config.php';
use PHPUnit\Framework\TestCase;
class EndPointByLocationTest extends TestCase
{
/**
* @var
*/
private $locationService;
/**
* @var
*/
private $clientProfile;
private function initClient()
{
# 创建 DefaultAcsClient 实例并初始化
$this->clientProfile = DefaultProfile::getProfile(
"cn-shanghai", # 您的 Region ID
"<your AK>", # 您的 Access Key ID
"<your Secret>" # 您的 Access Key Secret
);
$this->locationService = new LocationService($this->clientProfile);
}
public function testFindProductDomain()
{
$this->initClient();
$domain = $this->locationService->findProductDomain("cn-shanghai", "apigateway", "openAPI", "CloudAPI");
$this->assertEquals("apigateway.cn-shanghai.aliyuncs.com", $domain);
}
public function testFindProductDomainWithAddEndPoint()
{
DefaultProfile::addEndpoint("cn-shanghai", "cn-shanghai", "CloudAPI", "apigateway.cn-shanghai123.aliyuncs.com");
$this->initClient();
$domain = $this->locationService->findProductDomain("cn-shanghai", "apigateway", "openAPI", "CloudAPI");
$this->assertEquals("apigateway.cn-shanghai123.aliyuncs.com", $domain);
}
}
@@ -0,0 +1,28 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class EndpointProviderTest extends PHPUnit_Framework_TestCase
{
public function testFindProductDomain()
{
$this->assertEquals("ecs.aliyuncs.com", EndpointProvider::findProductDomain("cn-hangzhou", "Ecs"));
}
}