Skip to content

Commit 2d4eb75

Browse files
committed
update 2.0.0
1 parent 1f2c39f commit 2d4eb75

File tree

3 files changed

+61
-262
lines changed

3 files changed

+61
-262
lines changed

Client.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ public function init()
7676
if ($this->secretKey === null) {
7777
throw new InvalidConfigException('The "secretKey" property must be set.');
7878
}
79-
if ($this->region === null) {
80-
throw new InvalidConfigException('The "region" property must be set.');
81-
}
8279
$this->baseUrl = ($this->secureConnection ? 'https://' : 'http://') . $this->serverHost . $this->serverUri;
8380
$this->responseConfig['format'] = \yii\httpclient\Client::FORMAT_JSON;
8481
$this->on(Client::EVENT_BEFORE_SEND, [$this, 'RequestEvent']);
@@ -92,7 +89,7 @@ public function init()
9289
public function RequestEvent(RequestEvent $event)
9390
{
9491
$params = $event->request->getData();
95-
if (!isset($params['Region'])) {
92+
if (!isset($params['Region']) && !empty($this->region)) {
9693
$params['Region'] = $this->region;
9794
}
9895
if (!isset($params['SecretId'])) {

Qcloud.php renamed to QCloud.php

Lines changed: 60 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,75 @@
44
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd.
55
* @license http://www.tintsoft.com/license/
66
*/
7+
78
namespace xutl\qcloud;
89

910
use yii\base\Component;
1011
use yii\base\InvalidConfigException;
1112

1213
/**
13-
* Class Qcloud
14+
* Class QCloud
1415
* @package xutl\qcloud
1516
*/
16-
class Qcloud extends Component
17+
class QCloud extends Component
1718
{
19+
/**
20+
* @var string
21+
*/
22+
public $secretId;
23+
24+
/**
25+
* @var string
26+
*/
27+
public $secretKey;
28+
29+
/**
30+
* @var bool 是否使用安全连接
31+
*/
32+
public $secureConnection = true;
33+
34+
/**
35+
* 请求的Uri
36+
* @var string
37+
*/
38+
public $serverUri = '/v2/index.php';
39+
40+
public $defaultRegion = null;
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function init()
46+
{
47+
parent::init();
48+
if ($this->secretId === null) {
49+
throw new InvalidConfigException('The "secretId" property must be set.');
50+
}
51+
if ($this->secretKey === null) {
52+
throw new InvalidConfigException('The "secretKey" property must be set.');
53+
}
54+
}
55+
56+
/**
57+
* 创建API请求
58+
* @param string $service 服务名称
59+
* @param string|null $region 区域名称
60+
* @return \yii\httpclient\Request
61+
*/
62+
public function createRequest($service, $region = null)
63+
{
64+
$serverHost = $service . '.api.qcloud.com';
65+
return (new Client([
66+
'serverHost' => $serverHost,
67+
'secretId' => $this->secretId,
68+
'secretKey' => $this->secretKey,
69+
'secureConnection' => $this->secureConnection,
70+
'serverUri' => $this->serverUri,
71+
'region' => $region ? $region : $this->defaultRegion
72+
]))->createRequest()->setMethod('POST');
73+
}
74+
75+
1876
/**
1977
* 用户账户
2078
*/
@@ -134,100 +192,4 @@ class Qcloud extends Component
134192
* 云搜
135193
*/
136194
const API_YUNSOU = 'yunsou';
137-
138-
/**
139-
* @var string
140-
*/
141-
public $secretId;
142-
143-
/**
144-
* @var string
145-
*/
146-
public $secretKey;
147-
148-
/**
149-
* 请求的Uri
150-
* @var string
151-
*/
152-
public $serverUri = '/v2/index.php';
153-
154-
/**
155-
* 请求方法
156-
* @var string
157-
*/
158-
public $requestMethod = "POST";
159-
160-
/**
161-
* 服务器地址
162-
* @var array
163-
*/
164-
protected $_serverHosts = [
165-
'account' => 'account.api.qcloud.com',
166-
'bill' => 'bill.api.qcloud.com',
167-
'bm' => 'bm.api.qcloud.com',
168-
'cbs' => 'cbs.api.qcloud.com',
169-
'cdb' => 'cdb.api.qcloud.com',
170-
'cdn' => 'cdn.api.qcloud.com',
171-
'cmem' => 'cmem.api.qcloud.com',
172-
'cns' => 'cns.api.qcloud.com',
173-
'cvm' => 'cvm.api.qcloud.com',
174-
'eip' => 'eip.api.qcloud.com',
175-
'image' => 'image.api.qcloud.com',
176-
'lb' => 'lb.api.qcloud.com',
177-
'live' => 'live.api.qcloud.com',
178-
'market' => 'market.api.qcloud.com',
179-
'monitor' => 'monitor.api.qcloud.com',
180-
'scaling' => 'scaling.api.qcloud.com',
181-
'sec' => 'csec.api.qcloud.com',
182-
'snapshot' => 'snapshot.api.qcloud.com',
183-
'tdsql' => 'tdsql.api.qcloud.com',
184-
'trade' => 'trade.api.qcloud.com',
185-
'vod' => 'vod.api.qcloud.com',
186-
'vpc' => 'vpc.api.qcloud.com',
187-
'wenzhi' => 'wenzhi.api.qcloud.com',
188-
'yunsou' => 'yunsou.api.qcloud.com',
189-
];
190-
191-
/**
192-
* @inheritdoc
193-
*/
194-
public function init()
195-
{
196-
parent::init();
197-
if ($this->secretId === null) {
198-
throw new InvalidConfigException('The "secretId" property must be set.');
199-
}
200-
if ($this->secretKey === null) {
201-
throw new InvalidConfigException('The "secretKey" property must be set.');
202-
}
203-
}
204-
205-
/**
206-
* 获取服务器主机名
207-
* @param string $service
208-
* @return mixed|null
209-
*/
210-
protected function getServerHost($service)
211-
{
212-
return isset($this->_serverHosts[$service]) ? $this->_serverHosts[$service] : null;
213-
}
214-
215-
/**
216-
* 创建API请求
217-
* @param string $service 服务名称
218-
* @param string|null $region 区域名称
219-
* @return Request
220-
*/
221-
public function createRequest($service, $region = null)
222-
{
223-
$serverHost = $this->getServerHost($service);
224-
return new Request([
225-
'secretId' => $this->secretId,
226-
'secretKey' => $this->secretKey,
227-
'defaultRegion' => $region,
228-
'requestMethod' => $this->requestMethod,
229-
'serverUri' => $this->serverUri,
230-
'serverHost' => $serverHost
231-
]);
232-
}
233195
}

Request.php

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)