使用GuzzleHttp来进行公众号临时素材上传

由于是要上传文件,所以我们使用GuzzleHttp的multipart的参数来进行post请求
access_token和type两个参数的构建,不麻烦按正常思路走就行,
关于media的参数构建可以使用如下的代码进行:

$client->request('POST', '/post', [
    'multipart' => [
        [
            'name'     => 'media',
            'contents' => 'fopen('/path/to/file', 'r')
        ],
    ]
]);

  

参考资料:
https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html#multipart
https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html

posted @ 2021-02-26 15:36  风哀伤  阅读(652)  评论(0)    收藏  举报