我需要在链接中插入一个id变量" https://api.quickpay.net/payments/9727866/link" (而不是" 9727866")但我似乎无法使语法正确。
无论我做什么,它似乎都不接受我的变量..谁知道怎么做?
$params = array(
"amount" => 100,
"order_id" => 999999
);
$data_string = http_build_query($params, '&');
$headers = array(
'Accept-Version: v10',
'Accept: application/json',
'Authorization: Basic ' . base64_encode(":HIDDEN_API_KEY")
);
$ch = curl_init('https://api.quickpay.net/payments/9727866/link');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if(!curl_exec($ch)){
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
curl_close($ch);
print_r($result);
答案 0 :(得分:1)
这可能是因为你使用的是单引号。请尝试以下任何一种方法:
$ch = curl_init("https://api.quickpay.net/payments/$variable/link");
或
$ch = curl_init("https://api.quickpay.net/payments/{$variable}/link");
或
$ch = curl_init("https://api.quickpay.net/payments/" . $variable . "/link");
或
$str = "https://api.quickpay.net/payments/" . $variable . "/link";
$ch = curl_init($str);
或
sprintf("https://api.quickpay.net/payments/%s/link", $variable);
无论你的船漂浮着什么。