无法验证网络钩子签名 PHP



我正在尝试验证来自如下webhook的签名:

require_once('vendor/autoload.php');
use PayPalApiVerifyWebhookSignature;
use PayPalApiWebhookEvent;
use PayPalApiVerifyWebhookSignatureResponse;
$apiContext = require __DIR__ . '/bootstrap.php';
$bodyReceivedJson = file_get_contents('php://input');
$bodyDecoded = json_decode($requestBodyJson, true);
$headers = getallheaders();
$headers = array_change_key_case($headers, CASE_UPPER);
$signatureVerification = new VerifyWebhookSignature();
$signatureVerification->setAuthAlgo($headers['PAYPAL-AUTH-ALGO']);
$signatureVerification->setTransmissionId($headers['PAYPAL-TRANSMISSION-ID']);
$signatureVerification->setCertUrl($headers['PAYPAL-CERT-URL']);
$signatureVerification->setWebhookId("55555555555555555");
$signatureVerification->setTransmissionSig($headers['PAYPAL-TRANSMISSION-SIG']);
$signatureVerification->setTransmissionTime($headers['PAYPAL-TRANSMISSION-TIME']);
$signatureVerification->setRequestBody($bodyReceivedJson);
$request = clone $signatureVerification;
try{
$output = $signatureVerification->post($apiContext);
}
catch (Exception $ex){
exit(1);
}

但我得到了这个错误:

[26-Oct-2019 20:18:16 UTC] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to PayPalTransportPayPalRestCall::__construct() must be an instance of PayPalRestApiContext, int given, called in C:vendorpaypalrest-api-sdk-phplibPayPalCommonPayPalResourceModel.php on line 101 and defined in C:vendorpaypalrest-api-sdk-phplibPayPalTransportPayPalRestCall.php:38
Stack trace:
#0 C:vendorpaypalrest-api-sdk-phplibPayPalCommonPayPalResourceModel.php(101): PayPalTransportPayPalRestCall->__construct(1)
#1 C:vendorpaypalrest-api-sdk-phplibPayPalApiVerifyWebhookSignature.php(225): PayPalCommonPayPalResourceModel::executeCall('/v1/notificatio...', 'POST', '{"auth_algo": "...', NULL, 1, NULL)
#2 C:listener.php(33): PayPalApiVerifyWebhookSignature->post(1)
#3 {main}
thrown in C:vendorpaypalrest-api-sdk-phplibPayPalTransportPayPalRestCall.php on line 38

我不知道这个错误是想告诉我什么。

$request(修改的id和我不确定是否应该共享的东西(:

{"auth_algo": "SHA256withRSA","transmission_id": "ff0e44a0-f82e-11e9-93f0-f3e5d7c6e89f","cert_url": "https://api.paypal.com/v1/notifications/certs/CERT-360caa44-fsa5a584-5edf0ebc","webhook_id": "55555555555555555","transmission_sig": "Xcc1HHjcjCDZ/EU7oHDQdH/OFCshmbZB1hEHwHSyYUKFBWLkwOgFRhfsnYco10lLZ/oEexycET2pI4c0wpqA7M3UXHUSNxTp8FTeKjSaBqKsCW36hh3fhxhhhghI3CdjhhFZzB06kEzhryVgZpUqyqSz/NihlChhDGiShLfMh4P5hhhhhfeR47GGb5LZlHIlP7C2s9UE8h8heXhh9m/vflhgUDh/EhE/hmQ6+eMsh8oHAhsV8pLCBhkUKTF8tMoPjCVDMhFdFd2Hg5m8MIwbgEzGEYiAPKxkZd3YWXBP1XOgR2MDh6cUidhhC8olh1h6wh5lh3U6hoh4hI1hSezdhQ==","transmission_time": "2019-10-26T20:27:14Z","webhook_event": {"id":"WH-2WR55555HC02533534-65976315F54553755","event_version":"1.0","create_time":"2014-10-23T17:23:52Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"A successful sale payment was made for $ 0.48 USD","resource":{"id":"5555555555555","create_time":"2014-10-23T17:22:56Z","update_time":"2014-10-23T17:23:04Z","amount":{"total":"0.48","currency":"USD"},"payment_mode":"ECHECK","state":"completed","protection_eligibility":"ELIGIBLE","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","clearing_time":"2014-10-30T07:00:00Z","parent_payment":"PAY-1PA52105FU58455KRE5S4AH","links":[{"href":"https://api.paypal.com/v1/payments/sale/80021663DE681814L","rel":"self","method":"GET"},{"href":"https://api.paypal.com/v1/payments/sale/80021663DE681814L/refund","rel":"refund","method":"POST"},{"href":"https://api.paypal.com/v1/payments/payment/PAY-1PA52105FU58455KRE5S4AH","rel":"parent_payment","method":"GET"}]},"links":[{"href":"https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR55555HC02533534-65976315F54553755","rel":"self","method":"GET"},{"href":"https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR55555HC02533534-65976315F54553755/resend","rel":"resend","method":"POST"}]}}

事实证明:

$apiContext = require __DIR__ . '/bootstrap.php';

实际上并没有得到它需要的东西,那就是:

$apiContext  = new PayPalRestApiContext(
new PayPalAuthOAuthTokenCredential(
'YOUR APPLICATION CLIENT ID',
'YOUR APPLICATION CLIENT SECRET'
)
);

最新更新