提问人:Sachin 提问时间:7/27/2022 更新时间:7/27/2022 访问量:465
如何从 PHP 获取 Curl 响应的 Header 和 data-raw
How to get Header & data-raw Of Curl Response from PHP
问:
使用第三方服务;他们提供 webhook 服务;我已经给出了我的网址来在我的页面上发送响应: 示例:https://abcd.com/postback.php
在回发 .php 上获取卷曲响应;读取开机自检数据;我正在使用以下代码:
$postdata = file_get_contents("php://input");
但无法读取标题和数据内容。
他们发送的示例响应:
curl -L -X POST 'https://abcd.com/postback.php' -H 'x-changenow-signature: xcgh123POPI6727kslsldjsd' -H 'Content-Type: application/json' --data-raw '{"status":"finished","payinHash":"31mrEanXyv","payoutHash":"485d8dz","payinAddress":"3Nups0bF","payoutAddress":"1K1LcQSPZVj2dM","fromCurrency":"sol","toCurrency":"btc","amountSend":0.06676453,"amountReceive":0.00010273,"refundAddress":"Bk1qVzc3GULcJQ0NoW4DsepRJHevzAD8ynznEQ1aNzGq","id":"f7bed8a9e4a350","updatedAt":"2022-06-23T11:22:38.728Z","createdAt":"2022-06-23T11:09:56.403Z","expectedReceiveAmount":0.0001024,"isPartner":false}
请建议如何获取标题和数据部分。
答:
0赞
Barmar
7/27/2022
#1
标头位于 中。用于获取标头。$_SERVER
$_SERVER['HTTP_X_CHANGENOW_SIGNATURE']
x-changenow-signature
数据内容位于 中。用$postdata
$data = json_decode($postdata);
将其转换为对象。然后你可以使用 、 等来获取帖子数据的字段。$data->status
$data->payinHash
评论