Skip to content

上传电子小票

商户将支付成功回传的参数填入指定字段,可以给指定微信支付订单上传电子小票。 上传成功后,用户可以在账单详情页看到商户上传的电子小票。

请求参数类型描述
headersobject声明请求的头参数
Wechatpay-Serialstring平台公钥ID/平台公钥证书序列号
bodyobjectmultipart/form-data 数据结构
fileobject图片文件,电子小票图片只支持PNG、JPG格式,文件大小不能超过200KB。
metastring媒体文件元信息,使用json表示
transaction_idstring微信支付订单的交易单号,上传的电子小票会关联到该订单
transaction_mchidstring微信支付订单的下单商户号
transaction_sub_mchidstring微信支付订单的下单子商户号
out_trade_nostring微信支付订单的商户订单号
openidstring微信支付订单中OpenID
sha256string图片文件的sha256摘要
merchant_contact_informationobject用户与商家的联系渠道
consultation_phone_numberstring品牌售后部门的咨询电话。
upload_timestring上传时间,用于标识请求的先后顺序
php
$digest = \hash_file('sha256', 'file:///path/to/image.jpg');
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');
$meta = [
  'transaction_id'               => '420000153220220···158964',
  'transaction_mchid'            => '1900006#',
  'transaction_sub_mchid'        => '',
  'out_trade_no'                 => 'sdk123456789202205#809',
  'openid'                       => 'oK7fFt8zzEZ909XH-LE2',
  'sha256'                       => $digest,
  'upload_time'                  => '2022-05-07T15:39:35.000+08:00',
  'merchant_contact_information' => [
    'consultation_phone_number' => 'pVd1v/69bDnuC4lw/wDaespQO/0kjiwfqdfg==',//平台证书加密
  ],
];
$media->setMeta(\json_encode($meta));

$instance->v3->marketing->shoppingReceipt->shoppingreceipts->postAsync([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
    'Wechatpay-Serial' => '',
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$digest = \hash_file('sha256', 'file:///path/to/image.jpg');
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');
$meta = [
  'transaction_id'               => '420000153220220···158964',
  'transaction_mchid'            => '1900006#',
  'transaction_sub_mchid'        => '',
  'out_trade_no'                 => 'sdk123456789202205#809',
  'openid'                       => 'oK7fFt8zzEZ909XH-LE2',
  'sha256'                       => $digest,
  'upload_time'                  => '2022-05-07T15:39:35.000+08:00',
  'merchant_contact_information' => [
    'consultation_phone_number' => 'pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==',//平台证书加密
  ],
];
$media->setMeta(\json_encode($meta));

$instance->chain('v3/marketing/shopping-receipt/shoppingreceipts')->postAsync([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
    'Wechatpay-Serial' => '',
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$digest = \hash_file('sha256', 'file:///path/to/image.jpg');
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');
$meta = [
  'transaction_id'               => '420000153220220···158964',
  'transaction_mchid'            => '1900006#',
  'transaction_sub_mchid'        => '',
  'out_trade_no'                 => 'sdk123456789202205#809',
  'openid'                       => 'oK7fFt8zzEZ909XH-LE2',
  'sha256'                       => $digest,
  'upload_time'                  => '2022-05-07T15:39:35.000+08:00',
  'merchant_contact_information' => [
    'consultation_phone_number' => 'pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==',//平台证书加密
  ],
];
$media->setMeta(\json_encode($meta));

$instance['v3/marketing/shopping-receipt/shoppingreceipts']->postAsync([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
    'Wechatpay-Serial' => '',
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$digest = \hash_file('sha256', 'file:///path/to/image.jpg');
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');
$meta = [
  'transaction_id'               => '420000153220220···158964',
  'transaction_mchid'            => '1900006#',
  'transaction_sub_mchid'        => '',
  'out_trade_no'                 => 'sdk123456789202205#809',
  'openid'                       => 'oK7fFt8zzEZ909XH-LE2',
  'sha256'                       => $digest,
  'upload_time'                  => '2022-05-07T15:39:35.000+08:00',
  'merchant_contact_information' => [
    'consultation_phone_number' => 'pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==',//平台证书加密
  ],
];
$media->setMeta(\json_encode($meta));

$response = $instance->v3->marketing->shoppingReceipt->shoppingreceipts->post([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
    'Wechatpay-Serial' => '',
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$digest = \hash_file('sha256', 'file:///path/to/image.jpg');
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');
$meta = [
  'transaction_id'               => '420000153220220···158964',
  'transaction_mchid'            => '1900006#',
  'transaction_sub_mchid'        => '',
  'out_trade_no'                 => 'sdk123456789202205#809',
  'openid'                       => 'oK7fFt8zzEZ909XH-LE2',
  'sha256'                       => $digest,
  'upload_time'                  => '2022-05-07T15:39:35.000+08:00',
  'merchant_contact_information' => [
    'consultation_phone_number' => 'pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==',//平台证书加密
  ],
];
$media->setMeta(\json_encode($meta));

$response = $instance->chain('v3/marketing/shopping-receipt/shoppingreceipts')->post([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
    'Wechatpay-Serial' => '',
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$digest = \hash_file('sha256', 'file:///path/to/image.jpg');
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/image.jpg');
$meta = [
  'transaction_id'               => '420000153220220···158964',
  'transaction_mchid'            => '1900006#',
  'transaction_sub_mchid'        => '',
  'out_trade_no'                 => 'sdk123456789202205#809',
  'openid'                       => 'oK7fFt8zzEZ909XH-LE2',
  'sha256'                       => $digest,
  'upload_time'                  => '2022-05-07T15:39:35.000+08:00',
  'merchant_contact_information' => [
    'consultation_phone_number' => 'pVd1HJ6v/69bDnuC4EL5Kz4jBHLiCa8MRtelw/wDa4SzfeespQO/0kjiwfqdfg==',//平台证书加密
  ],
];
$media->setMeta(\json_encode($meta));

$response = $instance['v3/marketing/shopping-receipt/shoppingreceipts']->post([
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
    'Wechatpay-Serial' => '',
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
返回字典类型描述
receiptobject电子小票上传信息
receipt_idstring电子小票ID
statestring电子小票图片审核状态
transaction_idstring微信支付订单的交易单号,上传的电子小票会关联到该订单
transaction_mchidstring微信支付订单的商户号
transaction_sub_mchidstring微信支付订单的子商户号
openidstring微信支付订单中OpenID
sha256string图片文件的文件摘要,即对图片文件的二进制内容进行sha256计算得到的值
image_typestring标识电子小票图片类型
create_timestring电子小票创建的时间
modify_timestring电子小票最后一次修改时间
merchant_contact_informationobject用户与商家的联系渠道
consultation_phone_numberstring品牌售后部门的咨询电话。
upload_timestring上传时间,用于标识请求的先后顺序,该笔小票上传时填写则返回,没有不返回

参阅 官方文档

Published on the GitHub by TheNorthMemory