我是PHP開發(fā)的新手我正在嘗試通過實(shí)施一些有趣的真實(shí)項(xiàng)目來學(xué)習(xí)。因此,我嘗試構(gòu)建一個(gè)比特幣應(yīng)用程序,讓客戶可以用加密貨幣付款。所以我從Coinbase商業(yè)API開始我成功實(shí)現(xiàn)了收費(fèi)頁面,并且一切正常,直到到達(dá)必須處理WEBHOOKS的地步?我正在關(guān)注本文檔https://github.com/coinbase/coinbase-commerce-php/blob/master/README.md這就是WEBHOOKs的代碼`<?phprequire_once __DIR__ . "/vendor/autoload.php";use CoinbaseCommerce\Webhook;/** * To run this example please read README.md file * Past your Webhook Secret Key from Settings/Webhook section * Make sure you don't store your Secret Key in your source code! */$secret = 'SECRET_KEY';$headerName = 'X-Cc-Webhook-Signature';$headers = getallheaders();$signraturHeader = isset($headers[$headerName]) ? $headers[$headerName] : null;$payload = trim(file_get_contents('php://input'));try { $event = Webhook::buildEvent($payload, $signraturHeader, $secret); http_response_code(200); echo sprintf('Successully verified event with id %s and type %s.', $event->id, $event->type);} catch (\Exception $exception) { http_response_code(400); echo 'Error occured. ' . $exception->getMessage();}`當(dāng)我訪問we hooks URL時(shí),出現(xiàn)此錯(cuò)誤Error occured. Invalid payload provided. No JSON object could be decoded請(qǐng)?我希望有人向我解釋此錯(cuò)誤
2 回答

三國紛爭
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊
似乎您正在向期望從Web掛鉤發(fā)出POST(具有有效載荷數(shù)據(jù))請(qǐng)求的URL發(fā)出GET(無有效載荷數(shù)據(jù))請(qǐng)求。
要使用POST,PUT,GET請(qǐng)求測(cè)試API,可以使用PostMan之類的工具。
您可以手動(dòng)構(gòu)建JSON負(fù)載并測(cè)試端點(diǎn)。

慕姐8265434
TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
試試這個(gè)
$headerName = 'x-cc-webhook-signature';
$signraturHeader = isset($headers[$headerName]) ? $headers[$headerName] : null;
代替
$headerName = 'X-Cc-Webhook-Signature';
$signraturHeader = isset($headers[$headerName]) ? $headers[$headerName] : null;
- 2 回答
- 0 關(guān)注
- 234 瀏覽
添加回答
舉報(bào)
0/150
提交
取消