f0d6cde5
xu
vendor
|
1
2
3
4
|
<?php
namespace AlibabaCloud\Client\Request;
|
0c34aba8
xu
更新阿里云短信接口
|
5
6
7
8
|
use Exception;
use RuntimeException;
use AlibabaCloud\Client\Support\Sign;
use AlibabaCloud\Client\Support\Arrays;
|
f0d6cde5
xu
vendor
|
9
10
|
use AlibabaCloud\Client\Credentials\StsCredential;
use AlibabaCloud\Client\Exception\ClientException;
|
0c34aba8
xu
更新阿里云短信接口
|
11
12
|
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Client\Credentials\BearerTokenCredential;
|
f0d6cde5
xu
vendor
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
/**
* RESTful RPC Request.
*
* @package AlibabaCloud\Client\Request
*/
class RpcRequest extends Request
{
/**
* @var string
*/
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
/**
* Resolve request parameter.
*
|
f0d6cde5
xu
vendor
|
30
31
|
* @throws ClientException
*/
|
0c34aba8
xu
更新阿里云短信接口
|
32
|
public function resolveParameter()
|
f0d6cde5
xu
vendor
|
33
|
{
|
0c34aba8
xu
更新阿里云短信接口
|
34
35
36
|
$this->resolveBoolInParameters();
$this->resolveCommonParameters();
$this->repositionParameters();
|
f0d6cde5
xu
vendor
|
37
38
39
|
}
/**
|
0c34aba8
xu
更新阿里云短信接口
|
40
|
* Convert a Boolean value to a string
|
f0d6cde5
xu
vendor
|
41
|
*/
|
0c34aba8
xu
更新阿里云短信接口
|
42
|
private function resolveBoolInParameters()
|
f0d6cde5
xu
vendor
|
43
44
|
{
if (isset($this->options['query'])) {
|
0c34aba8
xu
更新阿里云短信接口
|
45
46
47
48
49
50
|
$this->options['query'] = array_map(
static function ($value) {
return self::boolToString($value);
},
$this->options['query']
);
|
f0d6cde5
xu
vendor
|
51
|
}
|
f0d6cde5
xu
vendor
|
52
53
54
55
56
57
58
59
60
|
}
/**
* Convert a Boolean value to a string.
*
* @param bool|string $value
*
* @return string
*/
|
0c34aba8
xu
更新阿里云短信接口
|
61
|
public static function boolToString($value)
|
f0d6cde5
xu
vendor
|
62
63
|
{
if (is_bool($value)) {
|
0c34aba8
xu
更新阿里云短信接口
|
64
|
return $value ? 'true' : 'false';
|
f0d6cde5
xu
vendor
|
65
66
67
68
69
70
|
}
return $value;
}
/**
|
0c34aba8
xu
更新阿里云短信接口
|
71
72
73
74
|
* Resolve Common Parameters.
*
* @throws ClientException
* @throws Exception
|
f0d6cde5
xu
vendor
|
75
|
*/
|
0c34aba8
xu
更新阿里云短信接口
|
76
|
private function resolveCommonParameters()
|
f0d6cde5
xu
vendor
|
77
|
{
|
0c34aba8
xu
更新阿里云短信接口
|
78
79
80
81
82
83
84
85
86
87
|
$signature = $this->httpClient()->getSignature();
$this->options['query']['RegionId'] = $this->realRegionId();
$this->options['query']['Format'] = $this->format;
$this->options['query']['SignatureMethod'] = $signature->getMethod();
$this->options['query']['SignatureVersion'] = $signature->getVersion();
$this->options['query']['SignatureNonce'] = Sign::uuid($this->product . $this->realRegionId());
$this->options['query']['Timestamp'] = gmdate($this->dateTimeFormat);
$this->options['query']['Action'] = $this->action;
if ($this->credential()->getAccessKeyId()) {
$this->options['query']['AccessKeyId'] = $this->credential()->getAccessKeyId();
|
f0d6cde5
xu
vendor
|
88
|
}
|
0c34aba8
xu
更新阿里云短信接口
|
89
90
91
92
93
94
95
96
97
|
if ($signature->getType()) {
$this->options['query']['SignatureType'] = $signature->getType();
}
if (!isset($this->options['query']['Version'])) {
$this->options['query']['Version'] = $this->version;
}
$this->resolveSecurityToken();
$this->resolveBearerToken();
$this->options['query']['Signature'] = $this->signature();
|
f0d6cde5
xu
vendor
|
98
99
100
|
}
/**
|
0c34aba8
xu
更新阿里云短信接口
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
* @throws ClientException
* @throws ServerException
*/
private function resolveSecurityToken()
{
if (!$this->credential() instanceof StsCredential) {
return;
}
if (!$this->credential()->getSecurityToken()) {
return;
}
$this->options['query']['SecurityToken'] = $this->credential()->getSecurityToken();
}
/**
* @throws ClientException
* @throws ServerException
|
f0d6cde5
xu
vendor
|
120
|
*/
|
0c34aba8
xu
更新阿里云短信接口
|
121
|
private function resolveBearerToken()
|
f0d6cde5
xu
vendor
|
122
|
{
|
0c34aba8
xu
更新阿里云短信接口
|
123
124
|
if ($this->credential() instanceof BearerTokenCredential) {
$this->options['query']['BearerToken'] = $this->credential()->getBearerToken();
|
f0d6cde5
xu
vendor
|
125
126
127
128
129
130
|
}
}
/**
* Sign the parameters.
*
|
f0d6cde5
xu
vendor
|
131
132
|
* @return mixed
* @throws ClientException
|
0c34aba8
xu
更新阿里云短信接口
|
133
|
* @throws ServerException
|
f0d6cde5
xu
vendor
|
134
|
*/
|
0c34aba8
xu
更新阿里云短信接口
|
135
|
private function signature()
|
f0d6cde5
xu
vendor
|
136
|
{
|
f0d6cde5
xu
vendor
|
137
138
|
return $this->httpClient()
->getSignature()
|
0c34aba8
xu
更新阿里云短信接口
|
139
140
141
142
|
->sign(
$this->stringToSign(),
$this->credential()->getAccessKeySecret() . '&'
);
|
f0d6cde5
xu
vendor
|
143
144
145
|
}
/**
|
0c34aba8
xu
更新阿里云短信接口
|
146
|
* @return string
|
f0d6cde5
xu
vendor
|
147
|
*/
|
0c34aba8
xu
更新阿里云短信接口
|
148
|
public function stringToSign()
|
f0d6cde5
xu
vendor
|
149
|
{
|
0c34aba8
xu
更新阿里云短信接口
|
150
151
152
153
154
155
|
$query = isset($this->options['query']) ? $this->options['query'] : [];
$form_params = isset($this->options['form_params']) ? $this->options['form_params'] : [];
$parameters = Arrays::merge([$query, $form_params]);
return Sign::rpcString($this->method, $parameters);
}
|
f0d6cde5
xu
vendor
|
156
|
|
0c34aba8
xu
更新阿里云短信接口
|
157
158
159
160
161
162
163
164
165
166
167
|
/**
* Adjust parameter position
*/
private function repositionParameters()
{
if ($this->method === 'POST' || $this->method === 'PUT') {
foreach ($this->options['query'] as $api_key => $api_value) {
$this->options['form_params'][$api_key] = $api_value;
}
unset($this->options['query']);
}
|
f0d6cde5
xu
vendor
|
168
169
170
171
172
173
174
175
176
177
178
179
|
}
/**
* Magic method for set or get request parameters.
*
* @param string $name
* @param mixed $arguments
*
* @return $this
*/
public function __call($name, $arguments)
{
|
0c34aba8
xu
更新阿里云短信接口
|
180
181
|
if (strncmp($name, 'get', 3) === 0) {
$parameter_name = \mb_strcut($name, 3);
|
f0d6cde5
xu
vendor
|
182
|
|
0c34aba8
xu
更新阿里云短信接口
|
183
|
return $this->__get($parameter_name);
|
f0d6cde5
xu
vendor
|
184
185
|
}
|
0c34aba8
xu
更新阿里云短信接口
|
186
187
188
189
|
if (strncmp($name, 'with', 4) === 0) {
$parameter_name = \mb_strcut($name, 4);
$this->__set($parameter_name, $arguments[0]);
$this->options['query'][$parameter_name] = $arguments[0];
|
f0d6cde5
xu
vendor
|
190
191
192
193
|
return $this;
}
|
0c34aba8
xu
更新阿里云短信接口
|
194
195
196
|
if (strncmp($name, 'set', 3) === 0) {
$parameter_name = \mb_strcut($name, 3);
$with_method = "with$parameter_name";
|
f0d6cde5
xu
vendor
|
197
|
|
0c34aba8
xu
更新阿里云短信接口
|
198
|
throw new RuntimeException("Please use $with_method instead of $name");
|
f0d6cde5
xu
vendor
|
199
200
201
202
203
|
}
throw new RuntimeException('Call to undefined method ' . __CLASS__ . '::' . $name . '()');
}
}
|