-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
80 lines (71 loc) · 2.74 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
use TencentCloud\Cdn\V20180606\CdnClient;
use TencentCloud\Cdn\V20180606\Models\DescribeDomainsConfigRequest;
use TencentCloud\Cdn\V20180606\Models\DomainFilter;
use TencentCloud\Cdn\V20180606\Models\ServerCert;
use TencentCloud\Cdn\V20180606\Models\UpdateDomainConfigRequest;
use TencentCloud\Common\Credential;
use TencentCloud\Ssl\V20191205\Models\UploadCertificateRequest;
use TencentCloud\Ssl\V20191205\Models\ModifyCertificatesExpiringNotificationSwitchRequest;
use TencentCloud\Ssl\V20191205\SslClient;
$config = require($conf);
set_error_handler(
function ($severity, $message, $file, $line) {
throw new ErrorException($message, $severity, $severity, $file, $line);
}
);
function init() {
global $config;
$config['cred'] = new Credential($config['Tencent']['SecretId'], $config['Tencent']["SecretKey"]);
}
function uploadCert(string $cert, string $key) {
global $config;
try {
$client = new SslClient($config['cred'], 'ap-shanghai');
$req = new UploadCertificateRequest();
$req->CertificatePublicKey = $cert;
$req->CertificatePrivateKey = $key;
$req->CertificateType = 'SVR';
$resp = $client->UploadCertificate($req);
return $resp->CertificateId;
} catch (Exception $e) {
throw $e;
}
}
function deployToCDN(string $domain, string $certId, array $parameters) {
global $config;
try {
$client = new CdnClient($config['cred'], 'ap-shanghai');
$query_req = new DescribeDomainsConfigRequest();
$filter = new DomainFilter();
$filter->Name = 'domain';
$filter->Value = [$domain];
$query_req->Filters = [$filter];
$query_resp = $client->DescribeDomainsConfig($query_req)->Domains[0];
if ($query_resp->Https->CertInfo && $query_resp->Https->CertInfo->CertId && ($parameters['disableExpireNotification'] ?? false)) {
disableExpireNotification($query_resp->Https->CertInfo->CertId);
}
$req = new UpdateDomainConfigRequest();
$req->Domain = $query_resp->Domain;
$req->Https = $query_resp->Https;
$cert = new ServerCert();
$cert->CertId = $certId;
$req->Https->CertInfo = $cert;
$req->Https->ClientCertInfo = null;
return $client->UpdateDomainConfig($req);
} catch (Exception $e) {
throw $e;
}
}
function disableExpireNotification(string $certId) {
global $config;
try {
$client = new SslClient($config['cred'], 'ap-shanghai');
$req = new ModifyCertificatesExpiringNotificationSwitchRequest();
$req->CertificateIds = [$certId];
$req->SwitchStatus = 1;
return $client->ModifyCertificatesExpiringNotificationSwitch($req);
} catch (Exception $e) {
throw $e;
}
}