近日,由于需要同步阿里资产费用信息,但是阿里目前只提供了相关接口,并无相关SDK给出,所以需要自行拼接相关参数,其中签名信息获取较为复杂,特此记录一下。
具体签名机制相关文档如下:
https://help.aliyun.com/document_detail/87971.html?spm=a2c4g.11174283.6.550.2b515467Fwv4EK
# coding=utf8
import time
import uuid
import urllib
import sys
import hashlib
import hmac
import base64
FORMAT_ISO_8601 = "%Y-%m-%dT%H:%M:%SZ"
# 获取请求时间戳
def get_Timestamp():
return time.strftime(FORMAT_ISO_8601, time.gmtime())
# 获取唯一随机数,防止网络攻击
def get_SignatureNonce():
return str(uuid.uuid4())
# 拼接参数字典
def get_all_parameters(accessKeyId,billingCycle,pageNumber,pageSize):
parameters = {
"Format": "JSON",
"Version": "2017-12-14",
"AccessKeyId": accessKeyId,