API接口:https://filebroker.alibaba.com/x/upload
上传参数:
file => 图片
bizCode => icbu_rfq
请求头:
Origin: https://rfq.alibaba.com
Pragma: no-cache
Referer: https://rfq.alibaba.com/
Cookie:
其中Cookie的值需要注册登录https://rfq.alibaba.com/rfq/rfqForm.htm后,打开浏览器控制台输入document.cookie获取
<?php
// Alibaba图床接口
// By: Linuors
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$apiUrl = 'https://filebroker.alibaba.com/x/upload';
$file = $_FILES['file'];
if ($file['error'] !== UPLOAD_ERR_OK) {
http_response_code(400);
echo json_encode(['error' => 'File upload error.']);
exit;
}
$randomToken = bin2hex(random_bytes(8));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, 1);
$cFile = new CURLFile($file['tmp_name'], $file['type'], $file['name']);
$postData = ['file' => $cFile, 'bizCode' => 'icbu_rfq'];
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// 登录地址:https://rfq.alibaba.com/rfq/rfqForm.htm
// 这里要替换为你登录后的cookie
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Cookie: ",
"origin: https://rfq.alibaba.com",
"pragma: no-cache",
"referer: https://rfq.alibaba.com/"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if ($responseData && isset($responseData['code']) && $responseData['code'] === 0) {
echo $responseData['url'];
} else {
echo $response;
}
} else {
http_response_code(400);
echo json_encode(['error' => 'No file uploaded.']);
}
?>