我需要使用 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是准确的。还有其他我没有看到的问题吗?
提前谢谢。
CURLOPT_USERNAME
是在PHP 5.5.0 中添加的。
如果您有旧版本,那么您可能需要尝试:
curl_setopt($ch, CURLOPT_USERPWD, "sk_pJDwxFxCVw5fQJhRRMpf29jReUjjN:");
这是最终的工作解决方案...
$post=array();
$post["amount"]=100000;
$post["currency"]="btc";
$post["description"]="test";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERNAME, "sk_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
curl_setopt($ch, CURLOPT_URL, "https://api.strike.acinq.co/api/v1/charges");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-Type: application/json"));
$output = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http==200) {
} else {
}