{{item}}
{{item.title}}
{{items.productName}}
{{items.price}}/年
{{item.title}}
部警SSL证书可实现网站HTTPS加密保护及身份的可信认证,防止传输数据的泄露或算改,提高网站可信度和品牌形象,利于SEO排名,为企业带来更多访问量,这也是网络安全法及PCI合规性的必备要求
前往SSL证书企业级HTTPS部署中,通过阿里云、腾讯云SSL证书API可实现证书全生命周期自动化管理。本文提炼API调用准备、两大平台核心流程、代码示例及问题排查,助力快速落地自动化方案。
遵循最小权限原则,配置SSL证书管理权限:
操作场景 | API接口名称 | 功能 | 调用方式 |
---|---|---|---|
申请免费证书 | CreateCertificate | 申请Let’s Encrypt证书 | POST |
查询证书列表 | DescribeCertificates | 按条件筛选证书 | GET |
下载证书 | DownloadCertificate | 按服务器类型下载证书包 | GET |
提交证书续期 | SubmitCertificateRenewal | 手动续期证书 | POST |
吊销证书 | RevokeCertificate | 吊销已签发证书 | POST |
(1)关键参数
参数 | 类型 | 示例值 | 说明 |
---|---|---|---|
Action | String | CreateCertificate | 接口名,固定值 |
Version | String | 2018-05-10 | 版本,固定值 |
RegionId | String | cn-hangzhou | 免费证书固定地域 |
CertificateType | String | FreeSSL | 证书类型,固定值 |
DomainName | String | www.example.com | 目标域名 |
ValidationMethod | String | DNS | 验证方式,推荐自动解析 |
AutoRenew | Boolean | true | 开启自动续期 |
(2)Python SDK 示例
from aliyunsdkcore.client import AcsClient
from aliyunsdkssl.request.v20180510 import CreateCertificateRequest
import json
# 初始化客户端
client = AcsClient("阿里云AK", "阿里云SK", "cn-hangzhou")
# 构建请求
request = CreateCertificateRequest.CreateCertificateRequest()
request.set_accept_format("json")
request.set_CertificateType("FreeSSL")
request.set_DomainName("www.example.com")
request.set_ValidationMethod("DNS")
request.set_AutoRenew(True)
# 发送请求
response = client.do_action_with_exception(request)
resp_dict = json.loads(response.decode("utf-8"))
print("证书ID:", resp_dict["CertId"]) # 后续操作需用
(3)响应关键字段
(1)关键参数
(2)Python SDK 示例
from aliyunsdkssl.request.v20180510 import DescribeCertificatesRequest
request = DescribeCertificatesRequest.DescribeCertificatesRequest()
request.set_accept_format("json")
request.set_CertId("123456789") # 传入CertId
response = client.do_action_with_exception(request)
resp_dict = json.loads(response.decode("utf-8"))
cert_info = resp_dict["Certificates"]["Certificate"][0]
print("状态:", cert_info["Status"], "有效期:", cert_info["StartTime"], "-", cert_info["EndTime"])
(1)关键参数
(2)Python SDK 示例
from aliyunsdkssl.request.v20180510 import DownloadCertificateRequest
import base64
request = DownloadCertificateRequest.DownloadCertificateRequest()
request.set_CertId("123456789")
request.set_Scene("Nginx")
response = client.do_action_with_exception(request)
resp_dict = json.loads(response.decode("utf-8"))
# 解码保存
fullchain = base64.b64decode(resp_dict["CertificateBody"]).decode("utf-8")
private_key = base64.b64decode(resp_dict["PrivateKey"]).decode("utf-8")
with open("fullchain.pem", "w") as f: f.write(fullchain)
with open("privkey.pem", "w") as f: f.write(private_key)
(1)关键参数:CertId、RenewalMethod=FreeSSL、ValidationMethod(同申请)。
操作场景 | API接口名称 | 功能 | 调用方式 |
---|---|---|---|
申请证书 | ApplyCertificate | 申请免费 / 付费证书 | POST |
查询证书列表 | DescribeCertificates | 按条件查询证书 | POST |
下载证书 | DownloadCertificate | 按服务器类型下载 | POST |
提交证书续期 | RenewCertificate | 手动续期 | POST |
(1)关键参数
参数 | 类型 | 示例值 | 说明 |
---|---|---|---|
Action | String | ApplyCertificate | 接口名,固定值 |
Version | String | 2019-12-05 | 版本,固定值 |
DomainName | String | www.example.com | 目标域名 |
CertificateType | String | 2 | 免费证书固定值 |
ValidateType | String | DNS | 验证方式 |
AutoRenewFlag | Integer | 1 | 1 = 开启自动续期 |
(2)Python SDK 示例
from tencentcloud.common import credential
from tencentcloud.common.profile import HttpProfile, ClientProfile
from tencentcloud.ssl.v20191205 import ssl_client, models
import json
# 初始化凭证与客户端
cred = credential.Credential("腾讯云AK", "腾讯云SK")
httpProfile = HttpProfile()
httpProfile.endpoint = "ssl.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = ssl_client.SslClient(cred, "", clientProfile)
# 构建请求
req = models.ApplyCertificateRequest()
params = {"DomainName":"www.example.com","CertificateType":2,"ValidateType":"DNS","AutoRenewFlag":1}
req.from_json_string(json.dumps(params))
# 发送请求
resp = client.ApplyCertificate(req)
resp_dict = json.loads(resp.to_json_string())
print("证书ID:", resp_dict["CertificateId"])
(1)关键参数
(2)Python SDK 示例
req = models.DescribeCertificatesRequest()
params = {"CertificateId":"abcdef123456"}
req.from_json_string(json.dumps(params))
resp = client.DescribeCertificates(req)
resp_dict = json.loads(resp.to_json_string())
cert_info = resp_dict["Certificates"][0]
print("状态:", cert_info["Status"], "有效期:", cert_info["StartTime"], "-", cert_info["EndTime"])
(1)关键参数
(2)Python SDK 示例
req = models.DownloadCertificateRequest()
params = {"CertificateId":"abcdef123456","ResourceType":"nginx"}
req.from_json_string(json.dumps(params))
resp = client.DownloadCertificate(req)
resp_dict = json.loads(resp.to_json_string())
# 保存证书(腾讯云返回证书内容,直接写入文件)
with open("cert.pem", "w") as f:
f.write(resp_dict["Content"]["Certificate"])
with open("key.pem", "w") as f:
f.write(resp_dict["Content"]["PrivateKey"])
问题现象 | 原因 | 解决方案 |
---|---|---|
签名错误 | AK/SK 错误或签名算法错 | 核对AK/SK,使用官方SDK |
权限不足 | 未配置SSL管理权限 | 关联对应平台的SSL权限策略 |
证书申请失败(验证超时) | DNS解析未生效 | 检查解析记录,等待生效后重试 |
下载证书为空 | 证书未签发(Status 非 Issued) | 确认证书状态为已签发后再下载 |
调用两大平台SSL证书API,需先完成权限、密钥、环境准备,再按 “申请 - 查询 - 下载 - 续期” 流程操作。优先使用官方SDK避免签名问题,定期监控证书状态,确保自动化管理合规高效。
Dogssl.com拥有20年网络安全服务经验,提供构涵盖国际CA机构Sectigo、Digicert、GeoTrust、GlobalSign,以及国内CA机构CFCA、沃通、vTrus、上海CA等数十个SSL证书品牌。全程技术支持及免费部署服务,如您有SSL证书需求,欢迎联系!