我的 PHP 代码
<?php
$xml="<request>
<point_of_sale_id>XXXXXXX</point_of_sale_id>
<order_id>XXXXXXX</order_id>
<amount>XXXXXXX</amount>
<description>XXXXXXX
</description>
<result_url>XXXXXXX</result_url>
<server_url>XXXXXXX</server_url>
</request>";
$parameters_xml=base64_encode($xml);
$merchant_secret_code='XXXXXXX';
$signature=base64_encode(sha1($xml.$merchant_secret_code,1));
echo "<form action=\"https://www.i-koruna.com/i-koruna/api/payment/payment-entry-point.jsf\"\n";
echo "method=\"POST\" accept-charset=\"utf-8\">\n";
echo "<input type=\"hidden\" name=\"api_version\" value=\"v2\" />\n";
echo "<input type=\"hidden\" name=\"parameters_xml\" value=\"$parameters_xml\" /> \n";
echo "<input type=\"hidden\" name=\"signature\" value=\"$signature\" />\n";
echo "<input type=\"hidden\" name=\"locale\" value=\"en\" />\n";
echo "<input type=\"submit\" value=\"Buy\" />\n";
echo "</form> \n";
?>
此代码正在工作,但在 perl 中相同的复制
Perl 代码
use MIME::Base64;
use Digest::SHA qw(sha1);
my $parameters_xml = encode_base64("<request><point_of_sale_id>".$c->{ikoruna_pos}."</point_of_sale_id><order_id>$id</order_id><amount>".$f->{amount}."</amount><description>".$c->{item_name}."</description><result_url>$c->{site_url}/?payment_complete=$id-$usr_id</result_url><server_url>$c->{site_url}/?payment_complete=$id-$usr_id</server_url></request>");
$parameters_xml =~ s/\s+//g;
my $merchant = 'XXXXXXXXXXXXX';
my $signature=encode_base64(sha1($parameters_xml.$merchant), '');
print "Content-type:text/html\n\n";
print <<END
<form action="https://www.i-koruna.com/i-koruna/api/payment/payment-entry-point.jsf" method="POST" accept-charset="utf-8">
<input type="hidden" name="api_version" value="v2" />
<input type="hidden" name="parameters_xml" value="$parameters_xml" />
<input type="hidden" name="signature" value="$signature" />
<input type="hidden" name="locale" value="en" />
<input type="submit" value="Buy" />
</form>
END
我在打包 $signature 时检查了这是一个问题,我这样做是否正确?如果我错过了一些我可以做到的不是问题的东西,请忽略 HTML 部分
我从商家“无效的商家签名”处收到此错误