我正在尝试使用 CURL 实现VISA Developer Foreign Exchange API ,但是当我发送请求时,我收到 Authentication Error 消息。我正在本地测试 API,这是我的实现。
$data_string = $_POST;
$ch = curl_init('https://sandbox.api.visa.com/forexrates/v1/foreignexchangerates');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', "Accept:application/json", "Authorization:".base64_encode("usernamestring:passwordstring")));
curl_setopt($ch, CURLOPT_URL, "https://sandbox.api.visa.com/forexrates/v1/foreignexchangerates");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data_string));
curl_setopt($ch, CURLOPT_POST, 1);
$results = curl_exec($ch);
他们还生成一个 .pem 证书,我不确定我是否必须将其用于 Foreign Exchnage API 请求,但请您看看我是否做错了什么?