From d035e5e206cda8bee19bbf9fa9ae45401b4ea516 Mon Sep 17 00:00:00 2001 From: 10295 <1029559041@qq.com> Date: Mon, 23 Apr 2018 01:30:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E4=BA=91=E7=9B=B8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PixivSearch/aliyun/photo/AliyunPhoto.py | 80 ++++++++++--------------- 1 file changed, 32 insertions(+), 48 deletions(-) diff --git a/PixivSearch/aliyun/photo/AliyunPhoto.py b/PixivSearch/aliyun/photo/AliyunPhoto.py index e5f053c..00df17d 100644 --- a/PixivSearch/aliyun/photo/AliyunPhoto.py +++ b/PixivSearch/aliyun/photo/AliyunPhoto.py @@ -5,7 +5,6 @@ import hashlib import hmac import os import random -import time from urllib import parse import requests @@ -26,54 +25,39 @@ def get_md5_01(file_path): def createTransaction(HTTPMethod, filePath): fileName = filePath.split('/')[-1] - for Version in getBetweenDay('2017-01-01'): - print("Version={Version}".format(Version=Version)) - param = { - "Format": "JSON", - "Version": Version, - "AccessKeyId": "LTAIeS8aBuPBZxV2", - "SignatureMethod": "HMAC-SHA1", - "Timestamp": int(time.time()), - "SignatureVersion": "1.0", - "SignatureNonce": random.randint(0, 9), - "Action": "CreateTransaction", - "Ext": fileName[-fileName[::-1].index('.'):], - "Md5": get_md5_01(filePath), - "Size": os.path.getsize(filePath) - } - AccessKeySecret = b'hyPeTaDQBQs6jetYcqY0BUdpacXTH3' - canonicalQueryString = '' - for i in sorted(param.items(), key=lambda d: d[0]): - canonicalQueryString += '&' + i[0] + parse.quote('=' + str(i[1])) - # print(canonicalQueryString[1:]) - - strUrlEncoding = HTTPMethod + '&%2F&' + canonicalQueryString[1:] - print(strUrlEncoding) - stringToSign = base64.b64encode(hmac.new(AccessKeySecret, strUrlEncoding.encode('UTF-8'), 'sha1').digest()) - - server = 'https://cloudphoto.cn-shanghai.aliyuncs.com' - url = server + "?" + canonicalQueryString[1:] + '&Signature=' + stringToSign.decode('utf-8').replace('+','%20').replace('/','%2F').replace('=','%3D') - print(url) - result = requests.get(url) - - if result.status_code == 200: - break - else: - print(result.content) - time.sleep(1) - - -def getBetweenDay(begin_date): - date_list = [] - begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d") - end_date = datetime.datetime.strptime(time.strftime('%Y-%m-%d', time.localtime(time.time())), "%Y-%m-%d") - while begin_date <= end_date: - date_str = begin_date.strftime("%Y-%m-%d") - date_list.append(date_str) - begin_date += datetime.timedelta(days=1) - return date_list + param = { + # "Format": "JSON", + "Version": '2017-07-11', + "AccessKeyId": "LTAIeS8aBuPBZxV2", + "SignatureMethod": "HMAC-SHA1", + "Timestamp": datetime.datetime.utcnow().isoformat()[:19] + 'Z', + "SignatureVersion": "1.0", + "SignatureNonce": '9166ab59-f445-' + str(random.randint(1000, 9999)) + '-911d-664c1570df0f', + "Action": "CreateTransaction" + # "Ext": fileName[-fileName[::-1].index('.'):], + # "Md5": get_md5_01(filePath), + # "Size": os.path.getsize(filePath) + } + AccessKeySecret = b'hyPeTaDQBQs6jetYcqY0BUdpacXTH3&' + canonicalQueryString = '' + + for i in sorted(param.items(), key=lambda d: d[0]): + canonicalQueryString += '&' + i[0] + '=' + str(i[1]) + print(canonicalQueryString[1:]) + + strUrlEncoding = HTTPMethod + '&%2F&' + parse.quote(canonicalQueryString[1:]) + print(strUrlEncoding) + stringToSign = base64.b64encode(hmac.new(AccessKeySecret, strUrlEncoding.encode('UTF-8'), 'sha1').digest()) + print(stringToSign) + server = 'https://cloudphoto.cn-shanghai.aliyuncs.com' + url = server + "?" + canonicalQueryString[1:] + '&Signature=' + parse.quote(stringToSign.decode('utf-8')).replace( + '/', '%2F') + print(url) + result = requests.get(url) + + print(result.content) if __name__ == '__main__': createTransaction("GET", "C:/Users/10295/Desktop/灵梦.png") - # print(getBetweenDay('2017-01-01')) + # print(datetime.datetime.utcnow())