├── .gitignore ├── README.md ├── aliyun-php-sdk-core ├── AcsRequest.php ├── AcsResponse.php ├── Auth │ ├── AbstractCredential.php │ ├── Credential.php │ ├── EcsRamRoleCredential.php │ ├── EcsRamRoleService.php │ ├── ISigner.php │ ├── RamRoleArnCredential.php │ ├── RamRoleArnService.php │ ├── ShaHmac1Signer.php │ └── ShaHmac256Signer.php ├── Autoloader │ └── Autoloader.php ├── ChangeLog.txt ├── Config.php ├── DefaultAcsClient.php ├── Exception │ ├── ClientException.php │ └── ServerException.php ├── Http │ ├── HttpHelper.php │ └── HttpResponse.php ├── IAcsClient.php ├── Profile │ ├── DefaultProfile.php │ └── IClientProfile.php ├── Regions │ ├── Endpoint.php │ ├── EndpointConfig.php │ ├── EndpointProvider.php │ ├── LocationService.php │ ├── ProductDomain.php │ └── endpoints.xml ├── RoaAcsRequest.php ├── RpcAcsRequest.php └── UnitTest │ ├── Auth │ ├── CredentialTest.php │ ├── ShaHmac1SignerTest.php │ └── ShaHmac256SignerTest.php │ ├── BaseTest.php │ ├── BatchCompute │ └── ListImagesRequest.php │ ├── DefaultAcsClientTest.php │ ├── Ecs │ └── Rquest │ │ └── DescribeRegionsRequest.php │ ├── Ft │ ├── InteTest.php │ ├── TestRoaApiRequest.php │ └── TestRpcApiRequest.php │ ├── Http │ └── HttpHelperTest.php │ ├── Profile │ └── DefaultProfileTest.php │ └── Regions │ ├── EndPointByLocationTest.php │ └── EndpointProviderTest.php ├── aliyun-php-sdk-nls-cloud-meta ├── ChangeLog.txt └── nls_cloud_meta │ └── Request │ └── V20180518 │ └── CreateTokenRequest.php ├── aliyun-php-sdk-nls-filetrans ├── ChangeLog.txt └── nls_filetrans │ └── Request │ └── V20180817 │ ├── GetTaskResultRequest.php │ └── SubmitTaskRequest.php └── composer.json /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | .idea/ 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Aliyun-openapi-sdk 2 | 3 | ### 介绍 4 | 5 | 基于 aliyun-openapi-php-sdk 提取部分sdk供项目调用 6 | 7 | ### 引用 8 | 9 | ``` 10 | composer require cmstop/aliyun-openapi-php-sdk:dev-master 11 | ``` 12 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/AcsRequest.php: -------------------------------------------------------------------------------- 1 | headers["x-sdk-client"] = "php/2.0.0"; 40 | $this->product = $product; 41 | $this->version = $version; 42 | $this->actionName = $actionName; 43 | 44 | $this->locationServiceCode = $locationServiceCode; 45 | $this->locationEndpointType = $locationEndpointType; 46 | } 47 | 48 | public abstract function composeUrl($iSigner, $credential, $domain); 49 | 50 | public function getVersion() 51 | { 52 | return $this->version; 53 | } 54 | 55 | public function setVersion($version) 56 | { 57 | $this->version = $version; 58 | } 59 | 60 | public function getProduct() 61 | { 62 | return $this->product; 63 | } 64 | 65 | public function setProduct($product) 66 | { 67 | $this->product = $product; 68 | } 69 | 70 | public function getActionName() 71 | { 72 | return $this->actionName; 73 | } 74 | 75 | public function setActionName($actionName) 76 | { 77 | $this->actionName = $actionName; 78 | } 79 | 80 | public function getAcceptFormat() 81 | { 82 | return $this->acceptFormat; 83 | } 84 | 85 | public function setAcceptFormat($acceptFormat) 86 | { 87 | $this->acceptFormat = $acceptFormat; 88 | } 89 | 90 | public function getQueryParameters() 91 | { 92 | return $this->queryParameters; 93 | } 94 | 95 | public function getHeaders() 96 | { 97 | return $this->headers; 98 | } 99 | 100 | public function getMethod() 101 | { 102 | return $this->method; 103 | } 104 | 105 | public function setMethod($method) 106 | { 107 | $this->method = $method; 108 | } 109 | 110 | public function getProtocol() 111 | { 112 | return $this->protocolType; 113 | } 114 | 115 | public function setProtocol($protocol) 116 | { 117 | $this->protocolType = $protocol; 118 | } 119 | 120 | public function getRegionId() 121 | { 122 | return $this->regionId; 123 | } 124 | public function setRegionId($region) 125 | { 126 | $this->regionId = $region; 127 | } 128 | 129 | public function getContent() 130 | { 131 | return $this->content; 132 | } 133 | 134 | public function setContent($content) 135 | { 136 | $this->content = $content; 137 | } 138 | 139 | 140 | public function addHeader($headerKey, $headerValue) 141 | { 142 | $this->headers[$headerKey] = $headerValue; 143 | } 144 | 145 | public function getLocationServiceCode() 146 | { 147 | return $this->locationServiceCode; 148 | } 149 | 150 | public function getLocationEndpointType() 151 | { 152 | return $this->locationEndpointType; 153 | } 154 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/AcsResponse.php: -------------------------------------------------------------------------------- 1 | code; 28 | } 29 | 30 | public function setCode($code) 31 | { 32 | $this->code = $code; 33 | } 34 | 35 | public function getMessage() 36 | { 37 | return $this->message; 38 | } 39 | 40 | public function setMessage($message) 41 | { 42 | $this->message = $message; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Auth/AbstractCredential.php: -------------------------------------------------------------------------------- 1 | accessKeyId = $accessKeyId; 32 | $this->accessSecret = $accessSecret; 33 | $this->securityToken = $securityToken; 34 | $this->refreshDate = date($this->dateTimeFormat); 35 | } 36 | 37 | public function isExpired() 38 | { 39 | if ($this->expiredDate == null) { 40 | return false; 41 | } 42 | if (strtotime($this->expiredDate)>strtotime(date($this->dateTimeFormat))) { 43 | return false; 44 | } 45 | return true; 46 | } 47 | 48 | public function getRefreshDate() 49 | { 50 | return $this->refreshDate; 51 | } 52 | 53 | public function getExpiredDate() 54 | { 55 | return $this->expiredDate; 56 | } 57 | 58 | public function setExpiredDate($expiredHours) 59 | { 60 | if ($expiredHours>0) { 61 | return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour")); 62 | } 63 | } 64 | 65 | public function getAccessKeyId() 66 | { 67 | return $this->accessKeyId; 68 | } 69 | 70 | public function setAccessKeyId($accessKeyId) 71 | { 72 | $this->accessKeyId = $accessKeyId; 73 | } 74 | 75 | public function getAccessSecret() 76 | { 77 | return $this->accessSecret; 78 | } 79 | 80 | public function setAccessSecret($accessSecret) 81 | { 82 | $this->accessSecret = $accessSecret; 83 | } 84 | 85 | public function getSecurityToken() 86 | { 87 | return $this->securityToken; 88 | } 89 | 90 | public function setSecurityToken($securityToken) 91 | { 92 | $this->securityToken = $securityToken; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Auth/EcsRamRoleCredential.php: -------------------------------------------------------------------------------- 1 | roleName = $roleName; 27 | } 28 | 29 | public function getAccessKeyId() 30 | { 31 | return null; 32 | } 33 | 34 | public function getAccessSecret() 35 | { 36 | return null; 37 | } 38 | 39 | public function getRoleName() 40 | { 41 | return $this->roleName; 42 | } 43 | 44 | public function setRoleName($roleName) 45 | { 46 | $this->roleName = $roleName; 47 | } 48 | 49 | public function getSecurityToken() { 50 | return null; 51 | } 52 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Auth/EcsRamRoleService.php: -------------------------------------------------------------------------------- 1 | clientProfile = $clientProfile; 32 | } 33 | 34 | public function getSessionCredential() 35 | { 36 | if ($this->lastClearTime != null && $this->sessionCredential != null) { 37 | $now = time(); 38 | $elapsedTime = $now - $this->lastClearTime; 39 | if ($elapsedTime <= ECS_ROLE_EXPIRE_TIME * 0.8) { 40 | return $this->sessionCredential; 41 | } 42 | } 43 | 44 | $credential = $this->assumeRole(); 45 | 46 | if ($credential == null) { 47 | return null; 48 | } 49 | 50 | $this->sessionCredential = $credential; 51 | $this->lastClearTime = time(); 52 | 53 | return $credential; 54 | } 55 | 56 | private function assumeRole() 57 | { 58 | $ecsRamRoleCredential = $this->clientProfile->getCredential(); 59 | 60 | $requestUrl = "http://100.100.100.200/latest/meta-data/ram/security-credentials/".$ecsRamRoleCredential->getRoleName(); 61 | 62 | $httpResponse = HttpHelper::curl($requestUrl, "GET", null, null); 63 | if (!$httpResponse->isSuccess()) 64 | { 65 | return null; 66 | } 67 | 68 | $respObj = json_decode($httpResponse->getBody()); 69 | 70 | $code = $respObj->Code; 71 | if ($code != "Success") { 72 | return null; 73 | } 74 | 75 | $sessionAccessKeyId = $respObj->AccessKeyId; 76 | $sessionAccessKeySecret = $respObj->AccessKeySecret; 77 | $securityToken = $respObj->SecurityToken; 78 | 79 | return new Credential($sessionAccessKeyId, $sessionAccessKeySecret, $securityToken); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Auth/ISigner.php: -------------------------------------------------------------------------------- 1 | accessKeyId = $accessKeyId; 30 | $this->accessSecret = $accessSecret; 31 | $this->roleArn = $roleArn; 32 | $this->roleSessionName = $roleSessionName; 33 | } 34 | 35 | public function getAccessKeyId() 36 | { 37 | return $this->accessKeyId; 38 | } 39 | 40 | public function setAccessKeyId($accessKeyId) 41 | { 42 | $this->accessKeyId = $accessKeyId; 43 | } 44 | 45 | public function getAccessSecret() 46 | { 47 | return $this->accessSecret; 48 | } 49 | 50 | public function setAccessSecret($accessSecret) 51 | { 52 | $this->accessSecret = $accessSecret; 53 | } 54 | 55 | public function getRoleArn() 56 | { 57 | return $this->roleArn; 58 | } 59 | 60 | public function setRoleArn($roleArn) 61 | { 62 | $this->roleArn = $roleArn; 63 | } 64 | 65 | public function getRoleSessionName() 66 | { 67 | return $this->roleSessionName; 68 | } 69 | 70 | public function setRoleSessionName($roleSessionName) 71 | { 72 | $this->roleSessionName = $roleSessionName; 73 | } 74 | 75 | public function getSecurityToken() { 76 | return null; 77 | } 78 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Auth/RamRoleArnService.php: -------------------------------------------------------------------------------- 1 | queryParameters["RoleArn"] = $roleArn; 34 | $this->queryParameters["RoleSessionName"] = $roleSessionName; 35 | $this->queryParameters["DurationSeconds"] = ROLE_ARN_EXPIRE_TIME; 36 | $this->setRegionId(ROLE_ARN_EXPIRE_TIME); 37 | $this->setProtocol("https"); 38 | 39 | $this->setAcceptFormat("JSON"); 40 | } 41 | } 42 | 43 | class RamRoleArnService 44 | { 45 | private $clientProfile; 46 | private $lastClearTime = null; 47 | private $sessionCredential = null; 48 | public static $serviceDomain = STS_DOMAIN; 49 | 50 | function __construct($clientProfile) { 51 | $this->clientProfile = $clientProfile; 52 | } 53 | 54 | public function getSessionCredential() 55 | { 56 | if ($this->lastClearTime != null && $this->sessionCredential != null) { 57 | $now = time(); 58 | $elapsedTime = $now - $this->lastClearTime; 59 | if ($elapsedTime <= ROLE_ARN_EXPIRE_TIME * 0.8) { 60 | return $this->sessionCredential; 61 | } 62 | } 63 | 64 | $credential = $this->assumeRole(); 65 | 66 | if ($credential == null) { 67 | return null; 68 | } 69 | 70 | $this->sessionCredential = $credential; 71 | $this->lastClearTime = time(); 72 | 73 | return $credential; 74 | } 75 | 76 | private function assumeRole() 77 | { 78 | $signer = $this->clientProfile->getSigner(); 79 | $ramRoleArnCredential = $this->clientProfile->getCredential(); 80 | 81 | $request = new AssumeRoleRequest($ramRoleArnCredential->getRoleArn(), $ramRoleArnCredential->getRoleSessionName()); 82 | 83 | $requestUrl = $request->composeUrl($signer, $ramRoleArnCredential, self::$serviceDomain); 84 | 85 | $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), null, $request->getHeaders()); 86 | 87 | if (!$httpResponse->isSuccess()) 88 | { 89 | return null; 90 | } 91 | 92 | $respObj = json_decode($httpResponse->getBody()); 93 | 94 | $sessionAccessKeyId = $respObj->Credentials->AccessKeyId; 95 | $sessionAccessKeySecret = $respObj->Credentials->AccessKeySecret; 96 | $securityToken = $respObj->Credentials->SecurityToken; 97 | return new Credential($sessionAccessKeyId, $sessionAccessKeySecret, $securityToken); 98 | } 99 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Auth/ShaHmac1Signer.php: -------------------------------------------------------------------------------- 1 | iClientProfile = $iClientProfile; 31 | $this->__urlTestFlag__ = false; 32 | $this->locationService = new LocationService($this->iClientProfile); 33 | if ($this->iClientProfile->isRamRoleArn()) { 34 | $this->ramRoleArnService = new RamRoleArnService($this->iClientProfile); 35 | } 36 | if ($this->iClientProfile->isEcsRamRole()) { 37 | $this->ecsRamRoleService = new EcsRamRoleService($this->iClientProfile); 38 | } 39 | } 40 | 41 | public function getAcsResponse($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3) 42 | { 43 | $httpResponse = $this->doActionImpl($request, $iSigner, $credential, $autoRetry, $maxRetryNumber); 44 | $respObject = $this->parseAcsResponse($httpResponse->getBody(), $request->getAcceptFormat()); 45 | if (false == $httpResponse->isSuccess()) { 46 | $this->buildApiException($respObject, $httpResponse->getStatus()); 47 | } 48 | return $respObject; 49 | } 50 | 51 | private function doActionImpl($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3) 52 | { 53 | if (null == $this->iClientProfile && (null == $iSigner || null == $credential 54 | || null == $request->getRegionId() || null == $request->getAcceptFormat())) { 55 | throw new ClientException("No active profile found.", "SDK.InvalidProfile"); 56 | } 57 | if (null == $iSigner) { 58 | $iSigner = $this->iClientProfile->getSigner(); 59 | } 60 | if (null == $credential) { 61 | $credential = $this->iClientProfile->getCredential(); 62 | } 63 | if ($this->iClientProfile->isRamRoleArn()) { 64 | $credential = $this->ramRoleArnService->getSessionCredential(); 65 | } 66 | if ($this->iClientProfile->isEcsRamRole()) { 67 | $credential = $this->ecsRamRoleService->getSessionCredential(); 68 | } 69 | if (null == $credential) { 70 | throw new ClientException("Incorrect user credentials.", "SDK.InvalidCredential"); 71 | } 72 | 73 | $request = $this->prepareRequest($request); 74 | 75 | // Get the domain from the Location Service by speicified `ServiceCode` and `RegionId`. 76 | $domain = null; 77 | if (null != $request->getLocationServiceCode()) 78 | { 79 | $domain = $this->locationService->findProductDomain($request->getRegionId(), $request->getLocationServiceCode(), $request->getLocationEndpointType(), $request->getProduct()); 80 | } 81 | if ($domain == null) 82 | { 83 | $domain = EndpointProvider::findProductDomain($request->getRegionId(), $request->getProduct()); 84 | } 85 | 86 | if (null == $domain) { 87 | throw new ClientException("Can not find endpoint to access.", "SDK.InvalidRegionId"); 88 | } 89 | $requestUrl = $request->composeUrl($iSigner, $credential, $domain); 90 | 91 | if ($this->__urlTestFlag__) { 92 | throw new ClientException($requestUrl, "URLTestFlagIsSet"); 93 | } 94 | 95 | if (count($request->getDomainParameter())>0) { 96 | $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getDomainParameter(), $request->getHeaders()); 97 | } else { 98 | $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getContent(), $request->getHeaders()); 99 | } 100 | 101 | $retryTimes = 1; 102 | while (500 <= $httpResponse->getStatus() && $autoRetry && $retryTimes < $maxRetryNumber) { 103 | $requestUrl = $request->composeUrl($iSigner, $credential, $domain); 104 | 105 | if (count($request->getDomainParameter())>0) { 106 | $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getDomainParameter(), $request->getHeaders()); 107 | } else { 108 | $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getContent(), $request->getHeaders()); 109 | } 110 | $retryTimes ++; 111 | } 112 | return $httpResponse; 113 | } 114 | 115 | public function doAction($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3) 116 | { 117 | trigger_error("doAction() is deprecated. Please use getAcsResponse() instead.", E_USER_NOTICE); 118 | return $this->doActionImpl($request, $iSigner, $credential, $autoRetry, $maxRetryNumber); 119 | } 120 | 121 | private function prepareRequest($request) 122 | { 123 | if (null == $request->getRegionId()) { 124 | $request->setRegionId($this->iClientProfile->getRegionId()); 125 | } 126 | if (null == $request->getAcceptFormat()) { 127 | $request->setAcceptFormat($this->iClientProfile->getFormat()); 128 | } 129 | if (null == $request->getMethod()) { 130 | $request->setMethod("GET"); 131 | } 132 | return $request; 133 | } 134 | 135 | 136 | private function buildApiException($respObject, $httpStatus) 137 | { 138 | throw new ServerException($respObject->Message, $respObject->Code, $httpStatus, $respObject->RequestId); 139 | } 140 | 141 | private function parseAcsResponse($body, $format) 142 | { 143 | if ("JSON" == $format) { 144 | $respObject = json_decode($body); 145 | } elseif ("XML" == $format) { 146 | $respObject = @simplexml_load_string($body); 147 | } elseif ("RAW" == $format) { 148 | $respObject = $body; 149 | } 150 | return $respObject; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Exception/ClientException.php: -------------------------------------------------------------------------------- 1 | errorMessage = $errorMessage; 26 | $this->errorCode = $errorCode; 27 | $this->setErrorType("Client"); 28 | } 29 | 30 | private $errorCode; 31 | private $errorMessage; 32 | private $errorType; 33 | 34 | public function getErrorCode() 35 | { 36 | return $this->errorCode; 37 | } 38 | 39 | public function setErrorCode($errorCode) 40 | { 41 | $this->errorCode = $errorCode; 42 | } 43 | 44 | public function getErrorMessage() 45 | { 46 | return $this->errorMessage; 47 | } 48 | 49 | public function setErrorMessage($errorMessage) 50 | { 51 | $this->errorMessage = $errorMessage; 52 | } 53 | 54 | public function getErrorType() 55 | { 56 | return $this->errorType; 57 | } 58 | 59 | public function setErrorType($errorType) 60 | { 61 | $this->errorType = $errorType; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Exception/ServerException.php: -------------------------------------------------------------------------------- 1 | setErrorMessage($errorMessage); 30 | $this->setErrorType("Server"); 31 | $this->httpStatus = $httpStatus; 32 | $this->requestId = $requestId; 33 | } 34 | 35 | public function getHttpStatus() 36 | { 37 | return $this->httpStatus; 38 | } 39 | 40 | public function getRequestId() 41 | { 42 | return $this->requestId; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Http/HttpHelper.php: -------------------------------------------------------------------------------- 1 | 5 && strtolower(substr($url, 0, 5)) == "https") { 48 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 49 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 50 | } 51 | if (is_array($headers) && 0 < count($headers)) { 52 | $httpHeaders =self::getHttpHearders($headers); 53 | curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); 54 | } 55 | $httpResponse = new HttpResponse(); 56 | $httpResponse->setBody(curl_exec($ch)); 57 | $httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE)); 58 | if (curl_errno($ch)) { 59 | throw new ClientException("Server unreachable: Errno: " . curl_errno($ch) . " " . curl_error($ch), "SDK.ServerUnreachable"); 60 | } 61 | curl_close($ch); 62 | return $httpResponse; 63 | } 64 | public static function getPostHttpBody($postFildes) 65 | { 66 | $content = ""; 67 | foreach ($postFildes as $apiParamKey => $apiParamValue) { 68 | $content .= "$apiParamKey=" . urlencode($apiParamValue) . "&"; 69 | } 70 | return substr($content, 0, -1); 71 | } 72 | public static function getHttpHearders($headers) 73 | { 74 | $httpHeader = array(); 75 | foreach ($headers as $key => $value) { 76 | array_push($httpHeader, $key.":".$value); 77 | } 78 | return $httpHeader; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Http/HttpResponse.php: -------------------------------------------------------------------------------- 1 | body; 28 | } 29 | 30 | public function setBody($body) 31 | { 32 | $this->body = $body; 33 | } 34 | 35 | public function getStatus() 36 | { 37 | return $this->status; 38 | } 39 | 40 | public function setStatus($status) 41 | { 42 | $this->status = $status; 43 | } 44 | 45 | public function isSuccess() 46 | { 47 | if (200 <= $this->status && 300 > $this->status) { 48 | return true; 49 | } 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/IAcsClient.php: -------------------------------------------------------------------------------- 1 | $endpoint) 142 | { 143 | if($endpoint->getName() == $endpointName) 144 | { 145 | return $endpoint; 146 | } 147 | } 148 | } 149 | 150 | private static function addEndpoint_($endpointName,$regionId, $product, $domain) 151 | { 152 | $regionIds = array($regionId); 153 | $productsDomains = array(new ProductDomain($product, $domain)); 154 | $endpoint = new Endpoint($endpointName, $regionIds, $productsDomains); 155 | array_push(self::$endpoints, $endpoint); 156 | } 157 | 158 | private static function updateEndpoint($regionId, $product, $domain, $endpoint) 159 | { 160 | $regionIds = $endpoint->getRegionIds(); 161 | if(!in_array($regionId,$regionIds)) 162 | { 163 | array_push($regionIds, $regionId); 164 | $endpoint->setRegionIds($regionIds); 165 | } 166 | 167 | $productDomains = $endpoint->getProductDomains(); 168 | if (null == self::findProductDomainAndUpdate($productDomains, $product, $domain)) { 169 | array_push($productDomains, new ProductDomain($product, $domain)); 170 | } 171 | 172 | $endpoint->setProductDomains($productDomains); 173 | } 174 | 175 | private static function findProductDomainAndUpdate($productDomains, $product, $domain) 176 | { 177 | foreach ($productDomains as $key => $productDomain) { 178 | if ($productDomain->getProductName() == $product) { 179 | $productDomain->setDomainName($domain); 180 | return $productDomain; 181 | } 182 | } 183 | return null; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Profile/IClientProfile.php: -------------------------------------------------------------------------------- 1 | name = $name; 29 | $this->regionIds = $regionIds; 30 | $this->productDomains = $productDomains; 31 | } 32 | 33 | public function getName() 34 | { 35 | return $this->name; 36 | } 37 | 38 | public function setName($name) 39 | { 40 | $this->name = $name; 41 | } 42 | 43 | public function getRegionIds() 44 | { 45 | return $this->regionIds; 46 | } 47 | 48 | public function setRegionIds($regionIds) 49 | { 50 | $this->regionIds = $regionIds; 51 | } 52 | 53 | public function getProductDomains() 54 | { 55 | return $this->productDomains; 56 | } 57 | 58 | public function setProductDomains($productDomains) 59 | { 60 | $this->productDomains = $productDomains; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Regions/EndpointConfig.php: -------------------------------------------------------------------------------- 1 | $endpoint) { 30 | if (in_array($regionId, $endpoint->getRegionIds())) { 31 | return self::findProductDomainByProduct($endpoint->getProductDomains(), $product); 32 | } 33 | } 34 | return null; 35 | } 36 | 37 | private static function findProductDomainByProduct($productDomains, $product) 38 | { 39 | if (null == $productDomains) { 40 | return null; 41 | } 42 | foreach ($productDomains as $key => $productDomain) { 43 | if ($product == $productDomain->getProductName()) { 44 | return $productDomain->getDomainName(); 45 | } 46 | } 47 | return null; 48 | } 49 | 50 | 51 | public static function getEndpoints() 52 | { 53 | return self::$endpoints; 54 | } 55 | 56 | public static function setEndpoints($endpoints) 57 | { 58 | self::$endpoints = $endpoints; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Regions/LocationService.php: -------------------------------------------------------------------------------- 1 | queryParameters["Id"] = $id; 35 | $this->queryParameters["ServiceCode"] = $serviceCode; 36 | $this->queryParameters["Type"] = $endPointType; 37 | $this->setRegionId(LOCATION_SERVICE_REGION); 38 | 39 | $this->setAcceptFormat("JSON"); 40 | } 41 | } 42 | 43 | class LocationService 44 | { 45 | private $clientProfile; 46 | public static $cache = array(); 47 | public static $lastClearTimePerProduct = array(); 48 | public static $serviceDomain = LOCATION_SERVICE_DOMAIN; 49 | 50 | function __construct($clientProfile) 51 | { 52 | $this->clientProfile = $clientProfile; 53 | } 54 | 55 | public function findProductDomain($regionId, $serviceCode, $endPointType, $product) 56 | { 57 | $key = $regionId . '#' . $product; 58 | @$domain = self::$cache[$key]; 59 | if ($domain == null || $this->checkCacheIsExpire($key) == true) { 60 | $domain = $this->findProductDomainFromLocationService($regionId, $serviceCode, $endPointType); 61 | self::$cache[$key] = $domain; 62 | } 63 | 64 | return $domain; 65 | } 66 | 67 | public static function addEndPoint($regionId, $product, $domain) 68 | { 69 | $key = $regionId . '#' . $product; 70 | self::$cache[$key] = $domain; 71 | $lastClearTime = mktime(0, 0, 0, 1, 1, 2999); 72 | self::$lastClearTimePerProduct[$key] = $lastClearTime; 73 | } 74 | 75 | public static function modifyServiceDomain($domain) 76 | { 77 | self::$serviceDomain = $domain; 78 | } 79 | 80 | private function checkCacheIsExpire($key) 81 | { 82 | $lastClearTime = self::$lastClearTimePerProduct[$key]; 83 | if ($lastClearTime == null) { 84 | $lastClearTime = time(); 85 | self::$lastClearTimePerProduct[$key] = $lastClearTime; 86 | } 87 | 88 | $now = time(); 89 | $elapsedTime = $now - $lastClearTime; 90 | 91 | if ($elapsedTime > CACHE_EXPIRE_TIME) { 92 | $lastClearTime = time(); 93 | self::$lastClearTimePerProduct[$key] = $lastClearTime; 94 | return true; 95 | } 96 | 97 | return false; 98 | } 99 | 100 | private function findProductDomainFromLocationService($regionId, $serviceCode, $endPointType) 101 | { 102 | $request = new DescribeEndpointRequest($regionId, $serviceCode, $endPointType); 103 | 104 | $signer = $this->clientProfile->getSigner(); 105 | $credential = $this->clientProfile->getCredential(); 106 | 107 | $requestUrl = $request->composeUrl($signer, $credential, self::$serviceDomain); 108 | 109 | $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), null, $request->getHeaders()); 110 | 111 | if (!$httpResponse->isSuccess()) { 112 | return null; 113 | } 114 | 115 | $respObj = json_decode($httpResponse->getBody()); 116 | return $respObj->Endpoints->Endpoint[0]->Endpoint; 117 | } 118 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/Regions/ProductDomain.php: -------------------------------------------------------------------------------- 1 | productName = $product; 28 | $this->domainName = $domain; 29 | } 30 | 31 | public function getProductName() 32 | { 33 | return $this->productName; 34 | } 35 | public function setProductName($productName) 36 | { 37 | $this->productName = $productName; 38 | } 39 | public function getDomainName() 40 | { 41 | return $this->domainName; 42 | } 43 | public function setDomainName($domainName) 44 | { 45 | $this->domainName = $domainName; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/RoaAcsRequest.php: -------------------------------------------------------------------------------- 1 | setVersion($version); 33 | $this->initialize(); 34 | } 35 | 36 | private function initialize() 37 | { 38 | $this->setMethod("RAW"); 39 | $this->setAcceptFormat("JSON"); 40 | } 41 | 42 | public function composeUrl($iSigner, $credential, $domain) 43 | { 44 | $this->prepareHeader($iSigner); 45 | 46 | $signString = $this->getMethod().self::$headerSeparator; 47 | if (isset($this->headers["Accept"])) { 48 | $signString = $signString.$this->headers["Accept"]; 49 | } 50 | $signString = $signString.self::$headerSeparator; 51 | 52 | if (isset($this->headers["Content-MD5"])) { 53 | $signString = $signString.$this->headers["Content-MD5"]; 54 | } 55 | $signString = $signString.self::$headerSeparator; 56 | 57 | if (isset($this->headers["Content-Type"])) { 58 | $signString = $signString.$this->headers["Content-Type"]; 59 | } 60 | $signString = $signString.self::$headerSeparator; 61 | 62 | if (isset($this->headers["Date"])) { 63 | $signString = $signString.$this->headers["Date"]; 64 | } 65 | $signString = $signString.self::$headerSeparator; 66 | 67 | $uri = $this->replaceOccupiedParameters(); 68 | $signString = $signString.$this->buildCanonicalHeaders(); 69 | $queryString = $this->buildQueryString($uri); 70 | $signString .= $queryString; 71 | $this->headers["Authorization"] = "acs ".$credential->getAccessKeyId().":" 72 | .$iSigner->signString($signString, $credential->getAccessSecret()); 73 | $requestUrl = $this->getProtocol()."://".$domain.$uri.$this->concatQueryString(); 74 | return $requestUrl; 75 | } 76 | 77 | private function concatQueryString() { 78 | $sortMap = $this->queryParameters; 79 | if(null == $sortMap || count($sortMap) == 0){ 80 | return ""; 81 | } 82 | $queryString =""; 83 | ksort($sortMap); 84 | foreach ($sortMap as $sortMapKey => $sortMapValue) { 85 | $queryString = $queryString.$sortMapKey; 86 | if (isset($sortMapValue)) { 87 | $queryString = $queryString."=".urlencode($sortMapValue); 88 | } 89 | $queryString .= self::$querySeprator; 90 | } 91 | 92 | if (count($sortMap) > 0) { 93 | $queryString = substr($queryString, 0, strlen($queryString)-1); 94 | } 95 | return '?'.$queryString; 96 | } 97 | 98 | private function prepareHeader($iSigner) 99 | { 100 | $this->headers["Date"] = gmdate($this->dateTimeFormat); 101 | if (null == $this->acceptFormat) { 102 | $this->acceptFormat = "RAW"; 103 | } 104 | $this->headers["Accept"] = $this->formatToAccept($this->getAcceptFormat()); 105 | $this->headers["x-acs-signature-method"] = $iSigner->getSignatureMethod(); 106 | $this->headers["x-acs-signature-version"] = $iSigner->getSignatureVersion(); 107 | $this->headers["x-acs-region-id"] = $this->regionId; 108 | $content = $this->getContent(); 109 | if ($content != null) { 110 | $this->headers["Content-MD5"] = base64_encode(md5($content, true)); 111 | } 112 | 113 | $this->headers["Content-Type"] = "application/json;charset=utf-8"; 114 | } 115 | 116 | private function replaceOccupiedParameters() 117 | { 118 | $result = $this->uriPattern; 119 | foreach ($this->pathParameters as $pathParameterKey => $apiParameterValue) { 120 | $target = "[".$pathParameterKey."]"; 121 | $result = str_replace($target, $apiParameterValue, $result); 122 | } 123 | return $result; 124 | } 125 | 126 | private function buildCanonicalHeaders() 127 | { 128 | $sortMap = array(); 129 | foreach ($this->headers as $headerKey => $headerValue) { 130 | $key = strtolower($headerKey); 131 | if (strpos($key, "x-acs-") === 0) { 132 | $sortMap[$key] = $headerValue; 133 | } 134 | } 135 | ksort($sortMap); 136 | $headerString = ""; 137 | foreach ($sortMap as $sortMapKey => $sortMapValue) { 138 | $headerString = $headerString.$sortMapKey.":".$sortMapValue.self::$headerSeparator; 139 | } 140 | return $headerString; 141 | } 142 | 143 | private function splitSubResource($uri) 144 | { 145 | $queIndex = strpos($uri, "?"); 146 | $uriParts = array(); 147 | if (null != $queIndex) { 148 | array_push($uriParts, substr($uri, 0, $queIndex)); 149 | array_push($uriParts, substr($uri, $queIndex+1)); 150 | } else { 151 | array_push($uriParts, $uri); 152 | } 153 | return $uriParts; 154 | } 155 | 156 | private function buildQueryString($uri) 157 | { 158 | $uriParts = $this->splitSubResource($uri); 159 | $sortMap = $this->queryParameters; 160 | if (isset($uriParts[1])) { 161 | $sortMap[$uriParts[1]] = null; 162 | } 163 | $queryString = $uriParts[0]; 164 | if (count($sortMap) > 0) { 165 | $queryString = $queryString."?"; 166 | } 167 | ksort($sortMap); 168 | foreach ($sortMap as $sortMapKey => $sortMapValue) { 169 | $queryString = $queryString.$sortMapKey; 170 | if (isset($sortMapValue)) { 171 | $queryString = $queryString."=".$sortMapValue; 172 | } 173 | $queryString = $queryString.self::$querySeprator; 174 | } 175 | if (count($sortMap) > 0) { 176 | $queryString = substr($queryString, 0, strlen($queryString)-1); 177 | } 178 | return $queryString; 179 | } 180 | 181 | private function formatToAccept($acceptFormat) 182 | { 183 | if ($acceptFormat == "JSON") { 184 | return "application/json"; 185 | } elseif ($acceptFormat == "XML") { 186 | return "application/xml"; 187 | } 188 | return "application/octet-stream"; 189 | } 190 | 191 | public function getPathParameters() 192 | { 193 | return $this->pathParameters; 194 | } 195 | 196 | public function putPathParameter($name, $value) 197 | { 198 | $this->pathParameters[$name] = $value; 199 | } 200 | 201 | public function getDomainParameter() 202 | { 203 | return $this->domainParameters; 204 | } 205 | 206 | public function putDomainParameters($name, $value) 207 | { 208 | $this->domainParameters[$name] = $value; 209 | } 210 | 211 | public function getUriPattern() 212 | { 213 | return $this->uriPattern; 214 | } 215 | 216 | public function setUriPattern($uriPattern) 217 | { 218 | return $this->uriPattern = $uriPattern; 219 | } 220 | 221 | public function setVersion($version) 222 | { 223 | $this->version = $version; 224 | $this->headers["x-acs-version"] = $version; 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/RpcAcsRequest.php: -------------------------------------------------------------------------------- 1 | initialize(); 29 | } 30 | 31 | private function initialize() 32 | { 33 | $this->setMethod("GET"); 34 | $this->setAcceptFormat("JSON"); 35 | } 36 | 37 | private function prepareValue($value) 38 | { 39 | if (is_bool($value)) { 40 | if ($value) { 41 | return "true"; 42 | } else { 43 | return "false"; 44 | } 45 | } else { 46 | return $value; 47 | } 48 | } 49 | 50 | public function composeUrl($iSigner, $credential, $domain) 51 | { 52 | $apiParams = parent::getQueryParameters(); 53 | foreach ($apiParams as $key => $value) { 54 | $apiParams[$key] = $this->prepareValue($value); 55 | } 56 | $apiParams["RegionId"] = $this->getRegionId(); 57 | $apiParams["AccessKeyId"] = $credential->getAccessKeyId(); 58 | $apiParams["Format"] = $this->getAcceptFormat(); 59 | $apiParams["SignatureMethod"] = $iSigner->getSignatureMethod(); 60 | $apiParams["SignatureVersion"] = $iSigner->getSignatureVersion(); 61 | $apiParams["SignatureNonce"] = md5(uniqid(mt_rand(), true)); 62 | $apiParams["Timestamp"] = gmdate($this->dateTimeFormat); 63 | $apiParams["Action"] = $this->getActionName(); 64 | $apiParams["Version"] = $this->getVersion(); 65 | if ($credential->getSecurityToken() != null) { 66 | $apiParams["SecurityToken"] = $credential->getSecurityToken(); 67 | } 68 | $apiParams["Signature"] = $this->computeSignature($apiParams, $credential->getAccessSecret(), $iSigner); 69 | if (parent::getMethod() == "POST") { 70 | $requestUrl = $this->getProtocol()."://". $domain . "/"; 71 | foreach ($apiParams as $apiParamKey => $apiParamValue) { 72 | $this->putDomainParameters($apiParamKey, $apiParamValue); 73 | } 74 | return $requestUrl; 75 | } else { 76 | $requestUrl = $this->getProtocol()."://". $domain . "/?"; 77 | 78 | foreach ($apiParams as $apiParamKey => $apiParamValue) { 79 | $requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&"; 80 | } 81 | return substr($requestUrl, 0, -1); 82 | } 83 | } 84 | 85 | private function computeSignature($parameters, $accessKeySecret, $iSigner) 86 | { 87 | ksort($parameters); 88 | $canonicalizedQueryString = ''; 89 | foreach ($parameters as $key => $value) { 90 | $canonicalizedQueryString .= '&' . $this->percentEncode($key). '=' . $this->percentEncode($value); 91 | } 92 | $stringToSign = parent::getMethod().'&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1)); 93 | $signature = $iSigner->signString($stringToSign, $accessKeySecret."&"); 94 | 95 | return $signature; 96 | } 97 | 98 | protected function percentEncode($str) 99 | { 100 | $res = urlencode($str); 101 | $res = preg_replace('/\+/', '%20', $res); 102 | $res = preg_replace('/\*/', '%2A', $res); 103 | $res = preg_replace('/%7E/', '~', $res); 104 | return $res; 105 | } 106 | 107 | public function getDomainParameter() 108 | { 109 | return $this->domainParameters; 110 | } 111 | 112 | public function putDomainParameters($name, $value) 113 | { 114 | $this->domainParameters[$name] = $value; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Auth/CredentialTest.php: -------------------------------------------------------------------------------- 1 | assertEquals("accessKeyId", $credential->getAccessKeyId()); 27 | $this->assertEquals("accessSecret", $credential->getAccessSecret()); 28 | $this->assertNotNull($credential->getRefreshDate()); 29 | 30 | $dateNow = date("Y-m-d\TH:i:s\Z"); 31 | $credential->setExpiredDate(1); 32 | $this->assertNotNull($credential->getExpiredDate()); 33 | $this->assertTrue($credential->getExpiredDate() > $dateNow); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Auth/ShaHmac1SignerTest.php: -------------------------------------------------------------------------------- 1 | assertEquals("33nmIV5/p6kG/64eLXNljJ5vw84=", $signer->signString("this is a ShaHmac1 test.", "accessSecret")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Auth/ShaHmac256SignerTest.php: -------------------------------------------------------------------------------- 1 | assertEquals("TpF1lE/avV9EHGWGg9Vo/QTd2bLRwFCk9jjo56uRbCo=", 28 | $signer->signString("this is a ShaHmac256 test.", "accessSecret")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/BaseTest.php: -------------------------------------------------------------------------------- 1 | client = new DefaultAcsClient($iClientProfile); 32 | } 33 | 34 | public function getProperty($propertyKey) 35 | { 36 | $accessKey = ""; 37 | $accessSecret = ""; 38 | $iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "AccessKey", "AccessSecret"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/BatchCompute/ListImagesRequest.php: -------------------------------------------------------------------------------- 1 | setUriPattern("/images"); 28 | $this->setMethod("GET"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/DefaultAcsClientTest.php: -------------------------------------------------------------------------------- 1 | client->doAction($request); 30 | 31 | $this->assertNotNull($response->RequestId); 32 | $this->assertNotNull($response->Regions->Region[0]->LocalName); 33 | $this->assertNotNull($response->Regions->Region[0]->RegionId); 34 | } 35 | 36 | public function testDoActionROA() 37 | { 38 | $request = new BC\ListImagesRequest(); 39 | $response = $this->client->doAction($request); 40 | $this->assertNotNull($response); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Ecs/Rquest/DescribeRegionsRequest.php: -------------------------------------------------------------------------------- 1 | ownerId; 40 | } 41 | 42 | public function setOwnerId($ownerId) 43 | { 44 | $this->ownerId = $ownerId; 45 | $this->queryParameters["OwnerId"]=$ownerId; 46 | } 47 | 48 | public function getResourceOwnerAccount() 49 | { 50 | return $this->resourceOwnerAccount; 51 | } 52 | 53 | public function setResourceOwnerAccount($resourceOwnerAccount) 54 | { 55 | $this->resourceOwnerAccount = $resourceOwnerAccount; 56 | $this->queryParameters["ResourceOwnerAccount"]=$resourceOwnerAccount; 57 | } 58 | 59 | public function getResourceOwnerId() 60 | { 61 | return $this->resourceOwnerId; 62 | } 63 | 64 | public function setResourceOwnerId($resourceOwnerId) 65 | { 66 | $this->resourceOwnerId = $resourceOwnerId; 67 | $this->queryParameters["ResourceOwnerId"]=$resourceOwnerId; 68 | } 69 | 70 | public function getOwnerAccount() 71 | { 72 | return $this->ownerAccount; 73 | } 74 | 75 | public function setOwnerAccount($ownerAccount) 76 | { 77 | $this->ownerAccount = $ownerAccount; 78 | $this->queryParameters["OwnerAccount"]=$ownerAccount; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Ft/InteTest.php: -------------------------------------------------------------------------------- 1 | ", 10 | "", 11 | "" 12 | ); 13 | 14 | DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", "Ft", "ft.aliyuncs.com"); 15 | 16 | print_r("1.开始测试普通AK访问: "); 17 | echo "\n"; 18 | $client = new DefaultAcsClient($clientProfile); 19 | # 创建 API 请求并设置参数 20 | $request = new TestRpcApiRequest(); 21 | $request->setQueryParam("conan"); 22 | # 发起请求并处理返回 23 | $response = $client->getAcsResponse($request); 24 | print_r($response); 25 | 26 | # 创建 API 请求并设置参数 27 | $request = new TestRoaApiRequest(); 28 | $request->setQueryParam("conan"); 29 | # 发起请求并处理返回 30 | $response = $client->getAcsResponse($request); 31 | print_r($response); 32 | 33 | //RoleArn 34 | echo "\n"; 35 | print_r("2.开始测试RoleArn: "); 36 | echo "\n"; 37 | $ramRoleArnProfile = DefaultProfile::getRamRoleArnProfile( 38 | "cn-hangzhou", 39 | "", 40 | "", 41 | "", 42 | "" 43 | ); 44 | 45 | $roleArnClient = new DefaultAcsClient($ramRoleArnProfile); 46 | 47 | # 创建 API 请求并设置参数 48 | $request = new TestRpcApiRequest(); 49 | $request->setQueryParam("conan"); 50 | # 发起请求并处理返回 51 | $response = $roleArnClient->getAcsResponse($request); 52 | print_r($response); 53 | 54 | # 创建 API 请求并设置参数 55 | $request = new TestRoaApiRequest(); 56 | $request->setQueryParam("conan"); 57 | # 发起请求并处理返回 58 | $response = $roleArnClient->getAcsResponse($request); 59 | print_r($response); 60 | 61 | //EcsRole 62 | //mock接口打开之前不要跑 63 | echo "\n"; 64 | print_r("3.开始测试EcsArn: "); 65 | echo "\n"; 66 | $ecsRamRoleProfile = DefaultProfile::getEcsRamRoleProfile( 67 | "cn-hangzhou", 68 | "" 69 | ); 70 | 71 | $ecsRamRoleClient = new DefaultAcsClient($ecsRamRoleProfile); 72 | 73 | # 创建 API 请求并设置参数 74 | $request = new TestRpcApiRequest(); 75 | $request->setQueryParam("conan"); 76 | # 发起请求并处理返回 77 | $response = $ecsRamRoleClient->getAcsResponse($request); 78 | print_r($response); 79 | 80 | # 创建 API 请求并设置参数 81 | $request = new TestRoaApiRequest(); 82 | $request->setQueryParam("conan"); 83 | # 发起请求并处理返回 84 | $response = $ecsRamRoleClient->getAcsResponse($request); 85 | print_r($response); -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Ft/TestRoaApiRequest.php: -------------------------------------------------------------------------------- 1 | setUriPattern("/web/cloudapi"); 16 | $this->setMethod("GET"); 17 | } 18 | 19 | private $queryParam; 20 | 21 | private $bodyParam; 22 | 23 | private $headerParam; 24 | 25 | public function getQueryParam() 26 | { 27 | return $this->queryParam; 28 | } 29 | 30 | public function setQueryParam($queryParam) 31 | { 32 | $this->queryParam = $queryParam; 33 | $this->queryParameters["QueryParam"]=$queryParam; 34 | } 35 | 36 | public function getBodyParam() 37 | { 38 | return $this->bodyParam; 39 | } 40 | 41 | public function setBodyParam($bodyParam) 42 | { 43 | $this->bodyParam = $bodyParam; 44 | $this->queryParameters["BodyParam"]=$bodyParam; 45 | } 46 | 47 | public function getHeaderParam() 48 | { 49 | return $this->headerParam; 50 | } 51 | 52 | public function setHeaderParam($headerParam) 53 | { 54 | $this->headerParam = $headerParam; 55 | $this->headerParam["HeaderParam"]=$headerParam; 56 | } 57 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Ft/TestRpcApiRequest.php: -------------------------------------------------------------------------------- 1 | queryParam; 24 | } 25 | 26 | public function setQueryParam($queryParam) 27 | { 28 | $this->queryParam = $queryParam; 29 | $this->queryParameters["QueryParam"]=$queryParam; 30 | } 31 | 32 | public function getBodyParam() 33 | { 34 | return $this->bodyParam; 35 | } 36 | 37 | public function setBodyParam($bodyParam) 38 | { 39 | $this->bodyParam = $bodyParam; 40 | $this->queryParameters["BodyParam"]=$bodyParam; 41 | } 42 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Http/HttpHelperTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(400, $httpResponse->getStatus()); 27 | $this->assertNotNull($httpResponse->getBody()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Profile/DefaultProfileTest.php: -------------------------------------------------------------------------------- 1 | assertEquals("cn-hangzhou", $profile->getRegionId()); 27 | $this->assertEquals("accessId", $profile->getCredential()->getAccessKeyId()); 28 | $this->assertEquals("accessSecret", $profile->getCredential()->getAccessSecret()); 29 | } 30 | 31 | public function testAddEndpoint() 32 | { 33 | $profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret"); 34 | $profile->addEndpoint("cn-hangzhou", "cn-hangzhou", "TestProduct", "testproduct.aliyuncs.com"); 35 | $endpoints = $profile->getEndpoints(); 36 | foreach ($endpoints as $key => $endpoint) { 37 | if ("cn-hangzhou" == $endpoint->getName()) { 38 | $regionIds = $endpoint->getRegionIds(); 39 | $this->assertContains("cn-hangzhou", $regionIds); 40 | 41 | $productDomains= $endpoint->getProductDomains(); 42 | $this->assertNotNull($productDomains); 43 | $productDomain = $this->getProductDomain($productDomains); 44 | $this->assertNotNull($productDomain); 45 | $this->assertEquals("TestProduct", $productDomain->getProductName()); 46 | $this->assertEquals("testproduct.aliyuncs.com", $productDomain->getDomainName()); 47 | } 48 | } 49 | } 50 | 51 | private function getProductDomain($productDomains) 52 | { 53 | foreach ($productDomains as $productDomain) { 54 | if ($productDomain->getProductName() == "TestProduct") { 55 | return $productDomain; 56 | } 57 | } 58 | return null; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Regions/EndPointByLocationTest.php: -------------------------------------------------------------------------------- 1 | clientProfile = DefaultProfile::getProfile( 23 | "cn-shanghai", # 您的 Region ID 24 | "", # 您的 Access Key ID 25 | "" # 您的 Access Key Secret 26 | ); 27 | 28 | $this->locationService = new LocationService($this->clientProfile); 29 | } 30 | 31 | public function testFindProductDomain() 32 | { 33 | $this->initClient(); 34 | $domain = $this->locationService->findProductDomain("cn-shanghai", "apigateway", "openAPI", "CloudAPI"); 35 | $this->assertEquals("apigateway.cn-shanghai.aliyuncs.com", $domain); 36 | } 37 | 38 | public function testFindProductDomainWithAddEndPoint() 39 | { 40 | DefaultProfile::addEndpoint("cn-shanghai", "cn-shanghai", "CloudAPI", "apigateway.cn-shanghai123.aliyuncs.com"); 41 | $this->initClient(); 42 | $domain = $this->locationService->findProductDomain("cn-shanghai", "apigateway", "openAPI", "CloudAPI"); 43 | $this->assertEquals("apigateway.cn-shanghai123.aliyuncs.com", $domain); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /aliyun-php-sdk-core/UnitTest/Regions/EndpointProviderTest.php: -------------------------------------------------------------------------------- 1 | assertEquals("ecs.aliyuncs.com", EndpointProvider::findProductDomain("cn-hangzhou", "Ecs")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aliyun-php-sdk-nls-cloud-meta/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 2018-07-13 Version: 1.0.0 2 | 1, Create authorization token for NLS services 3 | 4 | -------------------------------------------------------------------------------- /aliyun-php-sdk-nls-cloud-meta/nls_cloud_meta/Request/V20180518/CreateTokenRequest.php: -------------------------------------------------------------------------------- 1 | setUriPattern("/pop/2018-05-18/tokens"); 28 | $this->setMethod("POST"); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-nls-filetrans/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 2018-10-18 Version: 1.0.0 2 | 1, First version of aliyun speech to text SDK for php. 3 | 4 | 5 | -------------------------------------------------------------------------------- /aliyun-php-sdk-nls-filetrans/nls_filetrans/Request/V20180817/GetTaskResultRequest.php: -------------------------------------------------------------------------------- 1 | debug; 35 | } 36 | 37 | public function setDebug($debug) { 38 | $this->debug = $debug; 39 | $this->queryParameters["Debug"]=$debug; 40 | } 41 | 42 | public function getTaskId() { 43 | return $this->taskId; 44 | } 45 | 46 | public function setTaskId($taskId) { 47 | $this->taskId = $taskId; 48 | $this->queryParameters["TaskId"]=$taskId; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /aliyun-php-sdk-nls-filetrans/nls_filetrans/Request/V20180817/SubmitTaskRequest.php: -------------------------------------------------------------------------------- 1 | setMethod("POST"); 28 | } 29 | 30 | private $task; 31 | 32 | private $debug; 33 | 34 | public function getTask() { 35 | return $this->task; 36 | } 37 | 38 | public function setTask($task) { 39 | $this->task = $task; 40 | $this->queryParameters["Task"]=$task; 41 | } 42 | 43 | public function getDebug() { 44 | return $this->debug; 45 | } 46 | 47 | public function setDebug($debug) { 48 | $this->debug = $debug; 49 | $this->queryParameters["Debug"]=$debug; 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cmstop/aliyun-openapi-php-sdk", 3 | "description": "基于 aliyun-openapi-php-sdk 提取部分sdk供项目调用", 4 | "type": "library", 5 | "keywords": [ 6 | "Alibaba cloud open sdk", 7 | "CmsTop" 8 | ], 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Jade", 13 | "email": "hmy940118@gmail.com" 14 | } 15 | ], 16 | "require": { 17 | "php":">=5.4" 18 | }, 19 | "autoload":{ 20 | "classmap": [ 21 | "aliyun-php-sdk-core/" 22 | ], 23 | "psr-4":{ 24 | "nls_cloud_meta\\": "aliyun-php-sdk-nls-cloud-meta/nls_cloud_meta/", 25 | "nls_filetrans\\": "aliyun-php-sdk-nls-filetrans/nls_filetrans/" 26 | }, 27 | "files": [ 28 | "aliyun-php-sdk-core/Config.php" 29 | ] 30 | } 31 | } 32 | --------------------------------------------------------------------------------