API接口:https://upload.58cdn.com.cn/json
上传参数:
Pic-Data => 图片Base64值
Pic-Encoding => base64
Pic-Path => /nowater/webim/big/
Pic-Size => 0*0
请求头:
Content-Type: application/json
Referer: https://ai.58.com/pc/
需要对返回的数据进行拼接处理,详见代码示例
图床无水印,定期删除
<?php
// 58同城图床接口
// By: Linuors
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$apiUrl = 'https://upload.58cdn.com.cn/json';
$referer = 'https://ai.58.com/pc/';
$file = $_FILES['file'];
if ($file['error'] !== UPLOAD_ERR_OK) {
http_response_code(400);
echo json_encode(['error' => 'File upload error.']);
exit;
}
$imgdata = base64_encode(file_get_contents($file['tmp_name']));
$params = [
'Pic-Data' => $imgdata,
'Pic-Encoding' => 'base64',
'Pic-Path' => '/nowater/webim/big/',
'Pic-Size' => '0*0'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Referer: ' . $referer,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
if (strpos($response, 'n_v2') !== false) {
$imgurl = 'https://pic' . rand(1, 8) . '.58cdn.com.cn/nowater/webim/big/' . $response;
echo $imgurl;
} else {
http_response_code(500);
}
} else {
http_response_code(400);
echo json_encode(['error' => 'No file uploaded.']);
}
?>