需要 PHP 脚本返回 Python 脚本的精确匹配
请我需要帮助在 PHP 中获取此 python 脚本的准确 md5 值
Python 脚本
def md5code(params):
params = {'identifier': ' ', 'amount': '0.0', 'code': 'UNIA'}
req = dict([[key, params.get(key, '')] for key in ['code', 'identifier', 'amount']])
secret = '2fd0bba6b1774ed391c1ff8467f52a5d'
text = ":".join([req[x] for x in ['code', 'identifier', 'amount']] + secret)
return md5(text).hexdigest().upper()
返回值为: 5D316CD2311678A1B12F6152988F3097
PHP 脚本
$secret = '2fd0bba6b1774ed391c1ff8467f52a5d';
$code = 'UNIA';
$valid_institution = array('amount' => '0.0', 'code' => $code, 'identifier' => ' ');
foreach($valid_institution as $k => $v) {
$text = implode(":", $v[$k] + $secret);
}
print strtoupper(hash("md5", $text));
返回值为: D41D8CD98F00B204E9800998ECF8427E
我期望 PHP 脚本返回准确的 md5 值,但它是不是。
任何建议将不胜感激。
谢谢
Please I need help getting the exact md5 value of this python script in PHP
The Python script
def md5code(params):
params = {'identifier': ' ', 'amount': '0.0', 'code': 'UNIA'}
req = dict([[key, params.get(key, '')] for key in ['code', 'identifier', 'amount']])
secret = '2fd0bba6b1774ed391c1ff8467f52a5d'
text = ":".join([req[x] for x in ['code', 'identifier', 'amount']] + secret)
return md5(text).hexdigest().upper()
The return value is: 5D316CD2311678A1B12F6152988F3097
The PHP script
$secret = '2fd0bba6b1774ed391c1ff8467f52a5d';
$code = 'UNIA';
$valid_institution = array('amount' => '0.0', 'code' => $code, 'identifier' => ' ');
foreach($valid_institution as $k => $v) {
$text = implode(":", $v[$k] + $secret);
}
print strtoupper(hash("md5", $text));
The return value is: D41D8CD98F00B204E9800998ECF8427E
I'm expecting the PHP script to return an exact md5 value, but it is not.
Any suggestions will be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,看来您使用 foreach 的方式错误。试试这个:
ok, seems you're using foreach in a wrong way. Try this:
有效的 Python 代码可能如下所示:
这是等效的 PHP
Valid Python code could look like this:
and this is the equivalent PHP