查询支付宝交易流水

根据时间段,查询支付宝的交易明细, 需要淘宝卖家授权。

接口地址:

https://kf.fw199.com/gateway/alipay/trade/list

参数名 类型 说明 示例
appid String 开发者AppId 开放平台提供
tb_seller_nick String 要查询的商家, 淘宝卖家店铺登录账号,非店铺名称 kingdo
timestamp long 当前时间戳,开发者的接口请求和开放平台的时间差在5分钟之内。
sign string 接口签名 ,对请求参数进行签名,签名算法可参考附件示例代码
start_time string 开始时间,格式yyyy-MM-dd HH:mm:ss 比如 2020-02-16 11:09:19
page_no int 第几页 比如 1
page_size int 每页大小 ,注意每页大小在0-20之间,不要过大。 10

注意开始时间和结束时间之间不能超过7天。 返回的参数中包含总记录数,可以配合page_no或page_size进行分页。
请求示例

        String result ="";
        String tb_seller_nick = Config.TBSellerNick ; //要查询支付宝的淘宝商家
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost( Config.AliPayTradeListUrl );

        //业务参数
        Map<String, String> data = new HashMap<String, String>();
        data.put("appid",  Config.AppId);
        data.put("tb_seller_nick", tb_seller_nick);
        Long timestamp = System.currentTimeMillis() / 1000;
        data.put("timestamp", timestamp.toString());


        Calendar calendar=Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -7);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        data.put("start_time", df.format(calendar.getTime()));
        Date end = new Date();
        data.put("end_time",  df.format(end));
        data.put("page_no", "1");
        data.put("page_size","20");

        //参数签名
        try {
            data.put("sign", Utils.Sign(data,Config.AppSecret));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
        for (Map.Entry<String, String> entry : data.entrySet()) {
            params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
        //发起POST请求
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
            HttpResponse httpResponse = httpclient.execute(httpPost);
            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                result =  EntityUtils.toString(httpResponse.getEntity());
            } else {
                result =  ("doPost Error Response: " + httpResponse.getStatusLine().toString());
            }
        } catch (Exception e) {
            e.printStackTrace();

        }

        System.out.println(result);

返回示例

{
    "code": 0,
    "message": "ok",
    "data": {
        "trade_records": [
            {
                "alipay_order_no": "2020021522001135791418997111",
                "create_time": "2020-02-15 21:31:59",
                "in_out_type": "in",
                "modified_time": "2020-02-15 22:30:12",
                "opposite_logon_id": "f2fo5t*@163.com",
                "opposite_user_id": "2088732536435798",
                "order_from": "TAOBAO",
                "order_status": "TRADE_CLOSED",
                "order_title": "秋冬羊绒外套",
                "order_type": "TRADE",
                "owner_name": "*国英",
                "owner_user_id": "2088732487436622",
                "service_charge": "0.00",
                "total_amount": "100.00"
            },
            {
                "alipay_order_no": "2020021322001436601446511134",
                "create_time": "2020-02-13 21:36:02",
                "in_out_type": "out",
                "modified_time": "2020-02-13 21:36:51",
                "opposite_logon_id": "171****7789",
                "opposite_user_id": "2088432920648204",
                "order_from": "OTHER",
                "order_status": "TRADE_FINISHED",
                "order_title": "商品",
                "order_type": "TRADE",
                "owner_name": "*国英",
                "owner_user_id": "2088732487436643",
                "service_charge": "0.00",
                "total_amount": "1200.00"
            }

        ],
        "total_result": 2
    }
}

上述返回集合, 其中的字段信息可以参考”查询支付宝单笔交易” 中的字段描述。

文档更新时间: 2023-03-14 16:36   作者:admin