【发布时间】:2018-09-10 21:26:13
【问题描述】:
我需要使用 PHP 实现以下 curl。
$ curl https://api.dev.strike.acinq.co/api/v1/charges \
-u sk_pJDwxFxCVw5fQJhRRMpf29jReUjjN: \
-X POST \
-d amount=42000 \
-d currency="btc" \
-d description="1%20Blockaccino"
这是我目前所拥有的。
$post=array();
$post["amount"]=4200;
$post["currency"]="btc";
$post["description"]="1%20Blockaccino";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERNAME, "sk_pJDwxFxCVw5fQJhRRMpf29jReUjjN:");
curl_setopt($ch, CURLOPT_URL, "https://api.dev.strike.acinq.co/api/v1/charges");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$output = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http==200) {
} else {
}
返回
{ "code" : 401, "message" : "authentication failed" }
即使 CURLOPT_USERNAME 是准确的。还有其他我没有看到的问题吗?
提前致谢。
【问题讨论】:
-
看起来您的 API 密钥无效?您是否尝试过使用 curl 并且能够获得成功的结果?
-
我使用原生 curl 得到了相同的结果,所以我认为你是正确的,我得到的信息是准确的......谢谢!