f0d6cde5
xu
vendor
|
1
2
3
4
|
<?php
namespace AlibabaCloud\Client\Traits;
|
0c34aba8
xu
更新阿里云短信接口
|
5
|
use InvalidArgumentException;
|
f0d6cde5
xu
vendor
|
6
7
|
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Config\Config;
|
0c34aba8
xu
更新阿里云短信接口
|
8
|
use AlibabaCloud\Client\Request\Request;
|
f0d6cde5
xu
vendor
|
9
|
use AlibabaCloud\Client\Filter\ApiFilter;
|
f0d6cde5
xu
vendor
|
10
|
use AlibabaCloud\Client\Filter\HttpFilter;
|
0c34aba8
xu
更新阿里云短信接口
|
11
|
use AlibabaCloud\Client\Filter\ClientFilter;
|
f0d6cde5
xu
vendor
|
12
|
use AlibabaCloud\Client\Regions\LocationService;
|
0c34aba8
xu
更新阿里云短信接口
|
13
|
use AlibabaCloud\Client\Exception\ClientException;
|
f0d6cde5
xu
vendor
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
/**
* Help developers set up and get host.
*
* @package AlibabaCloud\Client\Traits
*
* @mixin AlibabaCloud
*/
trait EndpointTrait
{
/**
* @var array Host cache.
*/
private static $hosts = [];
/**
|
f0d6cde5
xu
vendor
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
* Resolve host based on product name and region.
*
* @param string $product
* @param string $regionId
*
* @return string
* @throws ClientException
*/
public static function resolveHost($product, $regionId = LocationService::GLOBAL_REGION)
{
ApiFilter::product($product);
ClientFilter::regionId($regionId);
if (isset(self::$hosts[$product][$regionId])) {
return self::$hosts[$product][$regionId];
}
$domain = Config::get("endpoints.{$product}.{$regionId}");
if (!$domain) {
$regionId = LocationService::GLOBAL_REGION;
$domain = Config::get("endpoints.{$product}.{$regionId}", '');
}
return $domain;
}
/**
|
f0d6cde5
xu
vendor
|
57
|
* @param string $product
|
0c34aba8
xu
更新阿里云短信接口
|
58
|
* @param string $regionId
|
f0d6cde5
xu
vendor
|
59
|
*
|
0c34aba8
xu
更新阿里云短信接口
|
60
|
* @return string
|
f0d6cde5
xu
vendor
|
61
|
*/
|
0c34aba8
xu
更新阿里云短信接口
|
62
|
public static function resolveHostByStatic($product, $regionId)
|
f0d6cde5
xu
vendor
|
63
|
{
|
0c34aba8
xu
更新阿里云短信接口
|
64
65
66
67
68
|
if (isset(self::$hosts[$product][$regionId])) {
return self::$hosts[$product][$regionId];
}
return '';
|
f0d6cde5
xu
vendor
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
}
/**
* Add host based on product name and region.
*
* @param string $product
* @param string $host
* @param string $regionId
*
* @return void
* @throws ClientException
*/
public static function addHost($product, $host, $regionId = LocationService::GLOBAL_REGION)
{
ApiFilter::product($product);
HttpFilter::host($host);
ClientFilter::regionId($regionId);
self::$hosts[$product][$regionId] = $host;
LocationService::addHost($product, $host, $regionId);
}
|
0c34aba8
xu
更新阿里云短信接口
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/**
* @param Request $request
*
* @return string
* @throws ClientException
*/
public static function resolveHostByRule(Request $request)
{
$regionId = $request->realRegionId();
$network = $request->network ?: 'public';
$suffix = $request->endpointSuffix;
if ($network === 'public') {
$network = '';
}
if ($request->endpointRegional === 'regional') {
return "{$request->product}{$suffix}{$network}.{$regionId}.aliyuncs.com";
}
if ($request->endpointRegional === 'central') {
return "{$request->product}{$suffix}{$network}.aliyuncs.com";
}
throw new InvalidArgumentException('endpointRegional is invalid.');
}
|
f0d6cde5
xu
vendor
|
119
|
}
|