Skip to content

上传电子发票文件

调用【将电子发票插入微信用户卡包】接口之前,需要先调用本接口上传电子发票文件,获取文件ID。上传的发票文件会在三天后过期,因此上传后请尽快调用【将电子发票插入微信用户卡包】接口执行插入微信用户卡包的操作。

请求参数类型描述
bodyobjectmultipart/form-data 数据结构
fileobject电子发票文件二进制数据流,只支持PDFOFD格式,文件大小不能超过2M。
metastring媒体文件元信息,使用json表示
sub_mchidstring微信支付分配的子商户号,服务商模式下必传
file_typestring发票文件的类型
digest_algorithmstring文件摘要算法 SM3枚举值
digeststring文件的SM3摘要
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/fapiao.pdf');
$meta = [
  'sub_mchid' => 'your_sub_mchid',
  'file_type' => 'PDF',
  'digest_algorithm' => 'SM3',
  'digest' => 'your_fapiao_pdf_sm3_string',
];
$media->setMeta(\json_encode($meta));

$instance->v3->newTaxControlFapiao->fapiaoApplications->uploadFapiaoFile->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/fapiao.pdf');
$meta = [
  'sub_mchid' => 'your_sub_mchid',
  'file_type' => 'PDF',
  'digest_algorithm' => 'SM3',
  'digest' => 'your_fapiao_pdf_sm3_string',
];
$media->setMeta(\json_encode($meta));

$instance->chain('v3/new-tax-control-fapiao/fapiao-applications/upload-fapiao-file')->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/fapiao.pdf');
$meta = [
  'sub_mchid' => 'your_sub_mchid',
  'file_type' => 'PDF',
  'digest_algorithm' => 'SM3',
  'digest' => 'your_fapiao_pdf_sm3_string',
];
$media->setMeta(\json_encode($meta));

$instance['v3/new-tax-control-fapiao/fapiao-applications/upload-fapiao-file']->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/fapiao.pdf');
$meta = [
  'sub_mchid' => 'your_sub_mchid',
  'file_type' => 'PDF',
  'digest_algorithm' => 'SM3',
  'digest' => 'your_fapiao_pdf_sm3_string',
];
$media->setMeta(\json_encode($meta));

$response = $instance->v3->newTaxControlFapiao->fapiaoApplications->uploadFapiaoFile->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/fapiao.pdf');
$meta = [
  'sub_mchid' => 'your_sub_mchid',
  'file_type' => 'PDF',
  'digest_algorithm' => 'SM3',
  'digest' => 'your_fapiao_pdf_sm3_string',
];
$media->setMeta(\json_encode($meta));

$response = $instance->chain('v3/new-tax-control-fapiao/fapiao-applications/upload-fapiao-file')->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/fapiao.pdf');
$meta = [
  'sub_mchid' => 'your_sub_mchid',
  'file_type' => 'PDF',
  'digest_algorithm' => 'SM3',
  'digest' => 'your_fapiao_pdf_sm3_string',
];
$media->setMeta(\json_encode($meta));

$response = $instance['v3/new-tax-control-fapiao/fapiao-applications/upload-fapiao-file']->post([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
返回字典类型描述
fapiao_media_idstring电子发票文件ID

参阅 官方文档

Published on the GitHub by TheNorthMemory