【发布时间】:2022-09-23 23:25:00
【问题描述】:
我正在尝试用 php 验证发送到我网站的回调。
请我尝试使用此 api 文档https://support.cryptapi.io/article/how-to-verify-the-callback-signature 来验证发送到我的网站的回调,但我的代码一直向 api 显示错误
我不知道它是否来自我的代码
<?php
$pubkey =
\"-----BEGIN PUBLIC KEY-----\\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3FT0Ym8b3myVxhQW7ESuuu6lo\\ndGAsUJs4fq+Ey//jm27jQ7HHHDmP1YJO7XE7Jf/0DTEJgcw4EZhJFVwsk6d3+4fy\\nBsn0tKeyGMiaE6cVkX0cy6Y85o8zgc/CwZKc0uw6d5siAo++xl2zl+RGMXCELQVE\\nox7pp208zTvown577wIDAQAB\\n-----END PUBLIC KEY-----\";
$signature = base64_decode($_SERVER[\'HTTP_X_CA_SIGNATURE\']);
$algo = OPENSSL_ALGO_SHA256;
// if request is GET
$data = \"https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]\";
// if request is POST
$data = file_get_contents(\'php://input\');
if (openssl_verify($data, $signature, $pubkey, $algo) == 1) {
require \"cryptapi.php\";
$url = $_GET[\'userdata\'];
$postdata = CryptAPI\\CryptAPI::process_callback($_GET);
$amount = $postdata[\'value_coin\'];
$txid_in = $postdata[\'txid_in\'];
$data = array(
\'amount\' => $amount,
\'txid_in\' => $txid_in
);
$payload = json_encode($data);
// Prepare new cURL resource
$ch = curl_init(urldecode($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
\'Content-Type: application/json\',
\'Content-Length: \' . strlen($payload))
);
// Submit the POST request
$result = curl_exec($ch);
// Close cURL session handle
curl_close($ch);
echo \"*ok*\";
} else {
echo \"error\";
// signature NOT valid
}
?>
-
它应该显示好的到那个api
-
究竟是什么错误?
-
它应该显示 echo ok 而不是错误
-
所以你是说
openssl_verify返回了假? -
我不太了解 openssl_verify
标签: php