美文网首页
{"errcode":41005,"errmsg":"media

{"errcode":41005,"errmsg":"media

作者: 夬大爷 | 来源:发表于2018-05-29 16:57 被阅读0次

    通过新增素材接口上传图片文件

    这个接口一直取不到文件搞了一下午
    用GuzzleHttp

    废话不多说直接上代码

        $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

    相关文章

      网友评论

          本文标题:{"errcode":41005,"errmsg":"media

          本文链接:https://www.haomeiwen.com/subject/xruajftx.html