Skip to content

文件上传

部分微信支付业务指定商户需要使用文件上传 API来上报文件(如图片)信息,从而获得必传参数的值:图片MediaID,或PDF文件MediaID。媒体图片只支持JPG、BMP、PNG格式,文件大小不能超过5M。PDF文件大小不能超过7.5M。

请求参数类型描述
bodyobjectmultipart/form-data 数据结构
fileobject媒体图⽚只⽀持JPG、BMP、PNG格式,⽂件⼤⼩不能超过5M。PDF文件大小不能超过7.5M。
metastring媒体文件元信息,使用json表示,包含两个参数:sha256filename
sha256string文件sha256摘要
filenamestring文件名称
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');

$instance->v3->merchant->media->upload->postAsync([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');

$instance->chain('v3/merchant/media/upload')->postAsync([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');

$instance['v3/merchant/media/upload']->postAsync([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');

$response = $instance->v3->merchant->media->upload->post([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');

$response = $instance->chain('v3/merchant/media/upload')->post([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');

$response = $instance['v3/merchant/media/upload']->post([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
返回字典类型描述
media_idstring媒体文件标识Id

参阅 官方文档 官方文档 官方文档 官方文档

Published on the GitHub by TheNorthMemory