Skip to content

上传文件

部分微信支付境外业务指定商户需要上传文件资料,可使用本API来提交资料,获取其他业务API所需的FileID值。

请求参数类型描述
base_uristring声明接入点https://apihk.mch.weixin.qq.com/(香港接入)
bodyobjectmultipart/form-data 数据结构
fileobject文件信息。文件支持PDF、JPG、BMP、PNG格式,文件大小不能超过5M。
metastring媒体文件元信息,使用json表示,包含两个参数:sha256filename
digeststring文件的sha256摘要
filenamestring商户上传的文件的名称,商户自定义,必须以PDF、JPG、BMP、PNG为后缀
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');
$media->setMeta(\json_encode([
  'filename' => 'image.jpg',
  'digest'   => 'your_image_file_sha256_string'
]));

$instance->v3->global->merchantStorage->file->upload->postAsync([
  'base_uri' => 'https://apihk.mch.weixin.qq.com/', // 接入点(香港接入)
  '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');
$media->setMeta(\json_encode([
  'filename' => 'image.jpg',
  'digest'   => 'your_image_file_sha256_string'
]));

$instance->chain('v3/global/merchant-storage/file/upload')->postAsync([
  'base_uri' => 'https://apihk.mch.weixin.qq.com/', // 接入点(香港接入)
  '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');
$media->setMeta(\json_encode([
  'filename' => 'image.jpg',
  'digest'   => 'your_image_file_sha256_string'
]));

$instance['v3/global/merchant-storage/file/upload']->postAsync([
  'base_uri' => 'https://apihk.mch.weixin.qq.com/', // 接入点(香港接入)
  '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');
$media->setMeta(\json_encode([
  'filename' => 'image.jpg',
  'digest'   => 'your_image_file_sha256_string'
]));

$response = $instance->v3->global->merchantStorage->file->upload->post([
  'base_uri' => 'https://apihk.mch.weixin.qq.com/', // 接入点(香港接入)
  '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');
$media->setMeta(\json_encode([
  'filename' => 'image.jpg',
  'digest'   => 'your_image_file_sha256_string'
]));

$response = $instance->chain('v3/global/merchant-storage/file/upload')->post([
  'base_uri' => 'https://apihk.mch.weixin.qq.com/', // 接入点(香港接入)
  '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');
$media->setMeta(\json_encode([
  'filename' => 'image.jpg',
  'digest'   => 'your_image_file_sha256_string'
]));

$response = $instance['v3/global/merchant-storage/file/upload']->post([
  'base_uri' => 'https://apihk.mch.weixin.qq.com/', // 接入点(香港接入)
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
返回字典类型描述
file_idstring文件标识ID

参阅 官方文档

Published on the GitHub by TheNorthMemory