<code>import base64 import hmac import urllib from hashlib import sha256 string_to_sign = 'GET\n/iaas/\naccess_key_id=QYACCESSKEYIDEXAMPLE&action=RunInstances&count=1&image_id=centos64x86a&instance_name=demo&instance_type=small_b&login_mode=passwd&login_passwd=QingCloud20130712&signature_method=HmacSHA256&signature_version=1&time_stamp=2013-08-27T14%3A30%3A10Z&version=1&vxnets.1=vxnet-0&zone=pek1' h = hmac.new(secret_access_key, digestmod=sha256) h.update(string_to_sign) sign = base64.b64encode(h.digest()).strip() signature = urllib.quote_plus(sign) </code>
感谢!
我有一个python写的签名算法,能否转成php的呢?
<code>import base64 import hmac import urllib from hashlib import sha256 string_to_sign = 'GET\n/iaas/\naccess_key_id=QYACCESSKEYIDEXAMPLE&action=RunInstances&count=1&image_id=centos64x86a&instance_name=demo&instance_type=small_b&login_mode=passwd&login_passwd=QingCloud20130712&signature_method=HmacSHA256&signature_version=1&time_stamp=2013-08-27T14%3A30%3A10Z&version=1&vxnets.1=vxnet-0&zone=pek1' h = hmac.new(secret_access_key, digestmod=sha256) h.update(string_to_sign) sign = base64.b64encode(h.digest()).strip() signature = urllib.quote_plus(sign) </code>
感谢!
http://php.net/manual/en/function.hash-hmac.php
http://php.net/manual/en/function.base64-encode.php
http://php.net/manual/en/function.urlencode.php
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号