php-HP-cloud为FormPOST-python-to-php翻译创建签名

2024-03-28 16:14:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在试用HP云对象存储API,但它们的所有示例都是用Python编写的,我正在用PHP编写。 我的签名是无效的,如果有人能帮我看出哪里出错了,我已经附上了python示例https://docs.hpcloud.com/api/object-storage/#formpost以及我在PHP中的尝试。你知道吗

import hmac
from hashlib import sha1
from time import time

path = '/v1/12345678912345/container/object_prefix'
redirect = 'https://myserver.com/some-page'
max_file_size = 104857600
max_file_count = 10
expires = int(time() + 600)
tenant_id = '12345678912345'
access_key_id = 'GP54NNRN2TKBVWH449AG'
secret_key = 'EHLzysK9S1QRWkwvVpVHsGZyM715OH4S2kJ'
hmac_body = '%s\n%s\n%s\n%s\n%s' % (path, redirect,
max_file_size, max_file_count, expires)
signature = tenant_id + ':' + access_key_id + ':' + hmac.new(secret_key, hmac_body, sha1).hexdigest()

这是我的尝试。。。你知道吗

<?php
$expires = time()+600;
$hmac_body = 'https://region-a.geo-1.objects.hpcloudsvc.com/v1/xxx/'.'http://www.test.com/test.php'.'41943040'.'1'.$expires;
$signature = 'tenant_id:access_key:'.hash_hmac(sha1,$hmac_body,'secret_key', FALSE);
?>
<form action="<?php echo 'https://region-a.geo-1.objects.hpcloudsvc.com/v1/xxx/';?>" method="POST" enctype="multipart/form-data">
 <input type="hidden" name="redirect" value="http://www.test.com/test.php" />
<input type="hidden" name="max_file_size" value="41943040" />
<input type="hidden" name="max_file_count" value="1" />
<input type="hidden" name="expires" value="<?php echo $expires;?>" />
<input type="hidden" name="signature" value="<?php echo $signature;?>" />
<input type="file" name="testupload" />
<input type="submit" />
</form>

如果有人能提供一个从python到PHP的hmacèu体和签名的翻译,我相信这会非常有帮助。你知道吗


Tags: keynamehttpscomidinputtimevalue
1条回答
网友
1楼 · 发布于 2024-03-28 16:14:39

你忘了新台词:

mac_body = '%s\n%s\n%s\n%s\n%s' % (path, redirect,
              ^^ ^^ ^^ ^^  newlines

$hmac_body = 'https://blahblah/xxx/'.'http://blahblah/test.php'.'41943040'.'1'.$expires;
                                    ^ here                    ^ here   etc....

相关问题 更多 >