【问题标题】:Clickbank IPN version 6 PHP / LaravelClickbank IPN 版本 6 PHP / Laravel
【发布时间】:2015-12-28 04:56:36
【问题描述】:

我正在尝试为 Clickbank 创建一个 IPN 侦听器,但到目前为止我还没有成功。

我使用了 clickbank 网站上列出的代码示例:https://support.clickbank.com/entries/22803622-Instant-Notification-Service

    <?php
// NOTE: the mcrypt libraries need to be installed and listed as an available extension in
// your phpinfo() to be able to use this method of decryption.
$secretKey = "YOUR SECRET KEY"; // secret key from your ClickBank account
 // get JSON from raw body...
$message = json_decode(file_get_contents('php://input'));
// Pull out the encrypted notification and the initialization vector for
// AES/CBC/PKCS5Padding decryption
$encrypted = $message->{'notification'};
$iv = $message->{'iv'};
error_log("IV: $iv");
// decrypt the body...
$decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,
                                 substr(sha1($secretKey), 0, 32),
                                 base64_decode($encrypted),
                                 MCRYPT_MODE_CBC,
                                 base64_decode($iv)), "\0..\32");
error_log("Decrypted: $decrypted");
// convert the decrypted string to a JSON object...
$order = json_decode($decrypted);
// Ready to rock and roll - If the decoding of the JSON string wasn't successful,
// then you can assume the notification wasn't encrypted with your secret key.
?>

对于 ipn v4,我设法为 ipn 测试器获得了经过验证的确认,并将输出保存在我的日志中。但是对于 v6,我什至无法将输出保存到日志文件中。似乎clickbank甚至没有发送任何东西。他们的文档含糊不清,我想知道这段代码是否应该首先工作。

有人有这方面的经验吗?我应该返回响应 200 以外的任何内容吗?

提前致谢。

【问题讨论】:

  • 您可以开票/发送电子邮件/给他们打电话。我知道在文档过期之前我已经这样做了。您也可以使用 403500 代替 200。
  • 感谢您的快速回复,我试过了,但他们说他们不提供对 api 实现的支持。有没有当时的示例代码?
  • 对不起,我没有。我从未处理过 Clickbank,但我处理过其他 API,这通常是我所做的。给他们打电话或发电子邮件。对不起,我帮不了你。
  • 谢谢安德鲁。我会调查的。
  • 科曼 - 你有没有想过解决这个问题。

标签: php laravel clickbank


【解决方案1】:

您可以做几件事情,这些事情与我的代码配合得很好。 (1) PHP 版本 - 如果您使用的是 PHP 7+,请尝试将其更改为 PHP 5.6 (2) 使用 $HTTP_RAW_POST_DATA 代替 file_get_contents (我知道 file_get_contents 更好,但是当它不起作用时使用替代)

这是要尝试的代码, $secretKey = "你的密钥";

// get JSON from raw body...
//$message = json_decode(file_get_contents('php://input'));

$message = $HTTP_RAW_POST_DATA;
$message = json_decode($message, true);
$messageString = http_build_query($message);    //converts associative array in to string
error_log("message string: $messageString");
$encrypted = $message['notification'];
$iv = $message['iv'];
error_log("IV: $iv");

// decrypt the body...
$decrypted = trim(openssl_decrypt(base64_decode($encrypted),'AES-256-CBC',substr(sha1($secretKey), 0, 32),OPENSSL_RAW_DATA, base64_decode($iv)), "\0..\32");

error_log("Decrypted: $decrypted");

////UTF8 Encoding, remove escape back slashes, and convert the decrypted string to a JSON object...
$sanitizedData = utf8_encode(stripslashes($decrypted));
$jsonDecodeData = json_decode($decrypted, true);
$jsonDecodeDataString = http_build_query($jsonDecodeData);

【讨论】:

    【解决方案2】:
    <?php
    
    function ipnVerification() {
        $secretKey="YOUR SECRET KEY";
        $pop = "";
        $ipnFields = array();
        foreach ($_POST as $key => $value) {
            if ($key == "cverify") {
                continue;
            }
            $ipnFields[] = $key;
        }
        sort($ipnFields);
        foreach ($ipnFields as $field) {
            // if Magic Quotes are enabled $_POST[$field] will need to be
            // un-escaped before being appended to $pop
            $pop = $pop . $_POST[$field] . "|";
        }
        $pop = $pop . $secretKey;
        $calcedVerify = sha1(mb_convert_encoding($pop, "UTF-8"));
        $calcedVerify = strtoupper(substr($calcedVerify,0,8));
        return $calcedVerify == $_POST["cverify"];
    }
    
    ?>
    

    您可以使用它来验证您的 IPN。它会很好用

    【讨论】:

      猜你喜欢
      • 2021-01-15
      • 2013-02-06
      • 2012-02-17
      • 2021-04-08
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      相关资源
      最近更新 更多