上传电子小票开发指引

更新时间:2024.09.20

本文档主要涉及开发指引文档超链接中对上传电子小票场景的处理流程。

前置步骤

在阅读本开发指引前,请确保您已经:

  • 已联系微信支付运营将上传商户号加入白名单

上传电子小票

用户在支付完成后,商户可以为该笔支付订单上传电子小票。上传电子小票需要一些基础的交易信息来指定需要上传小票的订单,这部分信息商户可自己通过支付成功回调、查询订单信息或从其他商家处获取。为了避免商户图片信息在上传过程中被篡改,需要用户在文本信息中携带图片的sha256哈希码,电子小票系统在收到图片信息后会计算sha256与文本信息中的sha256进行比对。

1// sdk会根据文件后缀填写file的content_type,请确保后缀填写正确。
2        String filePath = "/your/home/test.png";
3        URI uri = new URI("https://api.mch.weixin.qq.com/v3/marketing/shopping-receipt/shoppingreceipts");
4        File file = new File(filePath);
5        try (FileInputStream fileIs = new FileInputStream(file)) {
6            String transaction_id = "420000153220220···158964";
7            String transaction_mchid = "1900006#";
8            String transaction_sub_mchid = "";
9            String out_trade_no = "sdk123456789202205#809";
10            String openid = "oK7fFt8zzEZ909XH-LE2#";
11            String upload_time = "2022-05-07T15:39:35.000+08:00";
12            String meta = "";
13            String sha256 = DigestUtils.sha256Hex(fileIs);
14            if (transaction_sub_mchid == "") {
15                meta = String.format("{\"transaction_id\":\"%s\",\"transaction_mchid\":\"%s\",\"out_trade_no\":\"%s\",\"openid\":\"%s\",\"sha256\":\"%s\",\"upload_time\":\"%s\"}}", transaction_id, transaction_mchid, out_trade_no, openid, sha256, upload_time);
16            } else {
17                meta = String.format("{\"transaction_id\":\"%s\",\"transaction_mchid\":\"%s\",\"transaction_sub_mchid\":\"%s\",\"out_trade_no\":\"%s\",\"openid\":\"%s\",\"sha256\":\"%s\",\"upload_time\":\"%s\"}}", transaction_id, transaction_mchid, transaction_sub_mchid, out_trade_no, openid, sha256, upload_time);
18            }
19            try (InputStream is = new FileInputStream(file)) {
20                WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(uri)
21                        .withFile(file.getName(), meta, is)
22                        .build();
23                try (CloseableHttpResponse response = httpClient.execute(request)) {
24                    // do something useful with the response body
25                    // and ensure it is fully consumed
26                    String s = EntityUtils.toString(response.getEntity());
27                    System.out.println("result: "+s);
28                }
29            }
30        }

扩展阅读

请参考上传电子小票,了解上传电子小票场景的开发流程。

更多技术问题
技术咨询
反馈
咨询
目录
置顶