美团图床上传接口API源码百分百可用(一手接口源码)

作者:

更换WordPress后很久没有发博客了,发一个接口源码吧。

很早之前的了,现在也还可以用,美团图床该说不说还是稳,和百家号图床一样稳定。最大貌似上传20-25MB图片,用本接口源码,可用做自己的图床自己用。注意代码中的表头中的token替换为你自己的美团token,token怎么获取,自己研究一下。

上传后的图片例子:https://img.meituan.net/video/4317aaf82ca1c9c5a75e91c88f478f4e105742.jpg

京东图床不会更了,好多人搬运真是一点版权都不留啊,版权一改就是你的了是吧。

代码:

[hidecontent type=”reply”]
<?php
// zai1.com
// 检查是否有文件上传
// 转载请注明出处,谢谢啦。
if(isset($_FILES['file'])) {
    // 获取文件信息
    $file = $_FILES['file'];

    // 设置请求头
    $headers = array(
        'Accept: */*',
        'Accept-Encoding: gzip, deflate, br',
        'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
        'Cache-Control: no-cache',
        'Connection: keep-alive',
        'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarywt1pMxJgab51elEB',
        'Host: pic-up.meituan.com',
        'Origin: https://czz.meituan.com',
        'Pragma: no-cache',
        'Referer: https://czz.meituan.com/',
        'Sec-Fetch-Dest: empty',
        'Sec-Fetch-Mode: cors',
        'Sec-Fetch-Site: same-site',
        'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0',
        'client-id: p5gfsvmw6qnwc45n000000000025bbf1',
        'sec-ch-ua: "Not A(Brand";v="99", "Microsoft Edge";v="121", "Chromium";v="121"',
        'sec-ch-ua-mobile: ?0',
        'sec-ch-ua-platform: "Windows"',
        'token: 换自己的toekn'
    );

    // 构建 multipart/form-data 格式的数据
    $postData = "------WebKitFormBoundarywt1pMxJgab51elEB\r\n";
    $postData .= 'Content-Disposition: form-data; name="file"; filename="' . $file['name'] . "\"\r\n";
    $postData .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";
    $postData .= file_get_contents($file['tmp_name']) . "\r\n";
    $postData .= "------WebKitFormBoundarywt1pMxJgab51elEB--\r\n";

    // 初始化 cURL
    $ch = curl_init();

    // 设置 cURL 选项
    curl_setopt($ch, CURLOPT_URL, 'https://pic-up.meituan.com/extrastorage/new/video?isHttps=true');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // 执行请求并获取响应
    $response = curl_exec($ch);

    // 检查是否有错误发生
    if(curl_errno($ch)){
        echo 'Curl error: ' . curl_error($ch);
        exit;
    }

    // 关闭 cURL 资源
    curl_close($ch);

    // 解析 JSON 响应
    $jsonResponse = json_decode($response, true);

    // 检查是否上传成功
    if(isset($jsonResponse['success']) && $jsonResponse['success'] === true) {
        // 提取原始链接和原始文件名
        $originalLink = $jsonResponse['data']['originalLink'];
        $originalFileName = $jsonResponse['data']['originalFileName'];
        
        // 组成新的 JSON 并输出
        $newJson = array(
            'Jobs' => $originalLink,
            'Name' => $originalFileName,
            'os'=>'node-oss.zai1.com'
        );
        echo json_encode($newJson);
    } else {
        // 输出上传失败信息
        echo json_encode(array('error' => 'Upload failed'));
    }

} else {
    echo "No file uploaded.";
}
?>
[/hidecontent]

评论

188 条对“美团图床上传接口API源码百分百可用(一手接口源码)”的回复

  1. 小崽 的头像
    小崽

    看看咋样

  2. mtjk 的头像
    mtjk

    666666666666

  3. 给个机会 的头像
    给个机会

    关注下……

  4. Ron Cormier 的头像

    Your blog is a testament to your expertise and dedication to your craft. I’m constantly impressed by the depth of your knowledge and the clarity of your explanations. Keep up the amazing work!

  5. 都得 的头像
    都得

    感谢分享

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注