查询支付宝单笔交易

根据支付宝的交易号查询本笔交易信息, 需要淘宝卖家授权。

接口地址:

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

参数名 类型 说明 示例
appid String 开发者AppId 开放平台提供
tb_seller_nick String 要查询的商家, 淘宝卖家店铺登录账号,非店铺名称 kingdo
timestamp long 当前时间戳,开发者的接口请求和开放平台的时间差在5分钟之内。
sign string 接口签名 ,对请求参数进行签名,签名算法可参考附件示例代码
alipay_order_no string 支付宝交易号 比如 20200214200040011100270047861221

请求示例

 String result ="";
        String tb_seller_nick = Config.TBSellerNick ; //要查询支付宝的淘宝商家
        String alipay_order_no = "2020070622001413231427949559"; // 支付宝交易订单号
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost( Config.AliPayTradeDetailUrl );

        //业务参数
        Map<String, String> data = new HashMap<String, String>();
        data.put("appid",  Config.AppId);
        data.put("tb_seller_nick", tb_seller_nick);
        data.put("alipay_order_no", alipay_order_no);
//       SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Long timestamp = System.currentTimeMillis() / 1000;
        data.put("timestamp", timestamp.toString());

        //发起POST请求
        try {
            //参数签名
            data.put("sign", Utils.Sign(data,Config.AppSecret));
            List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
            for (Map.Entry<String, String> entry : data.entrySet()) {
                params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
            }
            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_record": {
            "alipay_order_no": "20200214200040011100270047861221",
            "create_time": "2020-02-14 00:12:52",
            "in_out_type": "in",
            "modified_time": "2020-02-14 00:12:58",
            "opposite_logon_id": "sup*@163.com",
            "opposite_user_id": "2088002269364279",
            "order_from": "ALIPAY",
            "order_status": "TRANSFER_WITHDRAW_SUCCESS",
            "order_title": "王者荣耀款",
            "order_type": "_OTHERS",
            "owner_name": "*享清",
            "owner_user_id": "2088502785989744",
            "service_charge": "0.00",
            "total_amount": "2.88"
        }
    }
}

其中,code为0表示成功,非0为失败,失败时,message中会有失败信息。 in_out_type表示收入和支出,
opposite_logon_id对方的支付宝号,owner_name为本人的真名。
order_status: OTHERS(比如花呗还款等) 、TRADEFINISHED(交易成功)、TRANSFER_APPLY_WITHDARW_SUCCESS(提现成功)、TRANSFER_WITHDRAW_SUCCESS(转账成功)、TRANSFER_INITIAL(待付款)
order_title:商品标题或是交易备注, 比如”主动还款-花呗2020年03月账单” 、”RDS费用”、普通提现等。

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