Skip to content

Commit b285d38

Browse files
committed
Generated php 2020-02-12 for ImageSearch.
1 parent 896d122 commit b285d38

24 files changed

+2409
-4
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2020-06-28 Version: 0.2.13
2+
- Generated php 2020-02-12 for ImageSearch.
3+

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ English | [简体中文](README-CN.md)
22

33
![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg)
44

5-
## Alibaba Cloud ImageSearch SDK Library for PHP
5+
## Alibaba Cloud image search (20200212) SDK Library for PHP
66

77
## Installation
88

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg)
44

5-
## Alibaba Cloud ImageSearch SDK Library for PHP
5+
## Alibaba Cloud image search (20200212) SDK Library for PHP
66

77
## 安装
88

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "alibabacloud/imagesearch-20200212",
3-
"description": "Alibaba Cloud ImageSearch SDK Library for PHP",
3+
"description": "Alibaba Cloud image search (20200212) SDK Library for PHP",
44
"type": "library",
55
"license": "Apache-2.0",
66
"authors": [
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": ">5.5",
1414
"alibabacloud/tea-oss-sdk": "^0.3.0",
15-
"alibabacloud/openplatform-20191219": "^0.2.8",
15+
"alibabacloud/openplatform-20191219": "1.0.0",
1616
"alibabacloud/tea-rpc-utils": "^0.2.0",
1717
"alibabacloud/tea-rpc": "^0.1.5",
1818
"alibabacloud/tea-oss-utils": "^0.2.0",

src/ImageSearch.php

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
<?php
2+
3+
// This file is auto-generated, don't edit it. Thanks.
4+
5+
namespace AlibabaCloud\SDK\ImageSearch\V20200212;
6+
7+
use AlibabaCloud\Endpoint\Endpoint;
8+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\AddImageAdvanceRequest;
9+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\AddImageRequest;
10+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\AddImageResponse;
11+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\DeleteImageRequest;
12+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\DeleteImageResponse;
13+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\SearchImageByNameRequest;
14+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\SearchImageByNameResponse;
15+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\SearchImageByPicAdvanceRequest;
16+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\SearchImageByPicRequest;
17+
use AlibabaCloud\SDK\ImageSearch\V20200212\Models\SearchImageByPicResponse;
18+
use AlibabaCloud\SDK\OpenPlatform\V20191219\Models\AuthorizeFileUploadRequest;
19+
use AlibabaCloud\SDK\OpenPlatform\V20191219\OpenPlatform;
20+
use AlibabaCloud\SDK\OSS\OSS;
21+
use AlibabaCloud\SDK\OSS\OSS\PostObjectRequest;
22+
use AlibabaCloud\SDK\OSS\OSS\PostObjectRequest\header;
23+
use AlibabaCloud\Tea\FileForm\FileForm\FileField;
24+
use AlibabaCloud\Tea\Rpc\Rpc;
25+
use AlibabaCloud\Tea\Rpc\Rpc\Config;
26+
use AlibabaCloud\Tea\RpcUtils\RpcUtils;
27+
use AlibabaCloud\Tea\Utils\Utils;
28+
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
29+
30+
class ImageSearch extends Rpc
31+
{
32+
public function __construct($config)
33+
{
34+
parent::__construct($config);
35+
$this->_endpointRule = '';
36+
$this->checkConfig($config);
37+
$this->_endpoint = $this->getEndpoint('imagesearch', $this->_regionId, $this->_endpointRule, $this->_network, $this->_suffix, $this->_endpointMap, $this->_endpoint);
38+
}
39+
40+
/**
41+
* @throws \Exception
42+
*
43+
* @return SearchImageByNameResponse
44+
*/
45+
public function searchImageByName(SearchImageByNameRequest $request, RuntimeOptions $runtime)
46+
{
47+
Utils::validateModel($request);
48+
49+
return SearchImageByNameResponse::fromMap($this->doRequest('SearchImageByName', 'HTTPS', 'POST', '2020-02-12', 'AK', null, $request, $runtime));
50+
}
51+
52+
/**
53+
* @throws \Exception
54+
*
55+
* @return SearchImageByPicResponse
56+
*/
57+
public function searchImageByPic(SearchImageByPicRequest $request, RuntimeOptions $runtime)
58+
{
59+
Utils::validateModel($request);
60+
61+
return SearchImageByPicResponse::fromMap($this->doRequest('SearchImageByPic', 'HTTPS', 'POST', '2020-02-12', 'AK', null, $request, $runtime));
62+
}
63+
64+
/**
65+
* @throws \Exception
66+
*
67+
* @return SearchImageByPicResponse
68+
*/
69+
public function searchImageByPicAdvance(SearchImageByPicAdvanceRequest $request, RuntimeOptions $runtime)
70+
{
71+
// Step 0: init client
72+
$accessKeyId = $this->_credential->getAccessKeyId();
73+
$accessKeySecret = $this->_credential->getAccessKeySecret();
74+
$authConfig = new Config([
75+
'accessKeyId' => $accessKeyId,
76+
'accessKeySecret' => $accessKeySecret,
77+
'type' => 'access_key',
78+
'endpoint' => 'openplatform.aliyuncs.com',
79+
'protocol' => $this->_protocol,
80+
'regionId' => $this->_regionId,
81+
]);
82+
$authClient = new OpenPlatform($authConfig);
83+
$authRequest = new AuthorizeFileUploadRequest([
84+
'product' => 'ImageSearch',
85+
'regionId' => $this->_regionId,
86+
]);
87+
$authResponse = $authClient->authorizeFileUploadWithOptions($authRequest, $runtime);
88+
// Step 1: request OSS api to upload file
89+
$ossConfig = new \AlibabaCloud\SDK\OSS\OSS\Config([
90+
'accessKeyId' => $authResponse->accessKeyId,
91+
'accessKeySecret' => $accessKeySecret,
92+
'type' => 'access_key',
93+
'endpoint' => RpcUtils::getEndpoint($authResponse->endpoint, $authResponse->useAccelerate, $this->_endpointType),
94+
'protocol' => $this->_protocol,
95+
'regionId' => $this->_regionId,
96+
]);
97+
$ossClient = new OSS($ossConfig);
98+
$fileObj = new FileField([
99+
'filename' => $authResponse->objectKey,
100+
'content' => $request->picContentObject,
101+
'contentType' => '',
102+
]);
103+
$ossHeader = new header([
104+
'accessKeyId' => $authResponse->accessKeyId,
105+
'policy' => $authResponse->encodedPolicy,
106+
'signature' => $authResponse->signature,
107+
'key' => $authResponse->objectKey,
108+
'file' => $fileObj,
109+
'successActionStatus' => '201',
110+
]);
111+
$uploadRequest = new PostObjectRequest([
112+
'bucketName' => $authResponse->bucket,
113+
'header' => $ossHeader,
114+
]);
115+
$ossRuntime = new \AlibabaCloud\Tea\OSSUtils\OSSUtils\RuntimeOptions([]);
116+
RpcUtils::convert($runtime, $ossRuntime);
117+
$ossClient->postObject($uploadRequest, $ossRuntime);
118+
// Step 2: request final api
119+
$searchImageByPicreq = new SearchImageByPicRequest([]);
120+
RpcUtils::convert($request, $searchImageByPicreq);
121+
$searchImageByPicreq->picContent = 'http://' . $authResponse->bucket . '.' . $authResponse->endpoint . '/' . $authResponse->objectKey . '';
122+
123+
return $this->searchImageByPic($searchImageByPicreq, $runtime);
124+
}
125+
126+
/**
127+
* @throws \Exception
128+
*
129+
* @return DeleteImageResponse
130+
*/
131+
public function deleteImage(DeleteImageRequest $request, RuntimeOptions $runtime)
132+
{
133+
Utils::validateModel($request);
134+
135+
return DeleteImageResponse::fromMap($this->doRequest('DeleteImage', 'HTTPS', 'POST', '2020-02-12', 'AK', null, $request, $runtime));
136+
}
137+
138+
/**
139+
* @throws \Exception
140+
*
141+
* @return AddImageResponse
142+
*/
143+
public function addImage(AddImageRequest $request, RuntimeOptions $runtime)
144+
{
145+
Utils::validateModel($request);
146+
147+
return AddImageResponse::fromMap($this->doRequest('AddImage', 'HTTPS', 'POST', '2020-02-12', 'AK', null, $request, $runtime));
148+
}
149+
150+
/**
151+
* @throws \Exception
152+
*
153+
* @return AddImageResponse
154+
*/
155+
public function addImageAdvance(AddImageAdvanceRequest $request, RuntimeOptions $runtime)
156+
{
157+
// Step 0: init client
158+
$accessKeyId = $this->_credential->getAccessKeyId();
159+
$accessKeySecret = $this->_credential->getAccessKeySecret();
160+
$authConfig = new Config([
161+
'accessKeyId' => $accessKeyId,
162+
'accessKeySecret' => $accessKeySecret,
163+
'type' => 'access_key',
164+
'endpoint' => 'openplatform.aliyuncs.com',
165+
'protocol' => $this->_protocol,
166+
'regionId' => $this->_regionId,
167+
]);
168+
$authClient = new OpenPlatform($authConfig);
169+
$authRequest = new AuthorizeFileUploadRequest([
170+
'product' => 'ImageSearch',
171+
'regionId' => $this->_regionId,
172+
]);
173+
$authResponse = $authClient->authorizeFileUploadWithOptions($authRequest, $runtime);
174+
// Step 1: request OSS api to upload file
175+
$ossConfig = new \AlibabaCloud\SDK\OSS\OSS\Config([
176+
'accessKeyId' => $authResponse->accessKeyId,
177+
'accessKeySecret' => $accessKeySecret,
178+
'type' => 'access_key',
179+
'endpoint' => RpcUtils::getEndpoint($authResponse->endpoint, $authResponse->useAccelerate, $this->_endpointType),
180+
'protocol' => $this->_protocol,
181+
'regionId' => $this->_regionId,
182+
]);
183+
$ossClient = new OSS($ossConfig);
184+
$fileObj = new FileField([
185+
'filename' => $authResponse->objectKey,
186+
'content' => $request->picContentObject,
187+
'contentType' => '',
188+
]);
189+
$ossHeader = new header([
190+
'accessKeyId' => $authResponse->accessKeyId,
191+
'policy' => $authResponse->encodedPolicy,
192+
'signature' => $authResponse->signature,
193+
'key' => $authResponse->objectKey,
194+
'file' => $fileObj,
195+
'successActionStatus' => '201',
196+
]);
197+
$uploadRequest = new PostObjectRequest([
198+
'bucketName' => $authResponse->bucket,
199+
'header' => $ossHeader,
200+
]);
201+
$ossRuntime = new \AlibabaCloud\Tea\OSSUtils\OSSUtils\RuntimeOptions([]);
202+
RpcUtils::convert($runtime, $ossRuntime);
203+
$ossClient->postObject($uploadRequest, $ossRuntime);
204+
// Step 2: request final api
205+
$addImagereq = new AddImageRequest([]);
206+
RpcUtils::convert($request, $addImagereq);
207+
$addImagereq->picContent = 'http://' . $authResponse->bucket . '.' . $authResponse->endpoint . '/' . $authResponse->objectKey . '';
208+
209+
return $this->addImage($addImagereq, $runtime);
210+
}
211+
212+
/**
213+
* @param string $productId
214+
* @param string $regionId
215+
* @param string $endpointRule
216+
* @param string $network
217+
* @param string $suffix
218+
* @param array $endpointMap
219+
* @param string $endpoint
220+
*
221+
* @throws \Exception
222+
*
223+
* @return string
224+
*/
225+
public function getEndpoint($productId, $regionId, $endpointRule, $network, $suffix, $endpointMap, $endpoint)
226+
{
227+
if (!Utils::empty_($endpoint)) {
228+
return $endpoint;
229+
}
230+
if (!Utils::isUnset($endpointMap) && !Utils::empty_($endpointMap['regionId'])) {
231+
return $endpointMap['regionId'];
232+
}
233+
234+
return Endpoint::getEndpointRules($productId, $regionId, $endpointRule, $network, $suffix);
235+
}
236+
}

0 commit comments

Comments
 (0)