{"errcode":41005,"errmsg":"media data missing hint: [anVMtA04733723]"}

通過(guò)新增素材接口上傳圖片文件

這個(gè)接口一直取不到文件搞了一下午
用GuzzleHttp

廢話不多說(shuō)直接上代碼

    $path = storage_path()."/app/public/upload/". $filename;
    if(!file_exists($path)){
        Log::error('####  file do not exist! at path!'.$path);
        exit(0);
    }
    $access_token = $this->getAccess_token();
    $uploadurl = getenv('WX_UPLOAD_URL');
    $url =$uploadurl.$access_token.'&type=image';
    $client = new GuzzleHttp\Client();
    $img = fopen($path, 'r');
    $res = $client->request('POST', $url, [
        'multipart' => [
            [
                'name'     => 'filename',
                'contents' => $filename
            ],
            [
                'name'     => 'content-type',
                'contents' => 'image/jpg'
            ],
            [
                'name'     => 'filelength',
                'contents' => filesize($path)
            ],
            [
                'name'     => 'media',
                'contents' => $img
            ]
        ]
    ]);

    $body = $res->getBody();
    $callback = json_decode($body->getContents());
    Log::info('####fileUpload'.$body.$url.$img);
BF77825B-A1E1-4198-9B91-83785180A3B9.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容